uv_cli/lib.rs
1use std::ffi::OsString;
2use std::fmt::{self, Display, Formatter};
3use std::ops::{Deref, DerefMut};
4use std::path::PathBuf;
5use std::str::FromStr;
6
7use anyhow::{Result, anyhow};
8use clap::builder::styling::{AnsiColor, Effects, Style};
9use clap::builder::{PossibleValue, Styles, TypedValueParser, ValueParserFactory};
10use clap::error::ErrorKind;
11use clap::{Args, Parser, Subcommand};
12use clap::{ValueEnum, ValueHint};
13
14use uv_auth::Service;
15use uv_cache::CacheArgs;
16use uv_configuration::{
17 ExportFormat, IndexStrategy, KeyringProviderType, PackageNameSpecifier, PipCompileFormat,
18 ProjectBuildBackend, TargetTriple, TrustedHost, TrustedPublishing, VersionControlSystem,
19};
20use uv_distribution_types::{
21 ConfigSettingEntry, ConfigSettingPackageEntry, Index, IndexUrl, Origin, PipExtraIndex,
22 PipFindLinks, PipIndex,
23};
24use uv_normalize::{ExtraName, GroupName, PackageName, PipGroupName};
25use uv_pep508::{MarkerTree, Requirement};
26use uv_preview::PreviewFeatures;
27use uv_pypi_types::VerbatimParsedUrl;
28use uv_python::{PythonDownloads, PythonPreference, PythonVersion};
29use uv_redacted::DisplaySafeUrl;
30use uv_resolver::{
31 AnnotationStyle, ExcludeNewerPackageEntry, ExcludeNewerValue, ForkStrategy, PrereleaseMode,
32 ResolutionMode,
33};
34use uv_settings::PythonInstallMirrors;
35use uv_static::EnvVars;
36use uv_torch::TorchMode;
37use uv_workspace::pyproject_mut::AddBoundsKind;
38
39pub mod comma;
40pub mod compat;
41pub mod options;
42pub mod version;
43
44#[derive(Debug, Clone, Copy, clap::ValueEnum)]
45pub enum VersionFormat {
46 /// Display the version as plain text.
47 Text,
48 /// Display the version as JSON.
49 Json,
50}
51
52#[derive(Debug, Default, Clone, Copy, clap::ValueEnum)]
53pub enum PythonListFormat {
54 /// Plain text (for humans).
55 #[default]
56 Text,
57 /// JSON (for computers).
58 Json,
59}
60
61#[derive(Debug, Default, Clone, Copy, clap::ValueEnum)]
62pub enum SyncFormat {
63 /// Display the result in a human-readable format.
64 #[default]
65 Text,
66 /// Display the result in JSON format.
67 Json,
68}
69
70#[derive(Debug, Default, Clone, clap::ValueEnum)]
71pub enum ListFormat {
72 /// Display the list of packages in a human-readable table.
73 #[default]
74 Columns,
75 /// Display the list of packages in a `pip freeze`-like format, with one package per line
76 /// alongside its version.
77 Freeze,
78 /// Display the list of packages in a machine-readable JSON format.
79 Json,
80}
81
82fn extra_name_with_clap_error(arg: &str) -> Result<ExtraName> {
83 ExtraName::from_str(arg).map_err(|_err| {
84 anyhow!(
85 "Extra names must start and end with a letter or digit and may only \
86 contain -, _, ., and alphanumeric characters"
87 )
88 })
89}
90
91// Configures Clap v3-style help menu colors
92const STYLES: Styles = Styles::styled()
93 .header(AnsiColor::Green.on_default().effects(Effects::BOLD))
94 .usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
95 .literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
96 .placeholder(AnsiColor::Cyan.on_default());
97
98#[derive(Parser)]
99#[command(name = "uv", author, long_version = crate::version::uv_self_version())]
100#[command(about = "An extremely fast Python package manager.")]
101#[command(
102 after_help = "Use `uv help` for more details.",
103 after_long_help = "",
104 disable_help_flag = true,
105 disable_help_subcommand = true,
106 disable_version_flag = true
107)]
108#[command(styles=STYLES)]
109pub struct Cli {
110 #[command(subcommand)]
111 pub command: Box<Commands>,
112
113 #[command(flatten)]
114 pub top_level: TopLevelArgs,
115}
116
117#[derive(Parser)]
118#[command(disable_help_flag = true, disable_version_flag = true)]
119pub struct TopLevelArgs {
120 #[command(flatten)]
121 pub cache_args: Box<CacheArgs>,
122
123 #[command(flatten)]
124 pub global_args: Box<GlobalArgs>,
125
126 /// The path to a `uv.toml` file to use for configuration.
127 ///
128 /// While uv configuration can be included in a `pyproject.toml` file, it is
129 /// not allowed in this context.
130 #[arg(
131 global = true,
132 long,
133 env = EnvVars::UV_CONFIG_FILE,
134 help_heading = "Global options",
135 value_hint = ValueHint::FilePath,
136 )]
137 pub config_file: Option<PathBuf>,
138
139 /// Avoid discovering configuration files (`pyproject.toml`, `uv.toml`).
140 ///
141 /// Normally, configuration files are discovered in the current directory,
142 /// parent directories, or user configuration directories.
143 #[arg(global = true, long, env = EnvVars::UV_NO_CONFIG, value_parser = clap::builder::BoolishValueParser::new(), help_heading = "Global options")]
144 pub no_config: bool,
145
146 /// Display the concise help for this command.
147 #[arg(global = true, short, long, action = clap::ArgAction::HelpShort, help_heading = "Global options")]
148 help: Option<bool>,
149
150 /// Display the uv version.
151 #[arg(short = 'V', long, action = clap::ArgAction::Version)]
152 version: Option<bool>,
153}
154
155#[derive(Parser, Debug, Clone)]
156#[command(next_help_heading = "Global options", next_display_order = 1000)]
157pub struct GlobalArgs {
158 #[arg(
159 global = true,
160 long,
161 help_heading = "Python options",
162 display_order = 700,
163 env = EnvVars::UV_PYTHON_PREFERENCE,
164 hide = true
165 )]
166 pub python_preference: Option<PythonPreference>,
167
168 /// Require use of uv-managed Python versions.
169 ///
170 /// By default, uv prefers using Python versions it manages. However, it
171 /// will use system Python versions if a uv-managed Python is not
172 /// installed. This option disables use of system Python versions.
173 #[arg(
174 global = true,
175 long,
176 help_heading = "Python options",
177 env = EnvVars::UV_MANAGED_PYTHON,
178 value_parser = clap::builder::BoolishValueParser::new(),
179 overrides_with = "no_managed_python",
180 conflicts_with = "python_preference"
181 )]
182 pub managed_python: bool,
183
184 /// Disable use of uv-managed Python versions.
185 ///
186 /// Instead, uv will search for a suitable Python version on the system.
187 #[arg(
188 global = true,
189 long,
190 help_heading = "Python options",
191 env = EnvVars::UV_NO_MANAGED_PYTHON,
192 value_parser = clap::builder::BoolishValueParser::new(),
193 overrides_with = "managed_python",
194 conflicts_with = "python_preference"
195 )]
196 pub no_managed_python: bool,
197
198 #[allow(clippy::doc_markdown)]
199 /// Allow automatically downloading Python when required. [env: "UV_PYTHON_DOWNLOADS=auto"]
200 #[arg(global = true, long, help_heading = "Python options", hide = true)]
201 pub allow_python_downloads: bool,
202
203 #[allow(clippy::doc_markdown)]
204 /// Disable automatic downloads of Python. [env: "UV_PYTHON_DOWNLOADS=never"]
205 #[arg(global = true, long, help_heading = "Python options")]
206 pub no_python_downloads: bool,
207
208 /// Deprecated version of [`Self::python_downloads`].
209 #[arg(global = true, long, hide = true)]
210 pub python_fetch: Option<PythonDownloads>,
211
212 /// Use quiet output.
213 ///
214 /// Repeating this option, e.g., `-qq`, will enable a silent mode in which
215 /// uv will write no output to stdout.
216 #[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "verbose")]
217 pub quiet: u8,
218
219 /// Use verbose output.
220 ///
221 /// You can configure fine-grained logging using the `RUST_LOG` environment variable.
222 /// (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)
223 #[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "quiet")]
224 pub verbose: u8,
225
226 /// Disable colors.
227 ///
228 /// Provided for compatibility with `pip`, use `--color` instead.
229 #[arg(global = true, long, hide = true, conflicts_with = "color")]
230 pub no_color: bool,
231
232 /// Control the use of color in output.
233 ///
234 /// By default, uv will automatically detect support for colors when writing to a terminal.
235 #[arg(
236 global = true,
237 long,
238 value_enum,
239 conflicts_with = "no_color",
240 value_name = "COLOR_CHOICE"
241 )]
242 pub color: Option<ColorChoice>,
243
244 /// Whether to load TLS certificates from the platform's native certificate store.
245 ///
246 /// By default, uv loads certificates from the bundled `webpki-roots` crate. The
247 /// `webpki-roots` are a reliable set of trust roots from Mozilla, and including them in uv
248 /// improves portability and performance (especially on macOS).
249 ///
250 /// However, in some cases, you may want to use the platform's native certificate store,
251 /// especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) that's
252 /// included in your system's certificate store.
253 #[arg(global = true, long, env = EnvVars::UV_NATIVE_TLS, value_parser = clap::builder::BoolishValueParser::new(), overrides_with("no_native_tls"))]
254 pub native_tls: bool,
255
256 #[arg(global = true, long, overrides_with("native_tls"), hide = true)]
257 pub no_native_tls: bool,
258
259 /// Disable network access.
260 ///
261 /// When disabled, uv will only use locally cached data and locally available files.
262 #[arg(global = true, long, overrides_with("no_offline"), env = EnvVars::UV_OFFLINE, value_parser = clap::builder::BoolishValueParser::new())]
263 pub offline: bool,
264
265 #[arg(global = true, long, overrides_with("offline"), hide = true)]
266 pub no_offline: bool,
267
268 /// Allow insecure connections to a host.
269 ///
270 /// Can be provided multiple times.
271 ///
272 /// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
273 /// `localhost:8080`), or a URL (e.g., `https://localhost`).
274 ///
275 /// WARNING: Hosts included in this list will not be verified against the system's certificate
276 /// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
277 /// bypasses SSL verification and could expose you to MITM attacks.
278 #[arg(
279 global = true,
280 long,
281 alias = "trusted-host",
282 env = EnvVars::UV_INSECURE_HOST,
283 value_delimiter = ' ',
284 value_parser = parse_insecure_host,
285 value_hint = ValueHint::Url,
286 )]
287 pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
288
289 /// Whether to enable all experimental preview features.
290 ///
291 /// Preview features may change without warning.
292 #[arg(global = true, long, hide = true, env = EnvVars::UV_PREVIEW, value_parser = clap::builder::BoolishValueParser::new(), overrides_with("no_preview"))]
293 pub preview: bool,
294
295 #[arg(global = true, long, overrides_with("preview"), hide = true)]
296 pub no_preview: bool,
297
298 /// Enable experimental preview features.
299 ///
300 /// Preview features may change without warning.
301 ///
302 /// Use comma-separated values or pass multiple times to enable multiple features.
303 ///
304 /// The following features are available: `python-install-default`, `python-upgrade`,
305 /// `json-output`, `pylock`, `add-bounds`.
306 #[arg(
307 global = true,
308 long = "preview-features",
309 env = EnvVars::UV_PREVIEW_FEATURES,
310 value_delimiter = ',',
311 hide = true,
312 alias = "preview-feature",
313 value_enum,
314 )]
315 pub preview_features: Vec<PreviewFeatures>,
316
317 /// Avoid discovering a `pyproject.toml` or `uv.toml` file.
318 ///
319 /// Normally, configuration files are discovered in the current directory,
320 /// parent directories, or user configuration directories.
321 ///
322 /// This option is deprecated in favor of `--no-config`.
323 #[arg(global = true, long, hide = true, env = EnvVars::UV_ISOLATED, value_parser = clap::builder::BoolishValueParser::new())]
324 pub isolated: bool,
325
326 /// Show the resolved settings for the current command.
327 ///
328 /// This option is used for debugging and development purposes.
329 #[arg(global = true, long, hide = true)]
330 pub show_settings: bool,
331
332 /// Hide all progress outputs.
333 ///
334 /// For example, spinners or progress bars.
335 #[arg(global = true, long, env = EnvVars::UV_NO_PROGRESS, value_parser = clap::builder::BoolishValueParser::new())]
336 pub no_progress: bool,
337
338 /// Skip writing `uv` installer metadata files (e.g., `INSTALLER`, `REQUESTED`, and `direct_url.json`) to site-packages `.dist-info` directories.
339 #[arg(global = true, long, hide = true, env = EnvVars::UV_NO_INSTALLER_METADATA, value_parser = clap::builder::BoolishValueParser::new())]
340 pub no_installer_metadata: bool,
341
342 /// Change to the given directory prior to running the command.
343 ///
344 /// Relative paths are resolved with the given directory as the base.
345 ///
346 /// See `--project` to only change the project root directory.
347 #[arg(global = true, long, env = EnvVars::UV_WORKING_DIR, value_hint = ValueHint::DirPath)]
348 pub directory: Option<PathBuf>,
349
350 /// Discover a project in the given directory.
351 ///
352 /// All `pyproject.toml`, `uv.toml`, and `.python-version` files will be discovered by walking
353 /// up the directory tree from the project root, as will the project's virtual environment
354 /// (`.venv`).
355 ///
356 /// Other command-line arguments (such as relative paths) will be resolved relative
357 /// to the current working directory.
358 ///
359 /// See `--directory` to change the working directory entirely.
360 ///
361 /// This setting has no effect when used in the `uv pip` interface.
362 #[arg(global = true, long, env = EnvVars::UV_PROJECT, value_hint = ValueHint::DirPath)]
363 pub project: Option<PathBuf>,
364}
365
366#[derive(Debug, Copy, Clone, clap::ValueEnum)]
367pub enum ColorChoice {
368 /// Enables colored output only when the output is going to a terminal or TTY with support.
369 Auto,
370
371 /// Enables colored output regardless of the detected environment.
372 Always,
373
374 /// Disables colored output.
375 Never,
376}
377
378impl ColorChoice {
379 /// Combine self (higher priority) with an [`anstream::ColorChoice`] (lower priority).
380 ///
381 /// This method allows prioritizing the user choice, while using the inferred choice for a
382 /// stream as default.
383 #[must_use]
384 pub fn and_colorchoice(self, next: anstream::ColorChoice) -> Self {
385 match self {
386 Self::Auto => match next {
387 anstream::ColorChoice::Auto => Self::Auto,
388 anstream::ColorChoice::Always | anstream::ColorChoice::AlwaysAnsi => Self::Always,
389 anstream::ColorChoice::Never => Self::Never,
390 },
391 Self::Always | Self::Never => self,
392 }
393 }
394}
395
396impl From<ColorChoice> for anstream::ColorChoice {
397 fn from(value: ColorChoice) -> Self {
398 match value {
399 ColorChoice::Auto => Self::Auto,
400 ColorChoice::Always => Self::Always,
401 ColorChoice::Never => Self::Never,
402 }
403 }
404}
405
406#[derive(Subcommand)]
407#[allow(clippy::large_enum_variant)]
408pub enum Commands {
409 /// Manage authentication.
410 #[command(
411 after_help = "Use `uv help auth` for more details.",
412 after_long_help = ""
413 )]
414 Auth(AuthNamespace),
415
416 /// Manage Python projects.
417 #[command(flatten)]
418 Project(Box<ProjectCommand>),
419
420 /// Run and install commands provided by Python packages.
421 #[command(
422 after_help = "Use `uv help tool` for more details.",
423 after_long_help = ""
424 )]
425 Tool(ToolNamespace),
426
427 /// Manage Python versions and installations
428 ///
429 /// Generally, uv first searches for Python in a virtual environment, either active or in a
430 /// `.venv` directory in the current working directory or any parent directory. If a virtual
431 /// environment is not required, uv will then search for a Python interpreter. Python
432 /// interpreters are found by searching for Python executables in the `PATH` environment
433 /// variable.
434 ///
435 /// On Windows, the registry is also searched for Python executables.
436 ///
437 /// By default, uv will download Python if a version cannot be found. This behavior can be
438 /// disabled with the `--no-python-downloads` flag or the `python-downloads` setting.
439 ///
440 /// The `--python` option allows requesting a different interpreter.
441 ///
442 /// The following Python version request formats are supported:
443 ///
444 /// - `<version>` e.g. `3`, `3.12`, `3.12.3`
445 /// - `<version-specifier>` e.g. `>=3.12,<3.13`
446 /// - `<version><short-variant>` (e.g., `3.13t`, `3.12.0d`)
447 /// - `<version>+<variant>` (e.g., `3.13+freethreaded`, `3.12.0+debug`)
448 /// - `<implementation>` e.g. `cpython` or `cp`
449 /// - `<implementation>@<version>` e.g. `cpython@3.12`
450 /// - `<implementation><version>` e.g. `cpython3.12` or `cp312`
451 /// - `<implementation><version-specifier>` e.g. `cpython>=3.12,<3.13`
452 /// - `<implementation>-<version>-<os>-<arch>-<libc>` e.g. `cpython-3.12.3-macos-aarch64-none`
453 ///
454 /// Additionally, a specific system Python interpreter can often be requested with:
455 ///
456 /// - `<executable-path>` e.g. `/opt/homebrew/bin/python3`
457 /// - `<executable-name>` e.g. `mypython3`
458 /// - `<install-dir>` e.g. `/some/environment/`
459 ///
460 /// When the `--python` option is used, normal discovery rules apply but discovered interpreters
461 /// are checked for compatibility with the request, e.g., if `pypy` is requested, uv will first
462 /// check if the virtual environment contains a PyPy interpreter then check if each executable
463 /// in the path is a PyPy interpreter.
464 ///
465 /// uv supports discovering CPython, PyPy, and GraalPy interpreters. Unsupported interpreters
466 /// will be skipped during discovery. If an unsupported interpreter implementation is requested,
467 /// uv will exit with an error.
468 #[clap(verbatim_doc_comment)]
469 #[command(
470 after_help = "Use `uv help python` for more details.",
471 after_long_help = ""
472 )]
473 Python(PythonNamespace),
474 /// Manage Python packages with a pip-compatible interface.
475 #[command(
476 after_help = "Use `uv help pip` for more details.",
477 after_long_help = ""
478 )]
479 Pip(PipNamespace),
480 /// Create a virtual environment.
481 ///
482 /// By default, creates a virtual environment named `.venv` in the working
483 /// directory. An alternative path may be provided positionally.
484 ///
485 /// If in a project, the default environment name can be changed with
486 /// the `UV_PROJECT_ENVIRONMENT` environment variable; this only applies
487 /// when run from the project root directory.
488 ///
489 /// If a virtual environment exists at the target path, it will be removed
490 /// and a new, empty virtual environment will be created.
491 ///
492 /// When using uv, the virtual environment does not need to be activated. uv
493 /// will find a virtual environment (named `.venv`) in the working directory
494 /// or any parent directories.
495 #[command(
496 alias = "virtualenv",
497 alias = "v",
498 after_help = "Use `uv help venv` for more details.",
499 after_long_help = ""
500 )]
501 Venv(VenvArgs),
502 /// Build Python packages into source distributions and wheels.
503 ///
504 /// `uv build` accepts a path to a directory or source distribution,
505 /// which defaults to the current working directory.
506 ///
507 /// By default, if passed a directory, `uv build` will build a source
508 /// distribution ("sdist") from the source directory, and a binary
509 /// distribution ("wheel") from the source distribution.
510 ///
511 /// `uv build --sdist` can be used to build only the source distribution,
512 /// `uv build --wheel` can be used to build only the binary distribution,
513 /// and `uv build --sdist --wheel` can be used to build both distributions
514 /// from source.
515 ///
516 /// If passed a source distribution, `uv build --wheel` will build a wheel
517 /// from the source distribution.
518 #[command(
519 after_help = "Use `uv help build` for more details.",
520 after_long_help = ""
521 )]
522 Build(BuildArgs),
523 /// Upload distributions to an index.
524 Publish(PublishArgs),
525 /// Inspect uv workspaces.
526 #[command(
527 after_help = "Use `uv help workspace` for more details.",
528 after_long_help = "",
529 hide = true
530 )]
531 Workspace(WorkspaceNamespace),
532 /// The implementation of the build backend.
533 ///
534 /// These commands are not directly exposed to the user, instead users invoke their build
535 /// frontend (PEP 517) which calls the Python shims which calls back into uv with this method.
536 #[command(hide = true)]
537 BuildBackend {
538 #[command(subcommand)]
539 command: BuildBackendCommand,
540 },
541 /// Manage uv's cache.
542 #[command(
543 after_help = "Use `uv help cache` for more details.",
544 after_long_help = ""
545 )]
546 Cache(CacheNamespace),
547 /// Manage the uv executable.
548 #[command(name = "self")]
549 Self_(SelfNamespace),
550 /// Clear the cache, removing all entries or those linked to specific packages.
551 #[command(hide = true)]
552 Clean(CleanArgs),
553 /// Generate shell completion
554 #[command(alias = "--generate-shell-completion", hide = true)]
555 GenerateShellCompletion(GenerateShellCompletionArgs),
556 /// Display documentation for a command.
557 // To avoid showing the global options when displaying help for the help command, we are
558 // responsible for maintaining the options using the `after_help`.
559 #[command(help_template = "\
560{about-with-newline}
561{usage-heading} {usage}{after-help}
562",
563 after_help = format!("\
564{heading}Options:{heading:#}
565 {option}--no-pager{option:#} Disable pager when printing help
566",
567 heading = Style::new().bold().underline(),
568 option = Style::new().bold(),
569 ),
570 )]
571 Help(HelpArgs),
572}
573
574#[derive(Args, Debug)]
575pub struct HelpArgs {
576 /// Disable pager when printing help
577 #[arg(long)]
578 pub no_pager: bool,
579
580 #[arg(value_hint = ValueHint::Other)]
581 pub command: Option<Vec<String>>,
582}
583
584#[derive(Args)]
585#[command(group = clap::ArgGroup::new("operation"))]
586pub struct VersionArgs {
587 /// Set the project version to this value
588 ///
589 /// To update the project using semantic versioning components instead, use `--bump`.
590 #[arg(group = "operation", value_hint = ValueHint::Other)]
591 pub value: Option<String>,
592
593 /// Update the project version using the given semantics
594 ///
595 /// This flag can be passed multiple times.
596 #[arg(group = "operation", long, value_name = "BUMP[=VALUE]")]
597 pub bump: Vec<VersionBumpSpec>,
598
599 /// Don't write a new version to the `pyproject.toml`
600 ///
601 /// Instead, the version will be displayed.
602 #[arg(long)]
603 pub dry_run: bool,
604
605 /// Only show the version
606 ///
607 /// By default, uv will show the project name before the version.
608 #[arg(long)]
609 pub short: bool,
610
611 /// The format of the output
612 #[arg(long, value_enum, default_value = "text")]
613 pub output_format: VersionFormat,
614
615 /// Avoid syncing the virtual environment after re-locking the project.
616 #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
617 pub no_sync: bool,
618
619 /// Prefer the active virtual environment over the project's virtual environment.
620 ///
621 /// If the project virtual environment is active or no virtual environment is active, this has
622 /// no effect.
623 #[arg(long, overrides_with = "no_active")]
624 pub active: bool,
625
626 /// Prefer project's virtual environment over an active environment.
627 ///
628 /// This is the default behavior.
629 #[arg(long, overrides_with = "active", hide = true)]
630 pub no_active: bool,
631
632 /// Assert that the `uv.lock` will remain unchanged.
633 ///
634 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
635 /// uv will exit with an error.
636 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
637 pub locked: bool,
638
639 /// Update the version without re-locking the project.
640 ///
641 /// The project environment will not be synced.
642 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
643 pub frozen: bool,
644
645 #[command(flatten)]
646 pub installer: ResolverInstallerArgs,
647
648 #[command(flatten)]
649 pub build: BuildOptionsArgs,
650
651 #[command(flatten)]
652 pub refresh: RefreshArgs,
653
654 /// Update the version of a specific package in the workspace.
655 #[arg(long, conflicts_with = "isolated", value_hint = ValueHint::Other)]
656 pub package: Option<PackageName>,
657
658 /// The Python interpreter to use for resolving and syncing.
659 ///
660 /// See `uv help python` for details on Python discovery and supported request formats.
661 #[arg(
662 long,
663 short,
664 env = EnvVars::UV_PYTHON,
665 verbatim_doc_comment,
666 help_heading = "Python options",
667 value_parser = parse_maybe_string,
668 value_hint = ValueHint::Other,
669 )]
670 pub python: Option<Maybe<String>>,
671}
672
673// Note that the ordering of the variants is significant, as when given a list of operations
674// to perform, we sort them and apply them in order, so users don't have to think too hard about it.
675#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
676pub enum VersionBump {
677 /// Increase the major version (e.g., 1.2.3 => 2.0.0)
678 Major,
679 /// Increase the minor version (e.g., 1.2.3 => 1.3.0)
680 Minor,
681 /// Increase the patch version (e.g., 1.2.3 => 1.2.4)
682 Patch,
683 /// Move from a pre-release to stable version (e.g., 1.2.3b4.post5.dev6 => 1.2.3)
684 ///
685 /// Removes all pre-release components, but will not remove "local" components.
686 Stable,
687 /// Increase the alpha version (e.g., 1.2.3a4 => 1.2.3a5)
688 ///
689 /// To move from a stable to a pre-release version, combine this with a stable component, e.g.,
690 /// for 1.2.3 => 2.0.0a1, you'd also include [`VersionBump::Major`].
691 Alpha,
692 /// Increase the beta version (e.g., 1.2.3b4 => 1.2.3b5)
693 ///
694 /// To move from a stable to a pre-release version, combine this with a stable component, e.g.,
695 /// for 1.2.3 => 2.0.0b1, you'd also include [`VersionBump::Major`].
696 Beta,
697 /// Increase the rc version (e.g., 1.2.3rc4 => 1.2.3rc5)
698 ///
699 /// To move from a stable to a pre-release version, combine this with a stable component, e.g.,
700 /// for 1.2.3 => 2.0.0rc1, you'd also include [`VersionBump::Major`].]
701 Rc,
702 /// Increase the post version (e.g., 1.2.3.post5 => 1.2.3.post6)
703 Post,
704 /// Increase the dev version (e.g., 1.2.3a4.dev6 => 1.2.3.dev7)
705 Dev,
706}
707
708impl Display for VersionBump {
709 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
710 let string = match self {
711 Self::Major => "major",
712 Self::Minor => "minor",
713 Self::Patch => "patch",
714 Self::Stable => "stable",
715 Self::Alpha => "alpha",
716 Self::Beta => "beta",
717 Self::Rc => "rc",
718 Self::Post => "post",
719 Self::Dev => "dev",
720 };
721 string.fmt(f)
722 }
723}
724
725impl FromStr for VersionBump {
726 type Err = String;
727
728 fn from_str(value: &str) -> Result<Self, Self::Err> {
729 match value {
730 "major" => Ok(Self::Major),
731 "minor" => Ok(Self::Minor),
732 "patch" => Ok(Self::Patch),
733 "stable" => Ok(Self::Stable),
734 "alpha" => Ok(Self::Alpha),
735 "beta" => Ok(Self::Beta),
736 "rc" => Ok(Self::Rc),
737 "post" => Ok(Self::Post),
738 "dev" => Ok(Self::Dev),
739 _ => Err(format!("invalid bump component `{value}`")),
740 }
741 }
742}
743
744#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
745pub struct VersionBumpSpec {
746 pub bump: VersionBump,
747 pub value: Option<u64>,
748}
749
750impl Display for VersionBumpSpec {
751 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
752 match self.value {
753 Some(value) => write!(f, "{}={value}", self.bump),
754 None => self.bump.fmt(f),
755 }
756 }
757}
758
759impl FromStr for VersionBumpSpec {
760 type Err = String;
761
762 fn from_str(input: &str) -> Result<Self, Self::Err> {
763 let (name, value) = match input.split_once('=') {
764 Some((name, value)) => (name, Some(value)),
765 None => (input, None),
766 };
767
768 let bump = name.parse::<VersionBump>()?;
769
770 if bump == VersionBump::Stable && value.is_some() {
771 return Err("`--bump stable` does not accept a value".to_string());
772 }
773
774 let value = match value {
775 Some("") => {
776 return Err("`--bump` values cannot be empty".to_string());
777 }
778 Some(raw) => Some(
779 raw.parse::<u64>()
780 .map_err(|_| format!("invalid numeric value `{raw}` for `--bump {name}`"))?,
781 ),
782 None => None,
783 };
784
785 Ok(Self { bump, value })
786 }
787}
788
789impl ValueParserFactory for VersionBumpSpec {
790 type Parser = VersionBumpSpecValueParser;
791
792 fn value_parser() -> Self::Parser {
793 VersionBumpSpecValueParser
794 }
795}
796
797#[derive(Clone, Debug)]
798pub struct VersionBumpSpecValueParser;
799
800impl TypedValueParser for VersionBumpSpecValueParser {
801 type Value = VersionBumpSpec;
802
803 fn parse_ref(
804 &self,
805 _cmd: &clap::Command,
806 _arg: Option<&clap::Arg>,
807 value: &std::ffi::OsStr,
808 ) -> Result<Self::Value, clap::Error> {
809 let raw = value.to_str().ok_or_else(|| {
810 clap::Error::raw(
811 ErrorKind::InvalidUtf8,
812 "`--bump` values must be valid UTF-8",
813 )
814 })?;
815
816 VersionBumpSpec::from_str(raw)
817 .map_err(|message| clap::Error::raw(ErrorKind::InvalidValue, message))
818 }
819
820 fn possible_values(&self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>> {
821 Some(Box::new(
822 VersionBump::value_variants()
823 .iter()
824 .filter_map(ValueEnum::to_possible_value),
825 ))
826 }
827}
828
829#[derive(Args)]
830pub struct SelfNamespace {
831 #[command(subcommand)]
832 pub command: SelfCommand,
833}
834
835#[derive(Subcommand)]
836pub enum SelfCommand {
837 /// Update uv.
838 Update(SelfUpdateArgs),
839 /// Display uv's version
840 Version {
841 /// Only print the version
842 #[arg(long)]
843 short: bool,
844 #[arg(long, value_enum, default_value = "text")]
845 output_format: VersionFormat,
846 },
847}
848
849#[derive(Args, Debug)]
850pub struct SelfUpdateArgs {
851 /// Update to the specified version. If not provided, uv will update to the latest version.
852 #[arg(value_hint = ValueHint::Other)]
853 pub target_version: Option<String>,
854
855 /// A GitHub token for authentication.
856 /// A token is not required but can be used to reduce the chance of encountering rate limits.
857 #[arg(long, env = EnvVars::UV_GITHUB_TOKEN, value_hint = ValueHint::Other)]
858 pub token: Option<String>,
859
860 /// Run without performing the update.
861 #[arg(long)]
862 pub dry_run: bool,
863}
864
865#[derive(Args)]
866pub struct CacheNamespace {
867 #[command(subcommand)]
868 pub command: CacheCommand,
869}
870
871#[derive(Subcommand)]
872pub enum CacheCommand {
873 /// Clear the cache, removing all entries or those linked to specific packages.
874 Clean(CleanArgs),
875 /// Prune all unreachable objects from the cache.
876 Prune(PruneArgs),
877 /// Show the cache directory.
878 ///
879 /// By default, the cache is stored in `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` on Unix and
880 /// `%LOCALAPPDATA%\uv\cache` on Windows.
881 ///
882 /// When `--no-cache` is used, the cache is stored in a temporary directory and discarded when
883 /// the process exits.
884 ///
885 /// An alternative cache directory may be specified via the `cache-dir` setting, the
886 /// `--cache-dir` option, or the `$UV_CACHE_DIR` environment variable.
887 ///
888 /// Note that it is important for performance for the cache directory to be located on the same
889 /// file system as the Python environment uv is operating on.
890 Dir,
891 /// Show the cache size.
892 ///
893 /// Displays the total size of the cache directory. This includes all downloaded and built
894 /// wheels, source distributions, and other cached data. By default, outputs the size in raw
895 /// bytes; use `--human` for human-readable output.
896 Size(SizeArgs),
897}
898
899#[derive(Args, Debug)]
900pub struct CleanArgs {
901 /// The packages to remove from the cache.
902 #[arg(value_hint = ValueHint::Other)]
903 pub package: Vec<PackageName>,
904
905 /// Force removal of the cache, ignoring in-use checks.
906 ///
907 /// By default, `uv cache clean` will block until no process is reading the cache. When
908 /// `--force` is used, `uv cache clean` will proceed without taking a lock.
909 #[arg(long)]
910 pub force: bool,
911}
912
913#[derive(Args, Debug)]
914pub struct PruneArgs {
915 /// Optimize the cache for persistence in a continuous integration environment, like GitHub
916 /// Actions.
917 ///
918 /// By default, uv caches both the wheels that it builds from source and the pre-built wheels
919 /// that it downloads directly, to enable high-performance package installation. In some
920 /// scenarios, though, persisting pre-built wheels may be undesirable. For example, in GitHub
921 /// Actions, it's faster to omit pre-built wheels from the cache and instead have re-download
922 /// them on each run. However, it typically _is_ faster to cache wheels that are built from
923 /// source, since the wheel building process can be expensive, especially for extension
924 /// modules.
925 ///
926 /// In `--ci` mode, uv will prune any pre-built wheels from the cache, but retain any wheels
927 /// that were built from source.
928 #[arg(long)]
929 pub ci: bool,
930
931 /// Force removal of the cache, ignoring in-use checks.
932 ///
933 /// By default, `uv cache prune` will block until no process is reading the cache. When
934 /// `--force` is used, `uv cache prune` will proceed without taking a lock.
935 #[arg(long)]
936 pub force: bool,
937}
938
939#[derive(Args, Debug)]
940pub struct SizeArgs {
941 /// Display the cache size in human-readable format (e.g., `1.2 GiB` instead of raw bytes).
942 #[arg(long = "human", short = 'H', alias = "human-readable")]
943 pub human: bool,
944}
945
946#[derive(Args)]
947pub struct PipNamespace {
948 #[command(subcommand)]
949 pub command: PipCommand,
950}
951
952#[derive(Subcommand)]
953pub enum PipCommand {
954 /// Compile a `requirements.in` file to a `requirements.txt` or `pylock.toml` file.
955 #[command(
956 after_help = "Use `uv help pip compile` for more details.",
957 after_long_help = ""
958 )]
959 Compile(PipCompileArgs),
960 /// Sync an environment with a `requirements.txt` or `pylock.toml` file.
961 ///
962 /// When syncing an environment, any packages not listed in the `requirements.txt` or
963 /// `pylock.toml` file will be removed. To retain extraneous packages, use `uv pip install`
964 /// instead.
965 ///
966 /// The input file is presumed to be the output of a `pip compile` or `uv export` operation,
967 /// in which it will include all transitive dependencies. If transitive dependencies are not
968 /// present in the file, they will not be installed. Use `--strict` to warn if any transitive
969 /// dependencies are missing.
970 #[command(
971 after_help = "Use `uv help pip sync` for more details.",
972 after_long_help = ""
973 )]
974 Sync(Box<PipSyncArgs>),
975 /// Install packages into an environment.
976 #[command(
977 after_help = "Use `uv help pip install` for more details.",
978 after_long_help = ""
979 )]
980 Install(PipInstallArgs),
981 /// Uninstall packages from an environment.
982 #[command(
983 after_help = "Use `uv help pip uninstall` for more details.",
984 after_long_help = ""
985 )]
986 Uninstall(PipUninstallArgs),
987 /// List, in requirements format, packages installed in an environment.
988 #[command(
989 after_help = "Use `uv help pip freeze` for more details.",
990 after_long_help = ""
991 )]
992 Freeze(PipFreezeArgs),
993 /// List, in tabular format, packages installed in an environment.
994 #[command(
995 after_help = "Use `uv help pip list` for more details.",
996 after_long_help = "",
997 alias = "ls"
998 )]
999 List(PipListArgs),
1000 /// Show information about one or more installed packages.
1001 #[command(
1002 after_help = "Use `uv help pip show` for more details.",
1003 after_long_help = ""
1004 )]
1005 Show(PipShowArgs),
1006 /// Display the dependency tree for an environment.
1007 #[command(
1008 after_help = "Use `uv help pip tree` for more details.",
1009 after_long_help = ""
1010 )]
1011 Tree(PipTreeArgs),
1012 /// Verify installed packages have compatible dependencies.
1013 #[command(
1014 after_help = "Use `uv help pip check` for more details.",
1015 after_long_help = ""
1016 )]
1017 Check(PipCheckArgs),
1018 /// Display debug information (unsupported)
1019 #[command(hide = true)]
1020 Debug(PipDebugArgs),
1021}
1022
1023#[derive(Subcommand)]
1024pub enum ProjectCommand {
1025 /// Run a command or script.
1026 ///
1027 /// Ensures that the command runs in a Python environment.
1028 ///
1029 /// When used with a file ending in `.py` or an HTTP(S) URL, the file will be treated as a
1030 /// script and run with a Python interpreter, i.e., `uv run file.py` is equivalent to `uv run
1031 /// python file.py`. For URLs, the script is temporarily downloaded before execution. If the
1032 /// script contains inline dependency metadata, it will be installed into an isolated, ephemeral
1033 /// environment. When used with `-`, the input will be read from stdin, and treated as a Python
1034 /// script.
1035 ///
1036 /// When used in a project, the project environment will be created and updated before invoking
1037 /// the command.
1038 ///
1039 /// When used outside a project, if a virtual environment can be found in the current directory
1040 /// or a parent directory, the command will be run in that environment. Otherwise, the command
1041 /// will be run in the environment of the discovered interpreter.
1042 ///
1043 /// Arguments following the command (or script) are not interpreted as arguments to uv. All
1044 /// options to uv must be provided before the command, e.g., `uv run --verbose foo`. A `--` can
1045 /// be used to separate the command from uv options for clarity, e.g., `uv run --python 3.12 --
1046 /// python`.
1047 #[command(
1048 after_help = "Use `uv help run` for more details.",
1049 after_long_help = ""
1050 )]
1051 Run(RunArgs),
1052 /// Create a new project.
1053 ///
1054 /// Follows the `pyproject.toml` specification.
1055 ///
1056 /// If a `pyproject.toml` already exists at the target, uv will exit with an error.
1057 ///
1058 /// If a `pyproject.toml` is found in any of the parent directories of the target path, the
1059 /// project will be added as a workspace member of the parent.
1060 ///
1061 /// Some project state is not created until needed, e.g., the project virtual environment
1062 /// (`.venv`) and lockfile (`uv.lock`) are lazily created during the first sync.
1063 Init(InitArgs),
1064 /// Add dependencies to the project.
1065 ///
1066 /// Dependencies are added to the project's `pyproject.toml` file.
1067 ///
1068 /// If a given dependency exists already, it will be updated to the new version specifier unless
1069 /// it includes markers that differ from the existing specifier in which case another entry for
1070 /// the dependency will be added.
1071 ///
1072 /// The lockfile and project environment will be updated to reflect the added dependencies. To
1073 /// skip updating the lockfile, use `--frozen`. To skip updating the environment, use
1074 /// `--no-sync`.
1075 ///
1076 /// If any of the requested dependencies cannot be found, uv will exit with an error, unless the
1077 /// `--frozen` flag is provided, in which case uv will add the dependencies verbatim without
1078 /// checking that they exist or are compatible with the project.
1079 ///
1080 /// uv will search for a project in the current directory or any parent directory. If a project
1081 /// cannot be found, uv will exit with an error.
1082 #[command(
1083 after_help = "Use `uv help add` for more details.",
1084 after_long_help = ""
1085 )]
1086 Add(AddArgs),
1087 /// Remove dependencies from the project.
1088 ///
1089 /// Dependencies are removed from the project's `pyproject.toml` file.
1090 ///
1091 /// If multiple entries exist for a given dependency, i.e., each with different markers, all of
1092 /// the entries will be removed.
1093 ///
1094 /// The lockfile and project environment will be updated to reflect the removed dependencies. To
1095 /// skip updating the lockfile, use `--frozen`. To skip updating the environment, use
1096 /// `--no-sync`.
1097 ///
1098 /// If any of the requested dependencies are not present in the project, uv will exit with an
1099 /// error.
1100 ///
1101 /// If a package has been manually installed in the environment, i.e., with `uv pip install`, it
1102 /// will not be removed by `uv remove`.
1103 ///
1104 /// uv will search for a project in the current directory or any parent directory. If a project
1105 /// cannot be found, uv will exit with an error.
1106 #[command(
1107 after_help = "Use `uv help remove` for more details.",
1108 after_long_help = ""
1109 )]
1110 Remove(RemoveArgs),
1111 /// Read or update the project's version.
1112 Version(VersionArgs),
1113 /// Update the project's environment.
1114 ///
1115 /// Syncing ensures that all project dependencies are installed and up-to-date with the
1116 /// lockfile.
1117 ///
1118 /// By default, an exact sync is performed: uv removes packages that are not declared as
1119 /// dependencies of the project. Use the `--inexact` flag to keep extraneous packages. Note that
1120 /// if an extraneous package conflicts with a project dependency, it will still be removed.
1121 /// Additionally, if `--no-build-isolation` is used, uv will not remove extraneous packages to
1122 /// avoid removing possible build dependencies.
1123 ///
1124 /// If the project virtual environment (`.venv`) does not exist, it will be created.
1125 ///
1126 /// The project is re-locked before syncing unless the `--locked` or `--frozen` flag is
1127 /// provided.
1128 ///
1129 /// uv will search for a project in the current directory or any parent directory. If a project
1130 /// cannot be found, uv will exit with an error.
1131 ///
1132 /// Note that, when installing from a lockfile, uv will not provide warnings for yanked package
1133 /// versions.
1134 #[command(
1135 after_help = "Use `uv help sync` for more details.",
1136 after_long_help = ""
1137 )]
1138 Sync(SyncArgs),
1139 /// Update the project's lockfile.
1140 ///
1141 /// If the project lockfile (`uv.lock`) does not exist, it will be created. If a lockfile is
1142 /// present, its contents will be used as preferences for the resolution.
1143 ///
1144 /// If there are no changes to the project's dependencies, locking will have no effect unless
1145 /// the `--upgrade` flag is provided.
1146 #[command(
1147 after_help = "Use `uv help lock` for more details.",
1148 after_long_help = ""
1149 )]
1150 Lock(LockArgs),
1151 /// Export the project's lockfile to an alternate format.
1152 ///
1153 /// At present, both `requirements.txt` and `pylock.toml` (PEP 751) formats are supported.
1154 ///
1155 /// The project is re-locked before exporting unless the `--locked` or `--frozen` flag is
1156 /// provided.
1157 ///
1158 /// uv will search for a project in the current directory or any parent directory. If a project
1159 /// cannot be found, uv will exit with an error.
1160 ///
1161 /// If operating in a workspace, the root will be exported by default; however, specific
1162 /// members can be selected using the `--package` option.
1163 #[command(
1164 after_help = "Use `uv help export` for more details.",
1165 after_long_help = ""
1166 )]
1167 Export(ExportArgs),
1168 /// Display the project's dependency tree.
1169 Tree(TreeArgs),
1170 /// Format Python code in the project.
1171 ///
1172 /// Formats Python code using the Ruff formatter. By default, all Python files in the project
1173 /// are formatted. This command has the same behavior as running `ruff format` in the project
1174 /// root.
1175 ///
1176 /// To check if files are formatted without modifying them, use `--check`. To see a diff of
1177 /// formatting changes, use `--diff`.
1178 ///
1179 /// Additional arguments can be passed to Ruff after `--`.
1180 #[command(
1181 after_help = "Use `uv help format` for more details.",
1182 after_long_help = ""
1183 )]
1184 Format(FormatArgs),
1185}
1186
1187/// A re-implementation of `Option`, used to avoid Clap's automatic `Option` flattening in
1188/// [`parse_index_url`].
1189#[derive(Debug, Clone)]
1190pub enum Maybe<T> {
1191 Some(T),
1192 None,
1193}
1194
1195impl<T> Maybe<T> {
1196 pub fn into_option(self) -> Option<T> {
1197 match self {
1198 Self::Some(value) => Some(value),
1199 Self::None => None,
1200 }
1201 }
1202
1203 pub fn is_some(&self) -> bool {
1204 matches!(self, Self::Some(_))
1205 }
1206}
1207
1208/// Parse an `--index-url` argument into an [`PipIndex`], mapping the empty string to `None`.
1209fn parse_index_url(input: &str) -> Result<Maybe<PipIndex>, String> {
1210 if input.is_empty() {
1211 Ok(Maybe::None)
1212 } else {
1213 IndexUrl::from_str(input)
1214 .map(Index::from_index_url)
1215 .map(|index| Index {
1216 origin: Some(Origin::Cli),
1217 ..index
1218 })
1219 .map(PipIndex::from)
1220 .map(Maybe::Some)
1221 .map_err(|err| err.to_string())
1222 }
1223}
1224
1225/// Parse an `--extra-index-url` argument into an [`PipExtraIndex`], mapping the empty string to `None`.
1226fn parse_extra_index_url(input: &str) -> Result<Maybe<PipExtraIndex>, String> {
1227 if input.is_empty() {
1228 Ok(Maybe::None)
1229 } else {
1230 IndexUrl::from_str(input)
1231 .map(Index::from_extra_index_url)
1232 .map(|index| Index {
1233 origin: Some(Origin::Cli),
1234 ..index
1235 })
1236 .map(PipExtraIndex::from)
1237 .map(Maybe::Some)
1238 .map_err(|err| err.to_string())
1239 }
1240}
1241
1242/// Parse a `--find-links` argument into an [`PipFindLinks`], mapping the empty string to `None`.
1243fn parse_find_links(input: &str) -> Result<Maybe<PipFindLinks>, String> {
1244 if input.is_empty() {
1245 Ok(Maybe::None)
1246 } else {
1247 IndexUrl::from_str(input)
1248 .map(Index::from_find_links)
1249 .map(|index| Index {
1250 origin: Some(Origin::Cli),
1251 ..index
1252 })
1253 .map(PipFindLinks::from)
1254 .map(Maybe::Some)
1255 .map_err(|err| err.to_string())
1256 }
1257}
1258
1259/// Parse an `--index` argument into a [`Vec<Index>`], mapping the empty string to an empty Vec.
1260///
1261/// This function splits the input on all whitespace characters rather than a single delimiter,
1262/// which is necessary to parse environment variables like `PIP_EXTRA_INDEX_URL`.
1263/// The standard `clap::Args` `value_delimiter` only supports single-character delimiters.
1264fn parse_indices(input: &str) -> Result<Vec<Maybe<Index>>, String> {
1265 if input.trim().is_empty() {
1266 return Ok(Vec::new());
1267 }
1268 let mut indices = Vec::new();
1269 for token in input.split_whitespace() {
1270 match Index::from_str(token) {
1271 Ok(index) => indices.push(Maybe::Some(Index {
1272 default: false,
1273 origin: Some(Origin::Cli),
1274 ..index
1275 })),
1276 Err(e) => return Err(e.to_string()),
1277 }
1278 }
1279 Ok(indices)
1280}
1281
1282/// Parse a `--default-index` argument into an [`Index`], mapping the empty string to `None`.
1283fn parse_default_index(input: &str) -> Result<Maybe<Index>, String> {
1284 if input.is_empty() {
1285 Ok(Maybe::None)
1286 } else {
1287 match Index::from_str(input) {
1288 Ok(index) => Ok(Maybe::Some(Index {
1289 default: true,
1290 origin: Some(Origin::Cli),
1291 ..index
1292 })),
1293 Err(err) => Err(err.to_string()),
1294 }
1295 }
1296}
1297
1298/// Parse a string into an [`Url`], mapping the empty string to `None`.
1299fn parse_insecure_host(input: &str) -> Result<Maybe<TrustedHost>, String> {
1300 if input.is_empty() {
1301 Ok(Maybe::None)
1302 } else {
1303 match TrustedHost::from_str(input) {
1304 Ok(host) => Ok(Maybe::Some(host)),
1305 Err(err) => Err(err.to_string()),
1306 }
1307 }
1308}
1309
1310/// Parse a string into a [`PathBuf`]. The string can represent a file, either as a path or a
1311/// `file://` URL.
1312fn parse_file_path(input: &str) -> Result<PathBuf, String> {
1313 if input.starts_with("file://") {
1314 let url = match url::Url::from_str(input) {
1315 Ok(url) => url,
1316 Err(err) => return Err(err.to_string()),
1317 };
1318 url.to_file_path()
1319 .map_err(|()| "invalid file URL".to_string())
1320 } else {
1321 Ok(PathBuf::from(input))
1322 }
1323}
1324
1325/// Parse a string into a [`PathBuf`], mapping the empty string to `None`.
1326fn parse_maybe_file_path(input: &str) -> Result<Maybe<PathBuf>, String> {
1327 if input.is_empty() {
1328 Ok(Maybe::None)
1329 } else {
1330 parse_file_path(input).map(Maybe::Some)
1331 }
1332}
1333
1334// Parse a string, mapping the empty string to `None`.
1335#[allow(clippy::unnecessary_wraps)]
1336fn parse_maybe_string(input: &str) -> Result<Maybe<String>, String> {
1337 if input.is_empty() {
1338 Ok(Maybe::None)
1339 } else {
1340 Ok(Maybe::Some(input.to_string()))
1341 }
1342}
1343
1344#[derive(Args)]
1345#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
1346pub struct PipCompileArgs {
1347 /// Include the packages listed in the given files.
1348 ///
1349 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
1350 /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
1351 ///
1352 /// If a `pyproject.toml`, `setup.py`, or `setup.cfg` file is provided, uv will extract the
1353 /// requirements for the relevant project.
1354 ///
1355 /// If `-` is provided, then requirements will be read from stdin.
1356 ///
1357 /// The order of the requirements files and the requirements in them is used to determine
1358 /// priority during resolution.
1359 #[arg(group = "sources", value_parser = parse_file_path, value_hint = ValueHint::FilePath)]
1360 pub src_file: Vec<PathBuf>,
1361
1362 /// Constrain versions using the given requirements files.
1363 ///
1364 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1365 /// requirement that's installed. However, including a package in a constraints file will _not_
1366 /// trigger the installation of that package.
1367 ///
1368 /// This is equivalent to pip's `--constraint` option.
1369 #[arg(
1370 long,
1371 short,
1372 alias = "constraint",
1373 env = EnvVars::UV_CONSTRAINT,
1374 value_delimiter = ' ',
1375 value_parser = parse_maybe_file_path,
1376 value_hint = ValueHint::FilePath,
1377 )]
1378 pub constraints: Vec<Maybe<PathBuf>>,
1379
1380 /// Override versions using the given requirements files.
1381 ///
1382 /// Overrides files are `requirements.txt`-like files that force a specific version of a
1383 /// requirement to be installed, regardless of the requirements declared by any constituent
1384 /// package, and regardless of whether this would be considered an invalid resolution.
1385 ///
1386 /// While constraints are _additive_, in that they're combined with the requirements of the
1387 /// constituent packages, overrides are _absolute_, in that they completely replace the
1388 /// requirements of the constituent packages.
1389 #[arg(
1390 long,
1391 alias = "override",
1392 env = EnvVars::UV_OVERRIDE,
1393 value_delimiter = ' ',
1394 value_parser = parse_maybe_file_path,
1395 value_hint = ValueHint::FilePath,
1396 )]
1397 pub overrides: Vec<Maybe<PathBuf>>,
1398
1399 /// Exclude packages from resolution using the given requirements files.
1400 ///
1401 /// Excludes files are `requirements.txt`-like files that specify packages to exclude
1402 /// from the resolution. When a package is excluded, it will be omitted from the
1403 /// dependency list entirely and its own dependencies will be ignored during the resolution
1404 /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
1405 /// any package listed in the provided file will be omitted from all resolved environments.
1406 #[arg(
1407 long,
1408 alias = "exclude",
1409 env = EnvVars::UV_EXCLUDE,
1410 value_delimiter = ' ',
1411 value_parser = parse_maybe_file_path,
1412 value_hint = ValueHint::FilePath,
1413 )]
1414 pub excludes: Vec<Maybe<PathBuf>>,
1415
1416 /// Constrain build dependencies using the given requirements files when building source
1417 /// distributions.
1418 ///
1419 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1420 /// requirement that's installed. However, including a package in a constraints file will _not_
1421 /// trigger the installation of that package.
1422 #[arg(
1423 long,
1424 short,
1425 alias = "build-constraint",
1426 env = EnvVars::UV_BUILD_CONSTRAINT,
1427 value_delimiter = ' ',
1428 value_parser = parse_maybe_file_path,
1429 value_hint = ValueHint::FilePath,
1430 )]
1431 pub build_constraints: Vec<Maybe<PathBuf>>,
1432
1433 /// Include optional dependencies from the specified extra name; may be provided more than once.
1434 ///
1435 /// Only applies to `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1436 #[arg(long, conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
1437 pub extra: Option<Vec<ExtraName>>,
1438
1439 /// Include all optional dependencies.
1440 ///
1441 /// Only applies to `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1442 #[arg(long, conflicts_with = "extra")]
1443 pub all_extras: bool,
1444
1445 #[arg(long, overrides_with("all_extras"), hide = true)]
1446 pub no_all_extras: bool,
1447
1448 /// Install the specified dependency group from a `pyproject.toml`.
1449 ///
1450 /// If no path is provided, the `pyproject.toml` in the working directory is used.
1451 ///
1452 /// May be provided multiple times.
1453 #[arg(long, group = "sources")]
1454 pub group: Vec<PipGroupName>,
1455
1456 #[command(flatten)]
1457 pub resolver: ResolverArgs,
1458
1459 #[command(flatten)]
1460 pub refresh: RefreshArgs,
1461
1462 /// Ignore package dependencies, instead only add those packages explicitly listed
1463 /// on the command line to the resulting requirements file.
1464 #[arg(long)]
1465 pub no_deps: bool,
1466
1467 #[arg(long, overrides_with("no_deps"), hide = true)]
1468 pub deps: bool,
1469
1470 /// Write the compiled requirements to the given `requirements.txt` or `pylock.toml` file.
1471 ///
1472 /// If the file already exists, the existing versions will be preferred when resolving
1473 /// dependencies, unless `--upgrade` is also specified.
1474 #[arg(long, short, value_hint = ValueHint::FilePath)]
1475 pub output_file: Option<PathBuf>,
1476
1477 /// The format in which the resolution should be output.
1478 ///
1479 /// Supports both `requirements.txt` and `pylock.toml` (PEP 751) output formats.
1480 ///
1481 /// uv will infer the output format from the file extension of the output file, if
1482 /// provided. Otherwise, defaults to `requirements.txt`.
1483 #[arg(long, value_enum)]
1484 pub format: Option<PipCompileFormat>,
1485
1486 /// Include extras in the output file.
1487 ///
1488 /// By default, uv strips extras, as any packages pulled in by the extras are already included
1489 /// as dependencies in the output file directly. Further, output files generated with
1490 /// `--no-strip-extras` cannot be used as constraints files in `install` and `sync` invocations.
1491 #[arg(long, overrides_with("strip_extras"))]
1492 pub no_strip_extras: bool,
1493
1494 #[arg(long, overrides_with("no_strip_extras"), hide = true)]
1495 pub strip_extras: bool,
1496
1497 /// Include environment markers in the output file.
1498 ///
1499 /// By default, uv strips environment markers, as the resolution generated by `compile` is
1500 /// only guaranteed to be correct for the target environment.
1501 #[arg(long, overrides_with("strip_markers"))]
1502 pub no_strip_markers: bool,
1503
1504 #[arg(long, overrides_with("no_strip_markers"), hide = true)]
1505 pub strip_markers: bool,
1506
1507 /// Exclude comment annotations indicating the source of each package.
1508 #[arg(long, overrides_with("annotate"))]
1509 pub no_annotate: bool,
1510
1511 #[arg(long, overrides_with("no_annotate"), hide = true)]
1512 pub annotate: bool,
1513
1514 /// Exclude the comment header at the top of the generated output file.
1515 #[arg(long, overrides_with("header"))]
1516 pub no_header: bool,
1517
1518 #[arg(long, overrides_with("no_header"), hide = true)]
1519 pub header: bool,
1520
1521 /// The style of the annotation comments included in the output file, used to indicate the
1522 /// source of each package.
1523 ///
1524 /// Defaults to `split`.
1525 #[arg(long, value_enum)]
1526 pub annotation_style: Option<AnnotationStyle>,
1527
1528 /// The header comment to include at the top of the output file generated by `uv pip compile`.
1529 ///
1530 /// Used to reflect custom build scripts and commands that wrap `uv pip compile`.
1531 #[arg(long, env = EnvVars::UV_CUSTOM_COMPILE_COMMAND, value_hint = ValueHint::Other)]
1532 pub custom_compile_command: Option<String>,
1533
1534 /// The Python interpreter to use during resolution.
1535 ///
1536 /// A Python interpreter is required for building source distributions to determine package
1537 /// metadata when there are not wheels.
1538 ///
1539 /// The interpreter is also used to determine the default minimum Python version, unless
1540 /// `--python-version` is provided.
1541 ///
1542 /// This option respects `UV_PYTHON`, but when set via environment variable, it is overridden
1543 /// by `--python-version`.
1544 ///
1545 /// See `uv help python` for details on Python discovery and supported request formats.
1546 #[arg(
1547 long,
1548 short,
1549 verbatim_doc_comment,
1550 help_heading = "Python options",
1551 value_parser = parse_maybe_string,
1552 value_hint = ValueHint::Other,
1553 )]
1554 pub python: Option<Maybe<String>>,
1555
1556 /// Install packages into the system Python environment.
1557 ///
1558 /// By default, uv uses the virtual environment in the current working directory or any parent
1559 /// directory, falling back to searching for a Python executable in `PATH`. The `--system`
1560 /// option instructs uv to avoid using a virtual environment Python and restrict its search to
1561 /// the system path.
1562 #[arg(
1563 long,
1564 env = EnvVars::UV_SYSTEM_PYTHON,
1565 value_parser = clap::builder::BoolishValueParser::new(),
1566 overrides_with("no_system")
1567 )]
1568 pub system: bool,
1569
1570 #[arg(long, overrides_with("system"), hide = true)]
1571 pub no_system: bool,
1572
1573 /// Include distribution hashes in the output file.
1574 #[arg(long, overrides_with("no_generate_hashes"))]
1575 pub generate_hashes: bool,
1576
1577 #[arg(long, overrides_with("generate_hashes"), hide = true)]
1578 pub no_generate_hashes: bool,
1579
1580 /// Don't build source distributions.
1581 ///
1582 /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
1583 /// already-built source distributions will be reused, but operations that require building
1584 /// distributions will exit with an error.
1585 ///
1586 /// Alias for `--only-binary :all:`.
1587 #[arg(
1588 long,
1589 conflicts_with = "no_binary",
1590 conflicts_with = "only_binary",
1591 overrides_with("build")
1592 )]
1593 pub no_build: bool,
1594
1595 #[arg(
1596 long,
1597 conflicts_with = "no_binary",
1598 conflicts_with = "only_binary",
1599 overrides_with("no_build"),
1600 hide = true
1601 )]
1602 pub build: bool,
1603
1604 /// Don't install pre-built wheels.
1605 ///
1606 /// The given packages will be built and installed from source. The resolver will still use
1607 /// pre-built wheels to extract package metadata, if available.
1608 ///
1609 /// Multiple packages may be provided. Disable binaries for all packages with `:all:`.
1610 /// Clear previously specified packages with `:none:`.
1611 #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1612 pub no_binary: Option<Vec<PackageNameSpecifier>>,
1613
1614 /// Only use pre-built wheels; don't build source distributions.
1615 ///
1616 /// When enabled, resolving will not run code from the given packages. The cached wheels of already-built
1617 /// source distributions will be reused, but operations that require building distributions will
1618 /// exit with an error.
1619 ///
1620 /// Multiple packages may be provided. Disable binaries for all packages with `:all:`.
1621 /// Clear previously specified packages with `:none:`.
1622 #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1623 pub only_binary: Option<Vec<PackageNameSpecifier>>,
1624
1625 /// The Python version to use for resolution.
1626 ///
1627 /// For example, `3.8` or `3.8.17`.
1628 ///
1629 /// Defaults to the version of the Python interpreter used for resolution.
1630 ///
1631 /// Defines the minimum Python version that must be supported by the
1632 /// resolved requirements.
1633 ///
1634 /// If a patch version is omitted, the minimum patch version is assumed. For
1635 /// example, `3.8` is mapped to `3.8.0`.
1636 #[arg(long, help_heading = "Python options")]
1637 pub python_version: Option<PythonVersion>,
1638
1639 /// The platform for which requirements should be resolved.
1640 ///
1641 /// Represented as a "target triple", a string that describes the target platform in terms of
1642 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
1643 /// `aarch64-apple-darwin`.
1644 ///
1645 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
1646 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
1647 ///
1648 /// When targeting iOS, the default minimum version is `13.0`. Use
1649 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
1650 ///
1651 /// When targeting Android, the default minimum Android API level is `24`. Use
1652 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
1653 #[arg(long)]
1654 pub python_platform: Option<TargetTriple>,
1655
1656 /// Perform a universal resolution, attempting to generate a single `requirements.txt` output
1657 /// file that is compatible with all operating systems, architectures, and Python
1658 /// implementations.
1659 ///
1660 /// In universal mode, the current Python version (or user-provided `--python-version`) will be
1661 /// treated as a lower bound. For example, `--universal --python-version 3.7` would produce a
1662 /// universal resolution for Python 3.7 and later.
1663 ///
1664 /// Implies `--no-strip-markers`.
1665 #[arg(
1666 long,
1667 overrides_with("no_universal"),
1668 conflicts_with("python_platform"),
1669 conflicts_with("strip_markers")
1670 )]
1671 pub universal: bool,
1672
1673 #[arg(long, overrides_with("universal"), hide = true)]
1674 pub no_universal: bool,
1675
1676 /// Specify a package to omit from the output resolution. Its dependencies will still be
1677 /// included in the resolution. Equivalent to pip-compile's `--unsafe-package` option.
1678 #[arg(long, alias = "unsafe-package", value_hint = ValueHint::Other)]
1679 pub no_emit_package: Option<Vec<PackageName>>,
1680
1681 /// Include `--index-url` and `--extra-index-url` entries in the generated output file.
1682 #[arg(long, overrides_with("no_emit_index_url"))]
1683 pub emit_index_url: bool,
1684
1685 #[arg(long, overrides_with("emit_index_url"), hide = true)]
1686 pub no_emit_index_url: bool,
1687
1688 /// Include `--find-links` entries in the generated output file.
1689 #[arg(long, overrides_with("no_emit_find_links"))]
1690 pub emit_find_links: bool,
1691
1692 #[arg(long, overrides_with("emit_find_links"), hide = true)]
1693 pub no_emit_find_links: bool,
1694
1695 /// Include `--no-binary` and `--only-binary` entries in the generated output file.
1696 #[arg(long, overrides_with("no_emit_build_options"))]
1697 pub emit_build_options: bool,
1698
1699 #[arg(long, overrides_with("emit_build_options"), hide = true)]
1700 pub no_emit_build_options: bool,
1701
1702 /// Whether to emit a marker string indicating when it is known that the
1703 /// resulting set of pinned dependencies is valid.
1704 ///
1705 /// The pinned dependencies may be valid even when the marker expression is
1706 /// false, but when the expression is true, the requirements are known to
1707 /// be correct.
1708 #[arg(long, overrides_with("no_emit_marker_expression"), hide = true)]
1709 pub emit_marker_expression: bool,
1710
1711 #[arg(long, overrides_with("emit_marker_expression"), hide = true)]
1712 pub no_emit_marker_expression: bool,
1713
1714 /// Include comment annotations indicating the index used to resolve each package (e.g.,
1715 /// `# from https://pypi.org/simple`).
1716 #[arg(long, overrides_with("no_emit_index_annotation"))]
1717 pub emit_index_annotation: bool,
1718
1719 #[arg(long, overrides_with("emit_index_annotation"), hide = true)]
1720 pub no_emit_index_annotation: bool,
1721
1722 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`).
1723 ///
1724 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
1725 /// and will instead use the defined backend.
1726 ///
1727 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
1728 /// uv will use the PyTorch index for CUDA 12.6.
1729 ///
1730 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
1731 /// installed CUDA drivers.
1732 ///
1733 /// This option is in preview and may change in any future release.
1734 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
1735 pub torch_backend: Option<TorchMode>,
1736
1737 #[command(flatten)]
1738 pub compat_args: compat::PipCompileCompatArgs,
1739}
1740
1741#[derive(Args)]
1742pub struct PipSyncArgs {
1743 /// Include the packages listed in the given files.
1744 ///
1745 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
1746 /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
1747 ///
1748 /// If a `pyproject.toml`, `setup.py`, or `setup.cfg` file is provided, uv will
1749 /// extract the requirements for the relevant project.
1750 ///
1751 /// If `-` is provided, then requirements will be read from stdin.
1752 #[arg(required(true), value_parser = parse_file_path, value_hint = ValueHint::FilePath)]
1753 pub src_file: Vec<PathBuf>,
1754
1755 /// Constrain versions using the given requirements files.
1756 ///
1757 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1758 /// requirement that's installed. However, including a package in a constraints file will _not_
1759 /// trigger the installation of that package.
1760 ///
1761 /// This is equivalent to pip's `--constraint` option.
1762 #[arg(
1763 long,
1764 short,
1765 alias = "constraint",
1766 env = EnvVars::UV_CONSTRAINT,
1767 value_delimiter = ' ',
1768 value_parser = parse_maybe_file_path,
1769 value_hint = ValueHint::FilePath,
1770 )]
1771 pub constraints: Vec<Maybe<PathBuf>>,
1772
1773 /// Constrain build dependencies using the given requirements files when building source
1774 /// distributions.
1775 ///
1776 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1777 /// requirement that's installed. However, including a package in a constraints file will _not_
1778 /// trigger the installation of that package.
1779 #[arg(
1780 long,
1781 short,
1782 alias = "build-constraint",
1783 env = EnvVars::UV_BUILD_CONSTRAINT,
1784 value_delimiter = ' ',
1785 value_parser = parse_maybe_file_path,
1786 value_hint = ValueHint::FilePath,
1787 )]
1788 pub build_constraints: Vec<Maybe<PathBuf>>,
1789
1790 /// Include optional dependencies from the specified extra name; may be provided more than once.
1791 ///
1792 /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1793 #[arg(long, conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
1794 pub extra: Option<Vec<ExtraName>>,
1795
1796 /// Include all optional dependencies.
1797 ///
1798 /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1799 #[arg(long, conflicts_with = "extra", overrides_with = "no_all_extras")]
1800 pub all_extras: bool,
1801
1802 #[arg(long, overrides_with("all_extras"), hide = true)]
1803 pub no_all_extras: bool,
1804
1805 /// Install the specified dependency group from a `pylock.toml` or `pyproject.toml`.
1806 ///
1807 /// If no path is provided, the `pylock.toml` or `pyproject.toml` in the working directory is
1808 /// used.
1809 ///
1810 /// May be provided multiple times.
1811 #[arg(long, group = "sources")]
1812 pub group: Vec<PipGroupName>,
1813
1814 #[command(flatten)]
1815 pub installer: InstallerArgs,
1816
1817 #[command(flatten)]
1818 pub refresh: RefreshArgs,
1819
1820 /// Require a matching hash for each requirement.
1821 ///
1822 /// By default, uv will verify any available hashes in the requirements file, but will not
1823 /// require that all requirements have an associated hash.
1824 ///
1825 /// When `--require-hashes` is enabled, _all_ requirements must include a hash or set of hashes,
1826 /// and _all_ requirements must either be pinned to exact versions (e.g., `==1.0.0`), or be
1827 /// specified via direct URL.
1828 ///
1829 /// Hash-checking mode introduces a number of additional constraints:
1830 ///
1831 /// - Git dependencies are not supported.
1832 /// - Editable installations are not supported.
1833 /// - Local dependencies are not supported, unless they point to a specific wheel (`.whl`) or
1834 /// source archive (`.zip`, `.tar.gz`), as opposed to a directory.
1835 #[arg(
1836 long,
1837 env = EnvVars::UV_REQUIRE_HASHES,
1838 value_parser = clap::builder::BoolishValueParser::new(),
1839 overrides_with("no_require_hashes"),
1840 )]
1841 pub require_hashes: bool,
1842
1843 #[arg(long, overrides_with("require_hashes"), hide = true)]
1844 pub no_require_hashes: bool,
1845
1846 #[arg(long, overrides_with("no_verify_hashes"), hide = true)]
1847 pub verify_hashes: bool,
1848
1849 /// Disable validation of hashes in the requirements file.
1850 ///
1851 /// By default, uv will verify any available hashes in the requirements file, but will not
1852 /// require that all requirements have an associated hash. To enforce hash validation, use
1853 /// `--require-hashes`.
1854 #[arg(
1855 long,
1856 env = EnvVars::UV_NO_VERIFY_HASHES,
1857 value_parser = clap::builder::BoolishValueParser::new(),
1858 overrides_with("verify_hashes"),
1859 )]
1860 pub no_verify_hashes: bool,
1861
1862 /// The Python interpreter into which packages should be installed.
1863 ///
1864 /// By default, syncing requires a virtual environment. A path to an alternative Python can be
1865 /// provided, but it is only recommended in continuous integration (CI) environments and should
1866 /// be used with caution, as it can modify the system Python installation.
1867 ///
1868 /// See `uv help python` for details on Python discovery and supported request formats.
1869 #[arg(
1870 long,
1871 short,
1872 env = EnvVars::UV_PYTHON,
1873 verbatim_doc_comment,
1874 help_heading = "Python options",
1875 value_parser = parse_maybe_string,
1876 value_hint = ValueHint::Other,
1877 )]
1878 pub python: Option<Maybe<String>>,
1879
1880 /// Install packages into the system Python environment.
1881 ///
1882 /// By default, uv installs into the virtual environment in the current working directory or any
1883 /// parent directory. The `--system` option instructs uv to instead use the first Python found
1884 /// in the system `PATH`.
1885 ///
1886 /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
1887 /// should be used with caution, as it can modify the system Python installation.
1888 #[arg(
1889 long,
1890 env = EnvVars::UV_SYSTEM_PYTHON,
1891 value_parser = clap::builder::BoolishValueParser::new(),
1892 overrides_with("no_system")
1893 )]
1894 pub system: bool,
1895
1896 #[arg(long, overrides_with("system"), hide = true)]
1897 pub no_system: bool,
1898
1899 /// Allow uv to modify an `EXTERNALLY-MANAGED` Python installation.
1900 ///
1901 /// WARNING: `--break-system-packages` is intended for use in continuous integration (CI)
1902 /// environments, when installing into Python installations that are managed by an external
1903 /// package manager, like `apt`. It should be used with caution, as such Python installations
1904 /// explicitly recommend against modifications by other package managers (like uv or `pip`).
1905 #[arg(
1906 long,
1907 env = EnvVars::UV_BREAK_SYSTEM_PACKAGES,
1908 value_parser = clap::builder::BoolishValueParser::new(),
1909 overrides_with("no_break_system_packages")
1910 )]
1911 pub break_system_packages: bool,
1912
1913 #[arg(long, overrides_with("break_system_packages"))]
1914 pub no_break_system_packages: bool,
1915
1916 /// Install packages into the specified directory, rather than into the virtual or system Python
1917 /// environment. The packages will be installed at the top-level of the directory.
1918 ///
1919 /// Unlike other install operations, this command does not require discovery of an existing Python
1920 /// environment and only searches for a Python interpreter to use for package resolution.
1921 /// If a suitable Python interpreter cannot be found, uv will install one.
1922 /// To disable this, add `--no-python-downloads`.
1923 #[arg(long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
1924 pub target: Option<PathBuf>,
1925
1926 /// Install packages into `lib`, `bin`, and other top-level folders under the specified
1927 /// directory, as if a virtual environment were present at that location.
1928 ///
1929 /// In general, prefer the use of `--python` to install into an alternate environment, as
1930 /// scripts and other artifacts installed via `--prefix` will reference the installing
1931 /// interpreter, rather than any interpreter added to the `--prefix` directory, rendering them
1932 /// non-portable.
1933 ///
1934 /// Unlike other install operations, this command does not require discovery of an existing Python
1935 /// environment and only searches for a Python interpreter to use for package resolution.
1936 /// If a suitable Python interpreter cannot be found, uv will install one.
1937 /// To disable this, add `--no-python-downloads`.
1938 #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
1939 pub prefix: Option<PathBuf>,
1940
1941 /// Don't build source distributions.
1942 ///
1943 /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
1944 /// already-built source distributions will be reused, but operations that require building
1945 /// distributions will exit with an error.
1946 ///
1947 /// Alias for `--only-binary :all:`.
1948 #[arg(
1949 long,
1950 conflicts_with = "no_binary",
1951 conflicts_with = "only_binary",
1952 overrides_with("build")
1953 )]
1954 pub no_build: bool,
1955
1956 #[arg(
1957 long,
1958 conflicts_with = "no_binary",
1959 conflicts_with = "only_binary",
1960 overrides_with("no_build"),
1961 hide = true
1962 )]
1963 pub build: bool,
1964
1965 /// Don't install pre-built wheels.
1966 ///
1967 /// The given packages will be built and installed from source. The resolver will still use
1968 /// pre-built wheels to extract package metadata, if available.
1969 ///
1970 /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
1971 /// previously specified packages with `:none:`.
1972 #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1973 pub no_binary: Option<Vec<PackageNameSpecifier>>,
1974
1975 /// Only use pre-built wheels; don't build source distributions.
1976 ///
1977 /// When enabled, resolving will not run code from the given packages. The cached wheels of
1978 /// already-built source distributions will be reused, but operations that require building
1979 /// distributions will exit with an error.
1980 ///
1981 /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
1982 /// previously specified packages with `:none:`.
1983 #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1984 pub only_binary: Option<Vec<PackageNameSpecifier>>,
1985
1986 /// Allow sync of empty requirements, which will clear the environment of all packages.
1987 #[arg(long, overrides_with("no_allow_empty_requirements"))]
1988 pub allow_empty_requirements: bool,
1989
1990 #[arg(long, overrides_with("allow_empty_requirements"))]
1991 pub no_allow_empty_requirements: bool,
1992
1993 /// The minimum Python version that should be supported by the requirements (e.g., `3.7` or
1994 /// `3.7.9`).
1995 ///
1996 /// If a patch version is omitted, the minimum patch version is assumed. For example, `3.7` is
1997 /// mapped to `3.7.0`.
1998 #[arg(long)]
1999 pub python_version: Option<PythonVersion>,
2000
2001 /// The platform for which requirements should be installed.
2002 ///
2003 /// Represented as a "target triple", a string that describes the target platform in terms of
2004 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
2005 /// `aarch64-apple-darwin`.
2006 ///
2007 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
2008 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2009 ///
2010 /// When targeting iOS, the default minimum version is `13.0`. Use
2011 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2012 ///
2013 /// When targeting Android, the default minimum Android API level is `24`. Use
2014 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
2015 ///
2016 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
2017 /// platform; as a result, the installed distributions may not be compatible with the _current_
2018 /// platform. Conversely, any distributions that are built from source may be incompatible with
2019 /// the _target_ platform, as they will be built for the _current_ platform. The
2020 /// `--python-platform` option is intended for advanced use cases.
2021 #[arg(long)]
2022 pub python_platform: Option<TargetTriple>,
2023
2024 /// Validate the Python environment after completing the installation, to detect packages with
2025 /// missing dependencies or other issues.
2026 #[arg(long, overrides_with("no_strict"))]
2027 pub strict: bool,
2028
2029 #[arg(long, overrides_with("strict"), hide = true)]
2030 pub no_strict: bool,
2031
2032 /// Perform a dry run, i.e., don't actually install anything but resolve the dependencies and
2033 /// print the resulting plan.
2034 #[arg(long)]
2035 pub dry_run: bool,
2036
2037 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`).
2038 ///
2039 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
2040 /// and will instead use the defined backend.
2041 ///
2042 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
2043 /// uv will use the PyTorch index for CUDA 12.6.
2044 ///
2045 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
2046 /// installed CUDA drivers.
2047 ///
2048 /// This option is in preview and may change in any future release.
2049 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
2050 pub torch_backend: Option<TorchMode>,
2051
2052 #[command(flatten)]
2053 pub compat_args: compat::PipSyncCompatArgs,
2054}
2055
2056#[derive(Args)]
2057#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
2058pub struct PipInstallArgs {
2059 /// Install all listed packages.
2060 ///
2061 /// The order of the packages is used to determine priority during resolution.
2062 #[arg(group = "sources", value_hint = ValueHint::Other)]
2063 pub package: Vec<String>,
2064
2065 /// Install the packages listed in the given files.
2066 ///
2067 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
2068 /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
2069 ///
2070 /// If a `pyproject.toml`, `setup.py`, or `setup.cfg` file is provided, uv will extract the
2071 /// requirements for the relevant project.
2072 ///
2073 /// If `-` is provided, then requirements will be read from stdin.
2074 #[arg(
2075 long,
2076 short,
2077 alias = "requirement",
2078 group = "sources",
2079 value_parser = parse_file_path,
2080 value_hint = ValueHint::FilePath,
2081 )]
2082 pub requirements: Vec<PathBuf>,
2083
2084 /// Install the editable package based on the provided local file path.
2085 #[arg(long, short, group = "sources")]
2086 pub editable: Vec<String>,
2087
2088 /// Constrain versions using the given requirements files.
2089 ///
2090 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
2091 /// requirement that's installed. However, including a package in a constraints file will _not_
2092 /// trigger the installation of that package.
2093 ///
2094 /// This is equivalent to pip's `--constraint` option.
2095 #[arg(
2096 long,
2097 short,
2098 alias = "constraint",
2099 env = EnvVars::UV_CONSTRAINT,
2100 value_delimiter = ' ',
2101 value_parser = parse_maybe_file_path,
2102 value_hint = ValueHint::FilePath,
2103 )]
2104 pub constraints: Vec<Maybe<PathBuf>>,
2105
2106 /// Override versions using the given requirements files.
2107 ///
2108 /// Overrides files are `requirements.txt`-like files that force a specific version of a
2109 /// requirement to be installed, regardless of the requirements declared by any constituent
2110 /// package, and regardless of whether this would be considered an invalid resolution.
2111 ///
2112 /// While constraints are _additive_, in that they're combined with the requirements of the
2113 /// constituent packages, overrides are _absolute_, in that they completely replace the
2114 /// requirements of the constituent packages.
2115 #[arg(
2116 long,
2117 alias = "override",
2118 env = EnvVars::UV_OVERRIDE,
2119 value_delimiter = ' ',
2120 value_parser = parse_maybe_file_path,
2121 value_hint = ValueHint::FilePath,
2122 )]
2123 pub overrides: Vec<Maybe<PathBuf>>,
2124
2125 /// Exclude packages from resolution using the given requirements files.
2126 ///
2127 /// Excludes files are `requirements.txt`-like files that specify packages to exclude
2128 /// from the resolution. When a package is excluded, it will be omitted from the
2129 /// dependency list entirely and its own dependencies will be ignored during the resolution
2130 /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
2131 /// any package listed in the provided file will be omitted from all resolved environments.
2132 #[arg(
2133 long,
2134 alias = "exclude",
2135 env = EnvVars::UV_EXCLUDE,
2136 value_delimiter = ' ',
2137 value_parser = parse_maybe_file_path,
2138 value_hint = ValueHint::FilePath,
2139 )]
2140 pub excludes: Vec<Maybe<PathBuf>>,
2141
2142 /// Constrain build dependencies using the given requirements files when building source
2143 /// distributions.
2144 ///
2145 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
2146 /// requirement that's installed. However, including a package in a constraints file will _not_
2147 /// trigger the installation of that package.
2148 #[arg(
2149 long,
2150 short,
2151 alias = "build-constraint",
2152 env = EnvVars::UV_BUILD_CONSTRAINT,
2153 value_delimiter = ' ',
2154 value_parser = parse_maybe_file_path,
2155 value_hint = ValueHint::FilePath,
2156 )]
2157 pub build_constraints: Vec<Maybe<PathBuf>>,
2158
2159 /// Include optional dependencies from the specified extra name; may be provided more than once.
2160 ///
2161 /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
2162 #[arg(long, conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
2163 pub extra: Option<Vec<ExtraName>>,
2164
2165 /// Include all optional dependencies.
2166 ///
2167 /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
2168 #[arg(long, conflicts_with = "extra", overrides_with = "no_all_extras")]
2169 pub all_extras: bool,
2170
2171 #[arg(long, overrides_with("all_extras"), hide = true)]
2172 pub no_all_extras: bool,
2173
2174 /// Install the specified dependency group from a `pylock.toml` or `pyproject.toml`.
2175 ///
2176 /// If no path is provided, the `pylock.toml` or `pyproject.toml` in the working directory is
2177 /// used.
2178 ///
2179 /// May be provided multiple times.
2180 #[arg(long, group = "sources")]
2181 pub group: Vec<PipGroupName>,
2182
2183 #[command(flatten)]
2184 pub installer: ResolverInstallerArgs,
2185
2186 #[command(flatten)]
2187 pub refresh: RefreshArgs,
2188
2189 /// Ignore package dependencies, instead only installing those packages explicitly listed
2190 /// on the command line or in the requirements files.
2191 #[arg(long, overrides_with("deps"))]
2192 pub no_deps: bool,
2193
2194 #[arg(long, overrides_with("no_deps"), hide = true)]
2195 pub deps: bool,
2196
2197 /// Require a matching hash for each requirement.
2198 ///
2199 /// By default, uv will verify any available hashes in the requirements file, but will not
2200 /// require that all requirements have an associated hash.
2201 ///
2202 /// When `--require-hashes` is enabled, _all_ requirements must include a hash or set of hashes,
2203 /// and _all_ requirements must either be pinned to exact versions (e.g., `==1.0.0`), or be
2204 /// specified via direct URL.
2205 ///
2206 /// Hash-checking mode introduces a number of additional constraints:
2207 ///
2208 /// - Git dependencies are not supported.
2209 /// - Editable installations are not supported.
2210 /// - Local dependencies are not supported, unless they point to a specific wheel (`.whl`) or
2211 /// source archive (`.zip`, `.tar.gz`), as opposed to a directory.
2212 #[arg(
2213 long,
2214 env = EnvVars::UV_REQUIRE_HASHES,
2215 value_parser = clap::builder::BoolishValueParser::new(),
2216 overrides_with("no_require_hashes"),
2217 )]
2218 pub require_hashes: bool,
2219
2220 #[arg(long, overrides_with("require_hashes"), hide = true)]
2221 pub no_require_hashes: bool,
2222
2223 #[arg(long, overrides_with("no_verify_hashes"), hide = true)]
2224 pub verify_hashes: bool,
2225
2226 /// Disable validation of hashes in the requirements file.
2227 ///
2228 /// By default, uv will verify any available hashes in the requirements file, but will not
2229 /// require that all requirements have an associated hash. To enforce hash validation, use
2230 /// `--require-hashes`.
2231 #[arg(
2232 long,
2233 env = EnvVars::UV_NO_VERIFY_HASHES,
2234 value_parser = clap::builder::BoolishValueParser::new(),
2235 overrides_with("verify_hashes"),
2236 )]
2237 pub no_verify_hashes: bool,
2238
2239 /// The Python interpreter into which packages should be installed.
2240 ///
2241 /// By default, installation requires a virtual environment. A path to an alternative Python can
2242 /// be provided, but it is only recommended in continuous integration (CI) environments and
2243 /// should be used with caution, as it can modify the system Python installation.
2244 ///
2245 /// See `uv help python` for details on Python discovery and supported request formats.
2246 #[arg(
2247 long,
2248 short,
2249 env = EnvVars::UV_PYTHON,
2250 verbatim_doc_comment,
2251 help_heading = "Python options",
2252 value_parser = parse_maybe_string,
2253 value_hint = ValueHint::Other,
2254 )]
2255 pub python: Option<Maybe<String>>,
2256
2257 /// Install packages into the system Python environment.
2258 ///
2259 /// By default, uv installs into the virtual environment in the current working directory or any
2260 /// parent directory. The `--system` option instructs uv to instead use the first Python found
2261 /// in the system `PATH`.
2262 ///
2263 /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
2264 /// should be used with caution, as it can modify the system Python installation.
2265 #[arg(
2266 long,
2267 env = EnvVars::UV_SYSTEM_PYTHON,
2268 value_parser = clap::builder::BoolishValueParser::new(),
2269 overrides_with("no_system")
2270 )]
2271 pub system: bool,
2272
2273 #[arg(long, overrides_with("system"), hide = true)]
2274 pub no_system: bool,
2275
2276 /// Allow uv to modify an `EXTERNALLY-MANAGED` Python installation.
2277 ///
2278 /// WARNING: `--break-system-packages` is intended for use in continuous integration (CI)
2279 /// environments, when installing into Python installations that are managed by an external
2280 /// package manager, like `apt`. It should be used with caution, as such Python installations
2281 /// explicitly recommend against modifications by other package managers (like uv or `pip`).
2282 #[arg(
2283 long,
2284 env = EnvVars::UV_BREAK_SYSTEM_PACKAGES,
2285 value_parser = clap::builder::BoolishValueParser::new(),
2286 overrides_with("no_break_system_packages")
2287 )]
2288 pub break_system_packages: bool,
2289
2290 #[arg(long, overrides_with("break_system_packages"))]
2291 pub no_break_system_packages: bool,
2292
2293 /// Install packages into the specified directory, rather than into the virtual or system Python
2294 /// environment. The packages will be installed at the top-level of the directory.
2295 ///
2296 /// Unlike other install operations, this command does not require discovery of an existing Python
2297 /// environment and only searches for a Python interpreter to use for package resolution.
2298 /// If a suitable Python interpreter cannot be found, uv will install one.
2299 /// To disable this, add `--no-python-downloads`.
2300 #[arg(long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2301 pub target: Option<PathBuf>,
2302
2303 /// Install packages into `lib`, `bin`, and other top-level folders under the specified
2304 /// directory, as if a virtual environment were present at that location.
2305 ///
2306 /// In general, prefer the use of `--python` to install into an alternate environment, as
2307 /// scripts and other artifacts installed via `--prefix` will reference the installing
2308 /// interpreter, rather than any interpreter added to the `--prefix` directory, rendering them
2309 /// non-portable.
2310 ///
2311 /// Unlike other install operations, this command does not require discovery of an existing Python
2312 /// environment and only searches for a Python interpreter to use for package resolution.
2313 /// If a suitable Python interpreter cannot be found, uv will install one.
2314 /// To disable this, add `--no-python-downloads`.
2315 #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2316 pub prefix: Option<PathBuf>,
2317
2318 /// Don't build source distributions.
2319 ///
2320 /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
2321 /// already-built source distributions will be reused, but operations that require building
2322 /// distributions will exit with an error.
2323 ///
2324 /// Alias for `--only-binary :all:`.
2325 #[arg(
2326 long,
2327 conflicts_with = "no_binary",
2328 conflicts_with = "only_binary",
2329 overrides_with("build")
2330 )]
2331 pub no_build: bool,
2332
2333 #[arg(
2334 long,
2335 conflicts_with = "no_binary",
2336 conflicts_with = "only_binary",
2337 overrides_with("no_build"),
2338 hide = true
2339 )]
2340 pub build: bool,
2341
2342 /// Don't install pre-built wheels.
2343 ///
2344 /// The given packages will be built and installed from source. The resolver will still use
2345 /// pre-built wheels to extract package metadata, if available.
2346 ///
2347 /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
2348 /// previously specified packages with `:none:`.
2349 #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
2350 pub no_binary: Option<Vec<PackageNameSpecifier>>,
2351
2352 /// Only use pre-built wheels; don't build source distributions.
2353 ///
2354 /// When enabled, resolving will not run code from the given packages. The cached wheels of
2355 /// already-built source distributions will be reused, but operations that require building
2356 /// distributions will exit with an error.
2357 ///
2358 /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
2359 /// previously specified packages with `:none:`.
2360 #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
2361 pub only_binary: Option<Vec<PackageNameSpecifier>>,
2362
2363 /// The minimum Python version that should be supported by the requirements (e.g., `3.7` or
2364 /// `3.7.9`).
2365 ///
2366 /// If a patch version is omitted, the minimum patch version is assumed. For example, `3.7` is
2367 /// mapped to `3.7.0`.
2368 #[arg(long)]
2369 pub python_version: Option<PythonVersion>,
2370
2371 /// The platform for which requirements should be installed.
2372 ///
2373 /// Represented as a "target triple", a string that describes the target platform in terms of
2374 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
2375 /// `aarch64-apple-darwin`.
2376 ///
2377 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
2378 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2379 ///
2380 /// When targeting iOS, the default minimum version is `13.0`. Use
2381 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2382 ///
2383 /// When targeting Android, the default minimum Android API level is `24`. Use
2384 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
2385 ///
2386 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
2387 /// platform; as a result, the installed distributions may not be compatible with the _current_
2388 /// platform. Conversely, any distributions that are built from source may be incompatible with
2389 /// the _target_ platform, as they will be built for the _current_ platform. The
2390 /// `--python-platform` option is intended for advanced use cases.
2391 #[arg(long)]
2392 pub python_platform: Option<TargetTriple>,
2393
2394 /// Do not remove extraneous packages present in the environment.
2395 #[arg(long, overrides_with("exact"), alias = "no-exact", hide = true)]
2396 pub inexact: bool,
2397
2398 /// Perform an exact sync, removing extraneous packages.
2399 ///
2400 /// By default, installing will make the minimum necessary changes to satisfy the requirements.
2401 /// When enabled, uv will update the environment to exactly match the requirements, removing
2402 /// packages that are not included in the requirements.
2403 #[arg(long, overrides_with("inexact"))]
2404 pub exact: bool,
2405
2406 /// Validate the Python environment after completing the installation, to detect packages with
2407 /// missing dependencies or other issues.
2408 #[arg(long, overrides_with("no_strict"))]
2409 pub strict: bool,
2410
2411 #[arg(long, overrides_with("strict"), hide = true)]
2412 pub no_strict: bool,
2413
2414 /// Perform a dry run, i.e., don't actually install anything but resolve the dependencies and
2415 /// print the resulting plan.
2416 #[arg(long)]
2417 pub dry_run: bool,
2418
2419 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
2420 ///
2421 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
2422 /// and will instead use the defined backend.
2423 ///
2424 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
2425 /// uv will use the PyTorch index for CUDA 12.6.
2426 ///
2427 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
2428 /// installed CUDA drivers.
2429 ///
2430 /// This option is in preview and may change in any future release.
2431 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
2432 pub torch_backend: Option<TorchMode>,
2433
2434 #[command(flatten)]
2435 pub compat_args: compat::PipInstallCompatArgs,
2436}
2437
2438#[derive(Args)]
2439#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
2440pub struct PipUninstallArgs {
2441 /// Uninstall all listed packages.
2442 #[arg(group = "sources", value_hint = ValueHint::Other)]
2443 pub package: Vec<String>,
2444
2445 /// Uninstall the packages listed in the given files.
2446 ///
2447 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
2448 /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
2449 #[arg(long, short, alias = "requirement", group = "sources", value_parser = parse_file_path, value_hint = ValueHint::FilePath)]
2450 pub requirements: Vec<PathBuf>,
2451
2452 /// The Python interpreter from which packages should be uninstalled.
2453 ///
2454 /// By default, uninstallation requires a virtual environment. A path to an alternative Python
2455 /// can be provided, but it is only recommended in continuous integration (CI) environments and
2456 /// should be used with caution, as it can modify the system Python installation.
2457 ///
2458 /// See `uv help python` for details on Python discovery and supported request formats.
2459 #[arg(
2460 long,
2461 short,
2462 env = EnvVars::UV_PYTHON,
2463 verbatim_doc_comment,
2464 help_heading = "Python options",
2465 value_parser = parse_maybe_string,
2466 value_hint = ValueHint::Other,
2467 )]
2468 pub python: Option<Maybe<String>>,
2469
2470 /// Attempt to use `keyring` for authentication for remote requirements files.
2471 ///
2472 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
2473 /// the `keyring` CLI to handle authentication.
2474 ///
2475 /// Defaults to `disabled`.
2476 #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
2477 pub keyring_provider: Option<KeyringProviderType>,
2478
2479 /// Use the system Python to uninstall packages.
2480 ///
2481 /// By default, uv uninstalls from the virtual environment in the current working directory or
2482 /// any parent directory. The `--system` option instructs uv to instead use the first Python
2483 /// found in the system `PATH`.
2484 ///
2485 /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
2486 /// should be used with caution, as it can modify the system Python installation.
2487 #[arg(
2488 long,
2489 env = EnvVars::UV_SYSTEM_PYTHON,
2490 value_parser = clap::builder::BoolishValueParser::new(),
2491 overrides_with("no_system")
2492 )]
2493 pub system: bool,
2494
2495 #[arg(long, overrides_with("system"), hide = true)]
2496 pub no_system: bool,
2497
2498 /// Allow uv to modify an `EXTERNALLY-MANAGED` Python installation.
2499 ///
2500 /// WARNING: `--break-system-packages` is intended for use in continuous integration (CI)
2501 /// environments, when installing into Python installations that are managed by an external
2502 /// package manager, like `apt`. It should be used with caution, as such Python installations
2503 /// explicitly recommend against modifications by other package managers (like uv or `pip`).
2504 #[arg(
2505 long,
2506 env = EnvVars::UV_BREAK_SYSTEM_PACKAGES,
2507 value_parser = clap::builder::BoolishValueParser::new(),
2508 overrides_with("no_break_system_packages")
2509 )]
2510 pub break_system_packages: bool,
2511
2512 #[arg(long, overrides_with("break_system_packages"))]
2513 pub no_break_system_packages: bool,
2514
2515 /// Uninstall packages from the specified `--target` directory.
2516 #[arg(long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2517 pub target: Option<PathBuf>,
2518
2519 /// Uninstall packages from the specified `--prefix` directory.
2520 #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2521 pub prefix: Option<PathBuf>,
2522
2523 /// Perform a dry run, i.e., don't actually uninstall anything but print the resulting plan.
2524 #[arg(long)]
2525 pub dry_run: bool,
2526
2527 #[command(flatten)]
2528 pub compat_args: compat::PipGlobalCompatArgs,
2529}
2530
2531#[derive(Args)]
2532pub struct PipFreezeArgs {
2533 /// Exclude any editable packages from output.
2534 #[arg(long)]
2535 pub exclude_editable: bool,
2536
2537 /// Validate the Python environment, to detect packages with missing dependencies and other
2538 /// issues.
2539 #[arg(long, overrides_with("no_strict"))]
2540 pub strict: bool,
2541
2542 #[arg(long, overrides_with("strict"), hide = true)]
2543 pub no_strict: bool,
2544
2545 /// The Python interpreter for which packages should be listed.
2546 ///
2547 /// By default, uv lists packages in a virtual environment but will show packages in a system
2548 /// Python environment if no virtual environment is found.
2549 ///
2550 /// See `uv help python` for details on Python discovery and supported request formats.
2551 #[arg(
2552 long,
2553 short,
2554 env = EnvVars::UV_PYTHON,
2555 verbatim_doc_comment,
2556 help_heading = "Python options",
2557 value_parser = parse_maybe_string,
2558 value_hint = ValueHint::Other,
2559 )]
2560 pub python: Option<Maybe<String>>,
2561
2562 /// Restrict to the specified installation path for listing packages (can be used multiple times).
2563 #[arg(long("path"), value_parser = parse_file_path, value_hint = ValueHint::DirPath)]
2564 pub paths: Option<Vec<PathBuf>>,
2565
2566 /// List packages in the system Python environment.
2567 ///
2568 /// Disables discovery of virtual environments.
2569 ///
2570 /// See `uv help python` for details on Python discovery.
2571 #[arg(
2572 long,
2573 env = EnvVars::UV_SYSTEM_PYTHON,
2574 value_parser = clap::builder::BoolishValueParser::new(),
2575 overrides_with("no_system")
2576 )]
2577 pub system: bool,
2578
2579 #[arg(long, overrides_with("system"), hide = true)]
2580 pub no_system: bool,
2581
2582 /// List packages from the specified `--target` directory.
2583 #[arg(long, conflicts_with_all = ["prefix", "paths"], value_hint = ValueHint::DirPath)]
2584 pub target: Option<PathBuf>,
2585
2586 /// List packages from the specified `--prefix` directory.
2587 #[arg(long, conflicts_with_all = ["target", "paths"], value_hint = ValueHint::DirPath)]
2588 pub prefix: Option<PathBuf>,
2589
2590 #[command(flatten)]
2591 pub compat_args: compat::PipGlobalCompatArgs,
2592}
2593
2594#[derive(Args)]
2595pub struct PipListArgs {
2596 /// Only include editable projects.
2597 #[arg(short, long)]
2598 pub editable: bool,
2599
2600 /// Exclude any editable packages from output.
2601 #[arg(long, conflicts_with = "editable")]
2602 pub exclude_editable: bool,
2603
2604 /// Exclude the specified package(s) from the output.
2605 #[arg(long, value_hint = ValueHint::Other)]
2606 pub r#exclude: Vec<PackageName>,
2607
2608 /// Select the output format.
2609 #[arg(long, value_enum, default_value_t = ListFormat::default())]
2610 pub format: ListFormat,
2611
2612 /// List outdated packages.
2613 ///
2614 /// The latest version of each package will be shown alongside the installed version. Up-to-date
2615 /// packages will be omitted from the output.
2616 #[arg(long, overrides_with("no_outdated"))]
2617 pub outdated: bool,
2618
2619 #[arg(long, overrides_with("outdated"), hide = true)]
2620 pub no_outdated: bool,
2621
2622 /// Validate the Python environment, to detect packages with missing dependencies and other
2623 /// issues.
2624 #[arg(long, overrides_with("no_strict"))]
2625 pub strict: bool,
2626
2627 #[arg(long, overrides_with("strict"), hide = true)]
2628 pub no_strict: bool,
2629
2630 #[command(flatten)]
2631 pub fetch: FetchArgs,
2632
2633 /// The Python interpreter for which packages should be listed.
2634 ///
2635 /// By default, uv lists packages in a virtual environment but will show packages in a system
2636 /// Python environment if no virtual environment is found.
2637 ///
2638 /// See `uv help python` for details on Python discovery and supported request formats.
2639 #[arg(
2640 long,
2641 short,
2642 env = EnvVars::UV_PYTHON,
2643 verbatim_doc_comment,
2644 help_heading = "Python options",
2645 value_parser = parse_maybe_string,
2646 value_hint = ValueHint::Other,
2647 )]
2648 pub python: Option<Maybe<String>>,
2649
2650 /// List packages in the system Python environment.
2651 ///
2652 /// Disables discovery of virtual environments.
2653 ///
2654 /// See `uv help python` for details on Python discovery.
2655 #[arg(
2656 long,
2657 env = EnvVars::UV_SYSTEM_PYTHON,
2658 value_parser = clap::builder::BoolishValueParser::new(),
2659 overrides_with("no_system")
2660 )]
2661 pub system: bool,
2662
2663 #[arg(long, overrides_with("system"), hide = true)]
2664 pub no_system: bool,
2665
2666 /// List packages from the specified `--target` directory.
2667 #[arg(long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2668 pub target: Option<PathBuf>,
2669
2670 /// List packages from the specified `--prefix` directory.
2671 #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2672 pub prefix: Option<PathBuf>,
2673
2674 #[command(flatten)]
2675 pub compat_args: compat::PipListCompatArgs,
2676}
2677
2678#[derive(Args)]
2679pub struct PipCheckArgs {
2680 /// The Python interpreter for which packages should be checked.
2681 ///
2682 /// By default, uv checks packages in a virtual environment but will check packages in a system
2683 /// Python environment if no virtual environment is found.
2684 ///
2685 /// See `uv help python` for details on Python discovery and supported request formats.
2686 #[arg(
2687 long,
2688 short,
2689 env = EnvVars::UV_PYTHON,
2690 verbatim_doc_comment,
2691 help_heading = "Python options",
2692 value_parser = parse_maybe_string,
2693 value_hint = ValueHint::Other,
2694 )]
2695 pub python: Option<Maybe<String>>,
2696
2697 /// Check packages in the system Python environment.
2698 ///
2699 /// Disables discovery of virtual environments.
2700 ///
2701 /// See `uv help python` for details on Python discovery.
2702 #[arg(
2703 long,
2704 env = EnvVars::UV_SYSTEM_PYTHON,
2705 value_parser = clap::builder::BoolishValueParser::new(),
2706 overrides_with("no_system")
2707 )]
2708 pub system: bool,
2709
2710 #[arg(long, overrides_with("system"), hide = true)]
2711 pub no_system: bool,
2712
2713 /// The Python version against which packages should be checked.
2714 ///
2715 /// By default, the installed packages are checked against the version of the current
2716 /// interpreter.
2717 #[arg(long)]
2718 pub python_version: Option<PythonVersion>,
2719
2720 /// The platform for which packages should be checked.
2721 ///
2722 /// By default, the installed packages are checked against the platform of the current
2723 /// interpreter.
2724 ///
2725 /// Represented as a "target triple", a string that describes the target platform in terms of
2726 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
2727 /// `aarch64-apple-darwin`.
2728 ///
2729 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
2730 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2731 ///
2732 /// When targeting iOS, the default minimum version is `13.0`. Use
2733 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2734 ///
2735 /// When targeting Android, the default minimum Android API level is `24`. Use
2736 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
2737 #[arg(long)]
2738 pub python_platform: Option<TargetTriple>,
2739}
2740
2741#[derive(Args)]
2742pub struct PipShowArgs {
2743 /// The package(s) to display.
2744 #[arg(value_hint = ValueHint::Other)]
2745 pub package: Vec<PackageName>,
2746
2747 /// Validate the Python environment, to detect packages with missing dependencies and other
2748 /// issues.
2749 #[arg(long, overrides_with("no_strict"))]
2750 pub strict: bool,
2751
2752 #[arg(long, overrides_with("strict"), hide = true)]
2753 pub no_strict: bool,
2754
2755 /// Show the full list of installed files for each package.
2756 #[arg(short, long)]
2757 pub files: bool,
2758
2759 /// The Python interpreter to find the package in.
2760 ///
2761 /// By default, uv looks for packages in a virtual environment but will look for packages in a
2762 /// system Python environment if no virtual environment is found.
2763 ///
2764 /// See `uv help python` for details on Python discovery and supported request formats.
2765 #[arg(
2766 long,
2767 short,
2768 env = EnvVars::UV_PYTHON,
2769 verbatim_doc_comment,
2770 help_heading = "Python options",
2771 value_parser = parse_maybe_string,
2772 value_hint = ValueHint::Other,
2773 )]
2774 pub python: Option<Maybe<String>>,
2775
2776 /// Show a package in the system Python environment.
2777 ///
2778 /// Disables discovery of virtual environments.
2779 ///
2780 /// See `uv help python` for details on Python discovery.
2781 #[arg(
2782 long,
2783 env = EnvVars::UV_SYSTEM_PYTHON,
2784 value_parser = clap::builder::BoolishValueParser::new(),
2785 overrides_with("no_system")
2786 )]
2787 pub system: bool,
2788
2789 #[arg(long, overrides_with("system"), hide = true)]
2790 pub no_system: bool,
2791
2792 /// Show a package from the specified `--target` directory.
2793 #[arg(long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2794 pub target: Option<PathBuf>,
2795
2796 /// Show a package from the specified `--prefix` directory.
2797 #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2798 pub prefix: Option<PathBuf>,
2799
2800 #[command(flatten)]
2801 pub compat_args: compat::PipGlobalCompatArgs,
2802}
2803
2804#[derive(Args)]
2805pub struct PipTreeArgs {
2806 /// Show the version constraint(s) imposed on each package.
2807 #[arg(long)]
2808 pub show_version_specifiers: bool,
2809
2810 #[command(flatten)]
2811 pub tree: DisplayTreeArgs,
2812
2813 /// Validate the Python environment, to detect packages with missing dependencies and other
2814 /// issues.
2815 #[arg(long, overrides_with("no_strict"))]
2816 pub strict: bool,
2817
2818 #[arg(long, overrides_with("strict"), hide = true)]
2819 pub no_strict: bool,
2820
2821 #[command(flatten)]
2822 pub fetch: FetchArgs,
2823
2824 /// The Python interpreter for which packages should be listed.
2825 ///
2826 /// By default, uv lists packages in a virtual environment but will show packages in a system
2827 /// Python environment if no virtual environment is found.
2828 ///
2829 /// See `uv help python` for details on Python discovery and supported request formats.
2830 #[arg(
2831 long,
2832 short,
2833 env = EnvVars::UV_PYTHON,
2834 verbatim_doc_comment,
2835 help_heading = "Python options",
2836 value_parser = parse_maybe_string,
2837 value_hint = ValueHint::Other,
2838 )]
2839 pub python: Option<Maybe<String>>,
2840
2841 /// List packages in the system Python environment.
2842 ///
2843 /// Disables discovery of virtual environments.
2844 ///
2845 /// See `uv help python` for details on Python discovery.
2846 #[arg(
2847 long,
2848 env = EnvVars::UV_SYSTEM_PYTHON,
2849 value_parser = clap::builder::BoolishValueParser::new(),
2850 overrides_with("no_system")
2851 )]
2852 pub system: bool,
2853
2854 #[arg(long, overrides_with("system"), hide = true)]
2855 pub no_system: bool,
2856
2857 #[command(flatten)]
2858 pub compat_args: compat::PipGlobalCompatArgs,
2859}
2860
2861#[derive(Args)]
2862pub struct PipDebugArgs {
2863 #[arg(long, hide = true)]
2864 pub platform: Option<String>,
2865
2866 #[arg(long, hide = true)]
2867 pub python_version: Option<String>,
2868
2869 #[arg(long, hide = true)]
2870 pub implementation: Option<String>,
2871
2872 #[arg(long, hide = true)]
2873 pub abi: Option<String>,
2874}
2875
2876#[derive(Args)]
2877pub struct BuildArgs {
2878 /// The directory from which distributions should be built, or a source
2879 /// distribution archive to build into a wheel.
2880 ///
2881 /// Defaults to the current working directory.
2882 #[arg(value_parser = parse_file_path, value_hint = ValueHint::DirPath)]
2883 pub src: Option<PathBuf>,
2884
2885 /// Build a specific package in the workspace.
2886 ///
2887 /// The workspace will be discovered from the provided source directory, or the current
2888 /// directory if no source directory is provided.
2889 ///
2890 /// If the workspace member does not exist, uv will exit with an error.
2891 #[arg(long, conflicts_with("all_packages"), value_hint = ValueHint::Other)]
2892 pub package: Option<PackageName>,
2893
2894 /// Builds all packages in the workspace.
2895 ///
2896 /// The workspace will be discovered from the provided source directory, or the current
2897 /// directory if no source directory is provided.
2898 ///
2899 /// If the workspace member does not exist, uv will exit with an error.
2900 #[arg(long, alias = "all", conflicts_with("package"))]
2901 pub all_packages: bool,
2902
2903 /// The output directory to which distributions should be written.
2904 ///
2905 /// Defaults to the `dist` subdirectory within the source directory, or the
2906 /// directory containing the source distribution archive.
2907 #[arg(long, short, value_parser = parse_file_path, value_hint = ValueHint::DirPath)]
2908 pub out_dir: Option<PathBuf>,
2909
2910 /// Build a source distribution ("sdist") from the given directory.
2911 #[arg(long)]
2912 pub sdist: bool,
2913
2914 /// Build a binary distribution ("wheel") from the given directory.
2915 #[arg(long)]
2916 pub wheel: bool,
2917
2918 /// When using the uv build backend, list the files that would be included when building.
2919 ///
2920 /// Skips building the actual distribution, except when the source distribution is needed to
2921 /// build the wheel. The file list is collected directly without a PEP 517 environment. It only
2922 /// works with the uv build backend, there is no PEP 517 file list build hook.
2923 ///
2924 /// This option can be combined with `--sdist` and `--wheel` for inspecting different build
2925 /// paths.
2926 // Hidden while in preview.
2927 #[arg(long, hide = true)]
2928 pub list: bool,
2929
2930 #[arg(long, overrides_with("no_build_logs"), hide = true)]
2931 pub build_logs: bool,
2932
2933 /// Hide logs from the build backend.
2934 #[arg(long, overrides_with("build_logs"))]
2935 pub no_build_logs: bool,
2936
2937 /// Always build through PEP 517, don't use the fast path for the uv build backend.
2938 ///
2939 /// By default, uv won't create a PEP 517 build environment for packages using the uv build
2940 /// backend, but use a fast path that calls into the build backend directly. This option forces
2941 /// always using PEP 517.
2942 #[arg(long, conflicts_with = "list")]
2943 pub force_pep517: bool,
2944
2945 /// Clear the output directory before the build, removing stale artifacts.
2946 #[arg(long)]
2947 pub clear: bool,
2948
2949 #[arg(long, overrides_with("no_create_gitignore"), hide = true)]
2950 pub create_gitignore: bool,
2951
2952 /// Do not create a `.gitignore` file in the output directory.
2953 ///
2954 /// By default, uv creates a `.gitignore` file in the output directory to exclude build
2955 /// artifacts from version control. When this flag is used, the file will be omitted.
2956 #[arg(long, overrides_with("create_gitignore"))]
2957 pub no_create_gitignore: bool,
2958
2959 /// Constrain build dependencies using the given requirements files when building distributions.
2960 ///
2961 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
2962 /// build dependency that's installed. However, including a package in a constraints file will
2963 /// _not_ trigger the inclusion of that package on its own.
2964 #[arg(
2965 long,
2966 short,
2967 alias = "build-constraint",
2968 env = EnvVars::UV_BUILD_CONSTRAINT,
2969 value_delimiter = ' ',
2970 value_parser = parse_maybe_file_path,
2971 value_hint = ValueHint::FilePath,
2972 )]
2973 pub build_constraints: Vec<Maybe<PathBuf>>,
2974
2975 /// Require a matching hash for each requirement.
2976 ///
2977 /// By default, uv will verify any available hashes in the requirements file, but will not
2978 /// require that all requirements have an associated hash.
2979 ///
2980 /// When `--require-hashes` is enabled, _all_ requirements must include a hash or set of hashes,
2981 /// and _all_ requirements must either be pinned to exact versions (e.g., `==1.0.0`), or be
2982 /// specified via direct URL.
2983 ///
2984 /// Hash-checking mode introduces a number of additional constraints:
2985 ///
2986 /// - Git dependencies are not supported.
2987 /// - Editable installations are not supported.
2988 /// - Local dependencies are not supported, unless they point to a specific wheel (`.whl`) or
2989 /// source archive (`.zip`, `.tar.gz`), as opposed to a directory.
2990 #[arg(
2991 long,
2992 env = EnvVars::UV_REQUIRE_HASHES,
2993 value_parser = clap::builder::BoolishValueParser::new(),
2994 overrides_with("no_require_hashes"),
2995 )]
2996 pub require_hashes: bool,
2997
2998 #[arg(long, overrides_with("require_hashes"), hide = true)]
2999 pub no_require_hashes: bool,
3000
3001 #[arg(long, overrides_with("no_verify_hashes"), hide = true)]
3002 pub verify_hashes: bool,
3003
3004 /// Disable validation of hashes in the requirements file.
3005 ///
3006 /// By default, uv will verify any available hashes in the requirements file, but will not
3007 /// require that all requirements have an associated hash. To enforce hash validation, use
3008 /// `--require-hashes`.
3009 #[arg(
3010 long,
3011 env = EnvVars::UV_NO_VERIFY_HASHES,
3012 value_parser = clap::builder::BoolishValueParser::new(),
3013 overrides_with("verify_hashes"),
3014 )]
3015 pub no_verify_hashes: bool,
3016
3017 /// The Python interpreter to use for the build environment.
3018 ///
3019 /// By default, builds are executed in isolated virtual environments. The discovered interpreter
3020 /// will be used to create those environments, and will be symlinked or copied in depending on
3021 /// the platform.
3022 ///
3023 /// See `uv help python` to view supported request formats.
3024 #[arg(
3025 long,
3026 short,
3027 env = EnvVars::UV_PYTHON,
3028 verbatim_doc_comment,
3029 help_heading = "Python options",
3030 value_parser = parse_maybe_string,
3031 value_hint = ValueHint::Other,
3032 )]
3033 pub python: Option<Maybe<String>>,
3034
3035 #[command(flatten)]
3036 pub resolver: ResolverArgs,
3037
3038 #[command(flatten)]
3039 pub build: BuildOptionsArgs,
3040
3041 #[command(flatten)]
3042 pub refresh: RefreshArgs,
3043}
3044
3045#[derive(Args)]
3046pub struct VenvArgs {
3047 /// The Python interpreter to use for the virtual environment.
3048 ///
3049 /// During virtual environment creation, uv will not look for Python interpreters in virtual
3050 /// environments.
3051 ///
3052 /// See `uv help python` for details on Python discovery and supported request formats.
3053 #[arg(
3054 long,
3055 short,
3056 env = EnvVars::UV_PYTHON,
3057 verbatim_doc_comment,
3058 help_heading = "Python options",
3059 value_parser = parse_maybe_string,
3060 value_hint = ValueHint::Other,
3061 )]
3062 pub python: Option<Maybe<String>>,
3063
3064 /// Ignore virtual environments when searching for the Python interpreter.
3065 ///
3066 /// This is the default behavior and has no effect.
3067 #[arg(
3068 long,
3069 env = EnvVars::UV_SYSTEM_PYTHON,
3070 value_parser = clap::builder::BoolishValueParser::new(),
3071 overrides_with("no_system"),
3072 hide = true,
3073 )]
3074 pub system: bool,
3075
3076 /// This flag is included for compatibility only, it has no effect.
3077 ///
3078 /// uv will never search for interpreters in virtual environments when creating a virtual
3079 /// environment.
3080 #[arg(long, overrides_with("system"), hide = true)]
3081 pub no_system: bool,
3082
3083 /// Avoid discovering a project or workspace.
3084 ///
3085 /// By default, uv searches for projects in the current directory or any parent directory to
3086 /// determine the default path of the virtual environment and check for Python version
3087 /// constraints, if any.
3088 #[arg(long, alias = "no-workspace")]
3089 pub no_project: bool,
3090
3091 /// Install seed packages (one or more of: `pip`, `setuptools`, and `wheel`) into the virtual environment.
3092 ///
3093 /// Note that `setuptools` and `wheel` are not included in Python 3.12+ environments.
3094 #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_VENV_SEED)]
3095 pub seed: bool,
3096
3097 /// Remove any existing files or directories at the target path.
3098 ///
3099 /// By default, `uv venv` will exit with an error if the given path is non-empty. The
3100 /// `--clear` option will instead clear a non-empty path before creating a new virtual
3101 /// environment.
3102 #[clap(long, short, overrides_with = "allow_existing", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_VENV_CLEAR)]
3103 pub clear: bool,
3104
3105 /// Fail without prompting if any existing files or directories are present at the target path.
3106 ///
3107 /// By default, when a TTY is available, `uv venv` will prompt to clear a non-empty directory.
3108 /// When `--no-clear` is used, the command will exit with an error instead of prompting.
3109 #[clap(
3110 long,
3111 overrides_with = "clear",
3112 conflicts_with = "allow_existing",
3113 hide = true
3114 )]
3115 pub no_clear: bool,
3116
3117 /// Preserve any existing files or directories at the target path.
3118 ///
3119 /// By default, `uv venv` will exit with an error if the given path is non-empty. The
3120 /// `--allow-existing` option will instead write to the given path, regardless of its contents,
3121 /// and without clearing it beforehand.
3122 ///
3123 /// WARNING: This option can lead to unexpected behavior if the existing virtual environment and
3124 /// the newly-created virtual environment are linked to different Python interpreters.
3125 #[clap(long, overrides_with = "clear")]
3126 pub allow_existing: bool,
3127
3128 /// The path to the virtual environment to create.
3129 ///
3130 /// Default to `.venv` in the working directory.
3131 ///
3132 /// Relative paths are resolved relative to the working directory.
3133 #[arg(value_hint = ValueHint::DirPath)]
3134 pub path: Option<PathBuf>,
3135
3136 /// Provide an alternative prompt prefix for the virtual environment.
3137 ///
3138 /// By default, the prompt is dependent on whether a path was provided to `uv venv`. If provided
3139 /// (e.g, `uv venv project`), the prompt is set to the directory name. If not provided
3140 /// (`uv venv`), the prompt is set to the current directory's name.
3141 ///
3142 /// If "." is provided, the current directory name will be used regardless of whether a path was
3143 /// provided to `uv venv`.
3144 #[arg(long, verbatim_doc_comment, value_hint = ValueHint::Other)]
3145 pub prompt: Option<String>,
3146
3147 /// Give the virtual environment access to the system site packages directory.
3148 ///
3149 /// Unlike `pip`, when a virtual environment is created with `--system-site-packages`, uv will
3150 /// _not_ take system site packages into account when running commands like `uv pip list` or `uv
3151 /// pip install`. The `--system-site-packages` flag will provide the virtual environment with
3152 /// access to the system site packages directory at runtime, but will not affect the behavior of
3153 /// uv commands.
3154 #[arg(long)]
3155 pub system_site_packages: bool,
3156
3157 /// Make the virtual environment relocatable.
3158 ///
3159 /// A relocatable virtual environment can be moved around and redistributed without invalidating
3160 /// its associated entrypoint and activation scripts.
3161 ///
3162 /// Note that this can only be guaranteed for standard `console_scripts` and `gui_scripts`.
3163 /// Other scripts may be adjusted if they ship with a generic `#!python[w]` shebang, and
3164 /// binaries are left as-is.
3165 ///
3166 /// As a result of making the environment relocatable (by way of writing relative, rather than
3167 /// absolute paths), the entrypoints and scripts themselves will _not_ be relocatable. In other
3168 /// words, copying those entrypoints and scripts to a location outside the environment will not
3169 /// work, as they reference paths relative to the environment itself.
3170 #[arg(long)]
3171 pub relocatable: bool,
3172
3173 #[command(flatten)]
3174 pub index_args: IndexArgs,
3175
3176 /// The strategy to use when resolving against multiple index URLs.
3177 ///
3178 /// By default, uv will stop at the first index on which a given package is available, and
3179 /// limit resolutions to those present on that first index (`first-index`). This prevents
3180 /// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
3181 /// same name to an alternate index.
3182 #[arg(long, value_enum, env = EnvVars::UV_INDEX_STRATEGY)]
3183 pub index_strategy: Option<IndexStrategy>,
3184
3185 /// Attempt to use `keyring` for authentication for index URLs.
3186 ///
3187 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
3188 /// the `keyring` CLI to handle authentication.
3189 ///
3190 /// Defaults to `disabled`.
3191 #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
3192 pub keyring_provider: Option<KeyringProviderType>,
3193
3194 /// Limit candidate packages to those that were uploaded prior to the given date.
3195 ///
3196 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
3197 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
3198 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
3199 /// `P7D`, `P30D`).
3200 ///
3201 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
3202 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
3203 /// Calendar units such as months and years are not allowed.
3204 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER)]
3205 pub exclude_newer: Option<ExcludeNewerValue>,
3206
3207 /// Limit candidate packages for a specific package to those that were uploaded prior to the
3208 /// given date.
3209 ///
3210 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
3211 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
3212 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
3213 /// (e.g., `24 hours`, `1 week`, `30 days`), or a ISO 8601 duration (e.g., `PT24H`, `P7D`,
3214 /// `P30D`).
3215 ///
3216 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
3217 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
3218 /// Calendar units such as months and years are not allowed.
3219 ///
3220 /// Can be provided multiple times for different packages.
3221 #[arg(long)]
3222 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
3223
3224 /// The method to use when installing packages from the global cache.
3225 ///
3226 /// This option is only used for installing seed packages.
3227 ///
3228 /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
3229 /// Windows.
3230 ///
3231 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
3232 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
3233 /// will break all installed packages by way of removing the underlying source files. Use
3234 /// symlinks with caution.
3235 #[arg(long, value_enum, env = EnvVars::UV_LINK_MODE)]
3236 pub link_mode: Option<uv_install_wheel::LinkMode>,
3237
3238 #[command(flatten)]
3239 pub refresh: RefreshArgs,
3240
3241 #[command(flatten)]
3242 pub compat_args: compat::VenvCompatArgs,
3243}
3244
3245#[derive(Parser, Debug, Clone)]
3246pub enum ExternalCommand {
3247 #[command(external_subcommand)]
3248 Cmd(Vec<OsString>),
3249}
3250
3251impl Deref for ExternalCommand {
3252 type Target = Vec<OsString>;
3253
3254 fn deref(&self) -> &Self::Target {
3255 match self {
3256 Self::Cmd(cmd) => cmd,
3257 }
3258 }
3259}
3260
3261impl DerefMut for ExternalCommand {
3262 fn deref_mut(&mut self) -> &mut Self::Target {
3263 match self {
3264 Self::Cmd(cmd) => cmd,
3265 }
3266 }
3267}
3268
3269impl ExternalCommand {
3270 pub fn split(&self) -> (Option<&OsString>, &[OsString]) {
3271 match self.as_slice() {
3272 [] => (None, &[]),
3273 [cmd, args @ ..] => (Some(cmd), args),
3274 }
3275 }
3276}
3277
3278#[derive(Debug, Default, Copy, Clone, clap::ValueEnum)]
3279pub enum AuthorFrom {
3280 /// Fetch the author information from some sources (e.g., Git) automatically.
3281 #[default]
3282 Auto,
3283 /// Fetch the author information from Git configuration only.
3284 Git,
3285 /// Do not infer the author information.
3286 None,
3287}
3288
3289#[derive(Args)]
3290pub struct InitArgs {
3291 /// The path to use for the project/script.
3292 ///
3293 /// Defaults to the current working directory when initializing an app or library; required when
3294 /// initializing a script. Accepts relative and absolute paths.
3295 ///
3296 /// If a `pyproject.toml` is found in any of the parent directories of the target path, the
3297 /// project will be added as a workspace member of the parent, unless `--no-workspace` is
3298 /// provided.
3299 #[arg(required_if_eq("script", "true"), value_hint = ValueHint::DirPath)]
3300 pub path: Option<PathBuf>,
3301
3302 /// The name of the project.
3303 ///
3304 /// Defaults to the name of the directory.
3305 #[arg(long, conflicts_with = "script", value_hint = ValueHint::Other)]
3306 pub name: Option<PackageName>,
3307
3308 /// Only create a `pyproject.toml`.
3309 ///
3310 /// Disables creating extra files like `README.md`, the `src/` tree, `.python-version` files,
3311 /// etc.
3312 ///
3313 /// When combined with `--script`, the script will only contain the inline metadata header.
3314 #[arg(long)]
3315 pub bare: bool,
3316
3317 /// Create a virtual project, rather than a package.
3318 ///
3319 /// This option is deprecated and will be removed in a future release.
3320 #[arg(long, hide = true, conflicts_with = "package")]
3321 pub r#virtual: bool,
3322
3323 /// Set up the project to be built as a Python package.
3324 ///
3325 /// Defines a `[build-system]` for the project.
3326 ///
3327 /// This is the default behavior when using `--lib` or `--build-backend`.
3328 ///
3329 /// When using `--app`, this will include a `[project.scripts]` entrypoint and use a `src/`
3330 /// project structure.
3331 #[arg(long, overrides_with = "no_package")]
3332 pub r#package: bool,
3333
3334 /// Do not set up the project to be built as a Python package.
3335 ///
3336 /// Does not include a `[build-system]` for the project.
3337 ///
3338 /// This is the default behavior when using `--app`.
3339 #[arg(long, overrides_with = "package", conflicts_with_all = ["lib", "build_backend"])]
3340 pub r#no_package: bool,
3341
3342 /// Create a project for an application.
3343 ///
3344 /// This is the default behavior if `--lib` is not requested.
3345 ///
3346 /// This project kind is for web servers, scripts, and command-line interfaces.
3347 ///
3348 /// By default, an application is not intended to be built and distributed as a Python package.
3349 /// The `--package` option can be used to create an application that is distributable, e.g., if
3350 /// you want to distribute a command-line interface via PyPI.
3351 #[arg(long, alias = "application", conflicts_with_all = ["lib", "script"])]
3352 pub r#app: bool,
3353
3354 /// Create a project for a library.
3355 ///
3356 /// A library is a project that is intended to be built and distributed as a Python package.
3357 #[arg(long, alias = "library", conflicts_with_all=["app", "script"])]
3358 pub r#lib: bool,
3359
3360 /// Create a script.
3361 ///
3362 /// A script is a standalone file with embedded metadata enumerating its dependencies, along
3363 /// with any Python version requirements, as defined in the PEP 723 specification.
3364 ///
3365 /// PEP 723 scripts can be executed directly with `uv run`.
3366 ///
3367 /// By default, adds a requirement on the system Python version; use `--python` to specify an
3368 /// alternative Python version requirement.
3369 #[arg(long, conflicts_with_all=["app", "lib", "package", "build_backend", "description"])]
3370 pub r#script: bool,
3371
3372 /// Set the project description.
3373 #[arg(long, conflicts_with = "script", overrides_with = "no_description", value_hint = ValueHint::Other)]
3374 pub description: Option<String>,
3375
3376 /// Disable the description for the project.
3377 #[arg(long, conflicts_with = "script", overrides_with = "description")]
3378 pub no_description: bool,
3379
3380 /// Initialize a version control system for the project.
3381 ///
3382 /// By default, uv will initialize a Git repository (`git`). Use `--vcs none` to explicitly
3383 /// avoid initializing a version control system.
3384 #[arg(long, value_enum, conflicts_with = "script")]
3385 pub vcs: Option<VersionControlSystem>,
3386
3387 /// Initialize a build-backend of choice for the project.
3388 ///
3389 /// Implicitly sets `--package`.
3390 #[arg(long, value_enum, conflicts_with_all=["script", "no_package"], env = EnvVars::UV_INIT_BUILD_BACKEND)]
3391 pub build_backend: Option<ProjectBuildBackend>,
3392
3393 /// Invalid option name for build backend.
3394 #[arg(
3395 long,
3396 required(false),
3397 action(clap::ArgAction::SetTrue),
3398 value_parser=clap::builder::UnknownArgumentValueParser::suggest_arg("--build-backend"),
3399 hide(true)
3400 )]
3401 backend: Option<String>,
3402
3403 /// Do not create a `README.md` file.
3404 #[arg(long)]
3405 pub no_readme: bool,
3406
3407 /// Fill in the `authors` field in the `pyproject.toml`.
3408 ///
3409 /// By default, uv will attempt to infer the author information from some sources (e.g., Git)
3410 /// (`auto`). Use `--author-from git` to only infer from Git configuration. Use `--author-from
3411 /// none` to avoid inferring the author information.
3412 #[arg(long, value_enum)]
3413 pub author_from: Option<AuthorFrom>,
3414
3415 /// Do not create a `.python-version` file for the project.
3416 ///
3417 /// By default, uv will create a `.python-version` file containing the minor version of the
3418 /// discovered Python interpreter, which will cause subsequent uv commands to use that version.
3419 #[arg(long)]
3420 pub no_pin_python: bool,
3421
3422 /// Create a `.python-version` file for the project.
3423 ///
3424 /// This is the default.
3425 #[arg(long, hide = true)]
3426 pub pin_python: bool,
3427
3428 /// Avoid discovering a workspace and create a standalone project.
3429 ///
3430 /// By default, uv searches for workspaces in the current directory or any parent directory.
3431 #[arg(long, alias = "no-project")]
3432 pub no_workspace: bool,
3433
3434 /// The Python interpreter to use to determine the minimum supported Python version.
3435 ///
3436 /// See `uv help python` to view supported request formats.
3437 #[arg(
3438 long,
3439 short,
3440 env = EnvVars::UV_PYTHON,
3441 verbatim_doc_comment,
3442 help_heading = "Python options",
3443 value_parser = parse_maybe_string,
3444 value_hint = ValueHint::Other,
3445 )]
3446 pub python: Option<Maybe<String>>,
3447}
3448
3449#[derive(Args)]
3450pub struct RunArgs {
3451 /// Include optional dependencies from the specified extra name.
3452 ///
3453 /// May be provided more than once.
3454 ///
3455 /// Optional dependencies are defined via `project.optional-dependencies` in a `pyproject.toml`.
3456 ///
3457 /// This option is only available when running in a project.
3458 #[arg(
3459 long,
3460 conflicts_with = "all_extras",
3461 conflicts_with = "only_group",
3462 value_parser = extra_name_with_clap_error,
3463 value_hint = ValueHint::Other,
3464 )]
3465 pub extra: Option<Vec<ExtraName>>,
3466
3467 /// Include all optional dependencies.
3468 ///
3469 /// Optional dependencies are defined via `project.optional-dependencies` in a `pyproject.toml`.
3470 ///
3471 /// This option is only available when running in a project.
3472 #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3473 pub all_extras: bool,
3474
3475 /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3476 ///
3477 /// May be provided multiple times.
3478 #[arg(long, value_hint = ValueHint::Other)]
3479 pub no_extra: Vec<ExtraName>,
3480
3481 #[arg(long, overrides_with("all_extras"), hide = true)]
3482 pub no_all_extras: bool,
3483
3484 /// Include the development dependency group.
3485 ///
3486 /// Development dependencies are defined via `dependency-groups.dev` or
3487 /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
3488 ///
3489 /// This option is an alias for `--group dev`.
3490 ///
3491 /// This option is only available when running in a project.
3492 #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3493 pub dev: bool,
3494
3495 /// Disable the development dependency group.
3496 ///
3497 /// This option is an alias of `--no-group dev`.
3498 /// See `--no-default-groups` to disable all default groups instead.
3499 ///
3500 /// This option is only available when running in a project.
3501 #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3502 pub no_dev: bool,
3503
3504 /// Include dependencies from the specified dependency group.
3505 ///
3506 /// May be provided multiple times.
3507 #[arg(long, conflicts_with_all = ["only_group", "only_dev"], value_hint = ValueHint::Other)]
3508 pub group: Vec<GroupName>,
3509
3510 /// Disable the specified dependency group.
3511 ///
3512 /// This option always takes precedence over default groups,
3513 /// `--all-groups`, and `--group`.
3514 ///
3515 /// May be provided multiple times.
3516 #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ', value_hint = ValueHint::Other)]
3517 pub no_group: Vec<GroupName>,
3518
3519 /// Ignore the default dependency groups.
3520 ///
3521 /// uv includes the groups defined in `tool.uv.default-groups` by default.
3522 /// This disables that option, however, specific groups can still be included with `--group`.
3523 #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
3524 pub no_default_groups: bool,
3525
3526 /// Only include dependencies from the specified dependency group.
3527 ///
3528 /// The project and its dependencies will be omitted.
3529 ///
3530 /// May be provided multiple times. Implies `--no-default-groups`.
3531 #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
3532 pub only_group: Vec<GroupName>,
3533
3534 /// Include dependencies from all dependency groups.
3535 ///
3536 /// `--no-group` can be used to exclude specific groups.
3537 #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3538 pub all_groups: bool,
3539
3540 /// Run a Python module.
3541 ///
3542 /// Equivalent to `python -m <module>`.
3543 #[arg(short, long, conflicts_with_all = ["script", "gui_script"])]
3544 pub module: bool,
3545
3546 /// Only include the development dependency group.
3547 ///
3548 /// The project and its dependencies will be omitted.
3549 ///
3550 /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3551 #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3552 pub only_dev: bool,
3553
3554 /// Install any non-editable dependencies, including the project and any workspace members, as
3555 /// editable.
3556 #[arg(long, overrides_with = "no_editable", hide = true)]
3557 pub editable: bool,
3558
3559 /// Install any editable dependencies, including the project and any workspace members, as
3560 /// non-editable.
3561 #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
3562 pub no_editable: bool,
3563
3564 /// Do not remove extraneous packages present in the environment.
3565 #[arg(long, overrides_with("exact"), alias = "no-exact", hide = true)]
3566 pub inexact: bool,
3567
3568 /// Perform an exact sync, removing extraneous packages.
3569 ///
3570 /// When enabled, uv will remove any extraneous packages from the environment. By default, `uv
3571 /// run` will make the minimum necessary changes to satisfy the requirements.
3572 #[arg(long, overrides_with("inexact"))]
3573 pub exact: bool,
3574
3575 /// Load environment variables from a `.env` file.
3576 ///
3577 /// Can be provided multiple times, with subsequent files overriding values defined in previous
3578 /// files.
3579 #[arg(long, env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
3580 pub env_file: Vec<String>,
3581
3582 /// Avoid reading environment variables from a `.env` file.
3583 #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_ENV_FILE)]
3584 pub no_env_file: bool,
3585
3586 /// The command to run.
3587 ///
3588 /// If the path to a Python script (i.e., ending in `.py`), it will be
3589 /// executed with the Python interpreter.
3590 #[command(subcommand)]
3591 pub command: Option<ExternalCommand>,
3592
3593 /// Run with the given packages installed.
3594 ///
3595 /// When used in a project, these dependencies will be layered on top of the project environment
3596 /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3597 /// specified by the project.
3598 #[arg(short = 'w', long, value_hint = ValueHint::Other)]
3599 pub with: Vec<comma::CommaSeparatedRequirements>,
3600
3601 /// Run with the given packages installed in editable mode.
3602 ///
3603 /// When used in a project, these dependencies will be layered on top of the project environment
3604 /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3605 /// specified by the project.
3606 #[arg(long, value_hint = ValueHint::DirPath)]
3607 pub with_editable: Vec<comma::CommaSeparatedRequirements>,
3608
3609 /// Run with the packages listed in the given files.
3610 ///
3611 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
3612 /// and `pylock.toml`.
3613 ///
3614 /// The same environment semantics as `--with` apply.
3615 ///
3616 /// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed.
3617 #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
3618 pub with_requirements: Vec<Maybe<PathBuf>>,
3619
3620 /// Run the command in an isolated virtual environment.
3621 ///
3622 /// Usually, the project environment is reused for performance. This option forces a fresh
3623 /// environment to be used for the project, enforcing strict isolation between dependencies and
3624 /// declaration of requirements.
3625 ///
3626 /// An editable installation is still used for the project.
3627 ///
3628 /// When used with `--with` or `--with-requirements`, the additional dependencies will still be
3629 /// layered in a second environment.
3630 #[arg(long, env = EnvVars::UV_ISOLATED, value_parser = clap::builder::BoolishValueParser::new())]
3631 pub isolated: bool,
3632
3633 /// Prefer the active virtual environment over the project's virtual environment.
3634 ///
3635 /// If the project virtual environment is active or no virtual environment is active, this has
3636 /// no effect.
3637 #[arg(long, overrides_with = "no_active")]
3638 pub active: bool,
3639
3640 /// Prefer project's virtual environment over an active environment.
3641 ///
3642 /// This is the default behavior.
3643 #[arg(long, overrides_with = "active", hide = true)]
3644 pub no_active: bool,
3645
3646 /// Avoid syncing the virtual environment.
3647 ///
3648 /// Implies `--frozen`, as the project dependencies will be ignored (i.e., the lockfile will not
3649 /// be updated, since the environment will not be synced regardless).
3650 #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new())]
3651 pub no_sync: bool,
3652
3653 /// Assert that the `uv.lock` will remain unchanged.
3654 ///
3655 /// Requires that the lockfile is up-to-date. If the lockfile is missing or
3656 /// needs to be updated, uv will exit with an error.
3657 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
3658 pub locked: bool,
3659
3660 /// Run without updating the `uv.lock` file.
3661 ///
3662 /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3663 /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3664 /// `pyproject.toml` includes changes to dependencies that have not been included in the
3665 /// lockfile yet, they will not be present in the environment.
3666 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3667 pub frozen: bool,
3668
3669 /// Run the given path as a Python script.
3670 ///
3671 /// Using `--script` will attempt to parse the path as a PEP 723 script,
3672 /// irrespective of its extension.
3673 #[arg(long, short, conflicts_with_all = ["module", "gui_script"])]
3674 pub script: bool,
3675
3676 /// Run the given path as a Python GUI script.
3677 ///
3678 /// Using `--gui-script` will attempt to parse the path as a PEP 723 script and run it with
3679 /// `pythonw.exe`, irrespective of its extension. Only available on Windows.
3680 #[arg(long, conflicts_with_all = ["script", "module"])]
3681 pub gui_script: bool,
3682
3683 #[command(flatten)]
3684 pub installer: ResolverInstallerArgs,
3685
3686 #[command(flatten)]
3687 pub build: BuildOptionsArgs,
3688
3689 #[command(flatten)]
3690 pub refresh: RefreshArgs,
3691
3692 /// Run the command with all workspace members installed.
3693 ///
3694 /// The workspace's environment (`.venv`) is updated to include all workspace members.
3695 ///
3696 /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
3697 /// to all workspace members.
3698 #[arg(long, conflicts_with = "package")]
3699 pub all_packages: bool,
3700
3701 /// Run the command in a specific package in the workspace.
3702 ///
3703 /// If the workspace member does not exist, uv will exit with an error.
3704 #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
3705 pub package: Option<PackageName>,
3706
3707 /// Avoid discovering the project or workspace.
3708 ///
3709 /// Instead of searching for projects in the current directory and parent directories, run in an
3710 /// isolated, ephemeral environment populated by the `--with` requirements.
3711 ///
3712 /// If a virtual environment is active or found in a current or parent directory, it will be
3713 /// used as if there was no project or workspace.
3714 #[arg(long, alias = "no_workspace", conflicts_with = "package")]
3715 pub no_project: bool,
3716
3717 /// The Python interpreter to use for the run environment.
3718 ///
3719 /// If the interpreter request is satisfied by a discovered environment, the environment will be
3720 /// used.
3721 ///
3722 /// See `uv help python` to view supported request formats.
3723 #[arg(
3724 long,
3725 short,
3726 env = EnvVars::UV_PYTHON,
3727 verbatim_doc_comment,
3728 help_heading = "Python options",
3729 value_parser = parse_maybe_string,
3730 value_hint = ValueHint::Other,
3731 )]
3732 pub python: Option<Maybe<String>>,
3733
3734 /// Whether to show resolver and installer output from any environment modifications.
3735 ///
3736 /// By default, environment modifications are omitted, but enabled under `--verbose`.
3737 #[arg(long, env = EnvVars::UV_SHOW_RESOLUTION, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
3738 pub show_resolution: bool,
3739
3740 /// Number of times that `uv run` will allow recursive invocations.
3741 ///
3742 /// The current recursion depth is tracked by environment variable. If environment variables are
3743 /// cleared, uv will fail to detect the recursion depth.
3744 ///
3745 /// If uv reaches the maximum recursion depth, it will exit with an error.
3746 #[arg(long, hide = true, env = EnvVars::UV_RUN_MAX_RECURSION_DEPTH)]
3747 pub max_recursion_depth: Option<u32>,
3748
3749 /// The platform for which requirements should be installed.
3750 ///
3751 /// Represented as a "target triple", a string that describes the target platform in terms of
3752 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
3753 /// `aarch64-apple-darwin`.
3754 ///
3755 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
3756 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3757 ///
3758 /// When targeting iOS, the default minimum version is `13.0`. Use
3759 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3760 ///
3761 /// When targeting Android, the default minimum Android API level is `24`. Use
3762 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
3763 ///
3764 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
3765 /// platform; as a result, the installed distributions may not be compatible with the _current_
3766 /// platform. Conversely, any distributions that are built from source may be incompatible with
3767 /// the _target_ platform, as they will be built for the _current_ platform. The
3768 /// `--python-platform` option is intended for advanced use cases.
3769 #[arg(long)]
3770 pub python_platform: Option<TargetTriple>,
3771}
3772
3773#[derive(Args)]
3774pub struct SyncArgs {
3775 /// Include optional dependencies from the specified extra name.
3776 ///
3777 /// May be provided more than once.
3778 ///
3779 /// When multiple extras or groups are specified that appear in `tool.uv.conflicts`, uv will
3780 /// report an error.
3781 ///
3782 /// Note that all optional dependencies are always included in the resolution; this option only
3783 /// affects the selection of packages to install.
3784 #[arg(
3785 long,
3786 conflicts_with = "all_extras",
3787 conflicts_with = "only_group",
3788 value_parser = extra_name_with_clap_error,
3789 value_hint = ValueHint::Other,
3790 )]
3791 pub extra: Option<Vec<ExtraName>>,
3792
3793 /// Select the output format.
3794 #[arg(long, value_enum, default_value_t = SyncFormat::default())]
3795 pub output_format: SyncFormat,
3796
3797 /// Include all optional dependencies.
3798 ///
3799 /// When two or more extras are declared as conflicting in `tool.uv.conflicts`, using this flag
3800 /// will always result in an error.
3801 ///
3802 /// Note that all optional dependencies are always included in the resolution; this option only
3803 /// affects the selection of packages to install.
3804 #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3805 pub all_extras: bool,
3806
3807 /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3808 ///
3809 /// May be provided multiple times.
3810 #[arg(long, value_hint = ValueHint::Other)]
3811 pub no_extra: Vec<ExtraName>,
3812
3813 #[arg(long, overrides_with("all_extras"), hide = true)]
3814 pub no_all_extras: bool,
3815
3816 /// Include the development dependency group.
3817 ///
3818 /// This option is an alias for `--group dev`.
3819 #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3820 pub dev: bool,
3821
3822 /// Disable the development dependency group.
3823 ///
3824 /// This option is an alias of `--no-group dev`.
3825 /// See `--no-default-groups` to disable all default groups instead.
3826 #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3827 pub no_dev: bool,
3828
3829 /// Only include the development dependency group.
3830 ///
3831 /// The project and its dependencies will be omitted.
3832 ///
3833 /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3834 #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3835 pub only_dev: bool,
3836
3837 /// Include dependencies from the specified dependency group.
3838 ///
3839 /// When multiple extras or groups are specified that appear in
3840 /// `tool.uv.conflicts`, uv will report an error.
3841 ///
3842 /// May be provided multiple times.
3843 #[arg(long, conflicts_with_all = ["only_group", "only_dev"], value_hint = ValueHint::Other)]
3844 pub group: Vec<GroupName>,
3845
3846 /// Disable the specified dependency group.
3847 ///
3848 /// This option always takes precedence over default groups,
3849 /// `--all-groups`, and `--group`.
3850 ///
3851 /// May be provided multiple times.
3852 #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ', value_hint = ValueHint::Other)]
3853 pub no_group: Vec<GroupName>,
3854
3855 /// Ignore the default dependency groups.
3856 ///
3857 /// uv includes the groups defined in `tool.uv.default-groups` by default.
3858 /// This disables that option, however, specific groups can still be included with `--group`.
3859 #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
3860 pub no_default_groups: bool,
3861
3862 /// Only include dependencies from the specified dependency group.
3863 ///
3864 /// The project and its dependencies will be omitted.
3865 ///
3866 /// May be provided multiple times. Implies `--no-default-groups`.
3867 #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
3868 pub only_group: Vec<GroupName>,
3869
3870 /// Include dependencies from all dependency groups.
3871 ///
3872 /// `--no-group` can be used to exclude specific groups.
3873 #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3874 pub all_groups: bool,
3875
3876 /// Install any non-editable dependencies, including the project and any workspace members, as
3877 /// editable.
3878 #[arg(long, overrides_with = "no_editable", hide = true)]
3879 pub editable: bool,
3880
3881 /// Install any editable dependencies, including the project and any workspace members, as
3882 /// non-editable.
3883 #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
3884 pub no_editable: bool,
3885
3886 /// Do not remove extraneous packages present in the environment.
3887 ///
3888 /// When enabled, uv will make the minimum necessary changes to satisfy the requirements.
3889 /// By default, syncing will remove any extraneous packages from the environment
3890 #[arg(long, overrides_with("exact"), alias = "no-exact")]
3891 pub inexact: bool,
3892
3893 /// Perform an exact sync, removing extraneous packages.
3894 #[arg(long, overrides_with("inexact"), hide = true)]
3895 pub exact: bool,
3896
3897 /// Sync dependencies to the active virtual environment.
3898 ///
3899 /// Instead of creating or updating the virtual environment for the project or script, the
3900 /// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
3901 /// set.
3902 #[arg(long, overrides_with = "no_active")]
3903 pub active: bool,
3904
3905 /// Prefer project's virtual environment over an active environment.
3906 ///
3907 /// This is the default behavior.
3908 #[arg(long, overrides_with = "active", hide = true)]
3909 pub no_active: bool,
3910
3911 /// Do not install the current project.
3912 ///
3913 /// By default, the current project is installed into the environment with all of its
3914 /// dependencies. The `--no-install-project` option allows the project to be excluded, but all
3915 /// of its dependencies are still installed. This is particularly useful in situations like
3916 /// building Docker images where installing the project separately from its dependencies allows
3917 /// optimal layer caching.
3918 ///
3919 /// The inverse `--only-install-project` can be used to install _only_ the project itself,
3920 /// excluding all dependencies.
3921 #[arg(long, conflicts_with = "only_install_project")]
3922 pub no_install_project: bool,
3923
3924 /// Only install the current project.
3925 #[arg(long, conflicts_with = "no_install_project", hide = true)]
3926 pub only_install_project: bool,
3927
3928 /// Do not install any workspace members, including the root project.
3929 ///
3930 /// By default, all workspace members and their dependencies are installed into the
3931 /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
3932 /// members while retaining their dependencies. This is particularly useful in situations like
3933 /// building Docker images where installing the workspace separately from its dependencies
3934 /// allows optimal layer caching.
3935 ///
3936 /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
3937 /// excluding all other dependencies.
3938 #[arg(long, conflicts_with = "only_install_workspace")]
3939 pub no_install_workspace: bool,
3940
3941 /// Only install workspace members, including the root project.
3942 #[arg(long, conflicts_with = "no_install_workspace", hide = true)]
3943 pub only_install_workspace: bool,
3944
3945 /// Do not install local path dependencies
3946 ///
3947 /// Skips the current project, workspace members, and any other local (path or editable)
3948 /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
3949 /// heavy third-party dependencies first and layer local packages separately.
3950 ///
3951 /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
3952 /// all remote dependencies.
3953 #[arg(long, conflicts_with = "only_install_local")]
3954 pub no_install_local: bool,
3955
3956 /// Only install local path dependencies
3957 #[arg(long, conflicts_with = "no_install_local", hide = true)]
3958 pub only_install_local: bool,
3959
3960 /// Do not install the given package(s).
3961 ///
3962 /// By default, all of the project's dependencies are installed into the environment. The
3963 /// `--no-install-package` option allows exclusion of specific packages. Note this can result
3964 /// in a broken environment, and should be used with caution.
3965 ///
3966 /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
3967 /// excluding all others.
3968 #[arg(long, conflicts_with = "only_install_package", value_hint = ValueHint::Other)]
3969 pub no_install_package: Vec<PackageName>,
3970
3971 /// Only install the given package(s).
3972 #[arg(long, conflicts_with = "no_install_package", hide = true, value_hint = ValueHint::Other)]
3973 pub only_install_package: Vec<PackageName>,
3974
3975 /// Assert that the `uv.lock` will remain unchanged.
3976 ///
3977 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
3978 /// uv will exit with an error.
3979 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
3980 pub locked: bool,
3981
3982 /// Sync without updating the `uv.lock` file.
3983 ///
3984 /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3985 /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3986 /// `pyproject.toml` includes changes to dependencies that have not been included in the
3987 /// lockfile yet, they will not be present in the environment.
3988 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3989 pub frozen: bool,
3990
3991 /// Perform a dry run, without writing the lockfile or modifying the project environment.
3992 ///
3993 /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
3994 /// changes to both the lockfile and the project environment, but will not modify either.
3995 #[arg(long)]
3996 pub dry_run: bool,
3997
3998 #[command(flatten)]
3999 pub installer: ResolverInstallerArgs,
4000
4001 #[command(flatten)]
4002 pub build: BuildOptionsArgs,
4003
4004 #[command(flatten)]
4005 pub refresh: RefreshArgs,
4006
4007 /// Sync all packages in the workspace.
4008 ///
4009 /// The workspace's environment (`.venv`) is updated to include all workspace members.
4010 ///
4011 /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
4012 /// to all workspace members.
4013 #[arg(long, conflicts_with = "package")]
4014 pub all_packages: bool,
4015
4016 /// Sync for specific packages in the workspace.
4017 ///
4018 /// The workspace's environment (`.venv`) is updated to reflect the subset of dependencies
4019 /// declared by the specified workspace member packages.
4020 ///
4021 /// If any workspace member does not exist, uv will exit with an error.
4022 #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
4023 pub package: Vec<PackageName>,
4024
4025 /// Sync the environment for a Python script, rather than the current project.
4026 ///
4027 /// If provided, uv will sync the dependencies based on the script's inline metadata table, in
4028 /// adherence with PEP 723.
4029 #[arg(
4030 long,
4031 conflicts_with = "all_packages",
4032 conflicts_with = "package",
4033 conflicts_with = "no_install_project",
4034 conflicts_with = "no_install_workspace",
4035 conflicts_with = "no_install_local",
4036 conflicts_with = "extra",
4037 conflicts_with = "all_extras",
4038 conflicts_with = "no_extra",
4039 conflicts_with = "no_all_extras",
4040 conflicts_with = "dev",
4041 conflicts_with = "no_dev",
4042 conflicts_with = "only_dev",
4043 conflicts_with = "group",
4044 conflicts_with = "no_group",
4045 conflicts_with = "no_default_groups",
4046 conflicts_with = "only_group",
4047 conflicts_with = "all_groups",
4048 value_hint = ValueHint::FilePath,
4049 )]
4050 pub script: Option<PathBuf>,
4051
4052 /// The Python interpreter to use for the project environment.
4053 ///
4054 /// By default, the first interpreter that meets the project's `requires-python` constraint is
4055 /// used.
4056 ///
4057 /// If a Python interpreter in a virtual environment is provided, the packages will not be
4058 /// synced to the given environment. The interpreter will be used to create a virtual
4059 /// environment in the project.
4060 ///
4061 /// See `uv help python` for details on Python discovery and supported request formats.
4062 #[arg(
4063 long,
4064 short,
4065 env = EnvVars::UV_PYTHON,
4066 verbatim_doc_comment,
4067 help_heading = "Python options",
4068 value_parser = parse_maybe_string,
4069 value_hint = ValueHint::Other,
4070 )]
4071 pub python: Option<Maybe<String>>,
4072
4073 /// The platform for which requirements should be installed.
4074 ///
4075 /// Represented as a "target triple", a string that describes the target platform in terms of
4076 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
4077 /// `aarch64-apple-darwin`.
4078 ///
4079 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
4080 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
4081 ///
4082 /// When targeting iOS, the default minimum version is `13.0`. Use
4083 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
4084 ///
4085 /// When targeting Android, the default minimum Android API level is `24`. Use
4086 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
4087 ///
4088 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
4089 /// platform; as a result, the installed distributions may not be compatible with the _current_
4090 /// platform. Conversely, any distributions that are built from source may be incompatible with
4091 /// the _target_ platform, as they will be built for the _current_ platform. The
4092 /// `--python-platform` option is intended for advanced use cases.
4093 #[arg(long)]
4094 pub python_platform: Option<TargetTriple>,
4095
4096 /// Check if the Python environment is synchronized with the project.
4097 ///
4098 /// If the environment is not up to date, uv will exit with an error.
4099 #[arg(long, overrides_with("no_check"))]
4100 pub check: bool,
4101
4102 #[arg(long, overrides_with("check"), hide = true)]
4103 pub no_check: bool,
4104}
4105
4106#[derive(Args)]
4107pub struct LockArgs {
4108 /// Check if the lockfile is up-to-date.
4109 ///
4110 /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
4111 /// missing or needs to be updated, uv will exit with an error.
4112 ///
4113 /// Equivalent to `--locked`.
4114 #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check_exists", "upgrade"], overrides_with = "check")]
4115 pub check: bool,
4116
4117 /// Check if the lockfile is up-to-date.
4118 ///
4119 /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
4120 /// missing or needs to be updated, uv will exit with an error.
4121 ///
4122 /// Equivalent to `--check`.
4123 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check_exists", "upgrade"], hide = true)]
4124 pub locked: bool,
4125
4126 /// Assert that a `uv.lock` exists without checking if it is up-to-date.
4127 ///
4128 /// Equivalent to `--frozen`.
4129 #[arg(long, alias = "frozen", env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check", "locked"])]
4130 pub check_exists: bool,
4131
4132 /// Perform a dry run, without writing the lockfile.
4133 ///
4134 /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
4135 /// changes, but will not write the lockfile to disk.
4136 #[arg(
4137 long,
4138 conflicts_with = "check_exists",
4139 conflicts_with = "check",
4140 conflicts_with = "locked"
4141 )]
4142 pub dry_run: bool,
4143
4144 /// Lock the specified Python script, rather than the current project.
4145 ///
4146 /// If provided, uv will lock the script (based on its inline metadata table, in adherence with
4147 /// PEP 723) to a `.lock` file adjacent to the script itself.
4148 #[arg(long, value_hint = ValueHint::FilePath)]
4149 pub script: Option<PathBuf>,
4150
4151 #[command(flatten)]
4152 pub resolver: ResolverArgs,
4153
4154 #[command(flatten)]
4155 pub build: BuildOptionsArgs,
4156
4157 #[command(flatten)]
4158 pub refresh: RefreshArgs,
4159
4160 /// The Python interpreter to use during resolution.
4161 ///
4162 /// A Python interpreter is required for building source distributions to determine package
4163 /// metadata when there are not wheels.
4164 ///
4165 /// The interpreter is also used as the fallback value for the minimum Python version if
4166 /// `requires-python` is not set.
4167 ///
4168 /// See `uv help python` for details on Python discovery and supported request formats.
4169 #[arg(
4170 long,
4171 short,
4172 env = EnvVars::UV_PYTHON,
4173 verbatim_doc_comment,
4174 help_heading = "Python options",
4175 value_parser = parse_maybe_string,
4176 value_hint = ValueHint::Other,
4177 )]
4178 pub python: Option<Maybe<String>>,
4179}
4180
4181#[derive(Args)]
4182#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
4183pub struct AddArgs {
4184 /// The packages to add, as PEP 508 requirements (e.g., `ruff==0.5.0`).
4185 #[arg(group = "sources", value_hint = ValueHint::Other)]
4186 pub packages: Vec<String>,
4187
4188 /// Add the packages listed in the given files.
4189 ///
4190 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
4191 /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
4192 #[arg(
4193 long,
4194 short,
4195 alias = "requirement",
4196 group = "sources",
4197 value_parser = parse_file_path,
4198 value_hint = ValueHint::FilePath,
4199 )]
4200 pub requirements: Vec<PathBuf>,
4201
4202 /// Constrain versions using the given requirements files.
4203 ///
4204 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
4205 /// requirement that's installed. The constraints will _not_ be added to the project's
4206 /// `pyproject.toml` file, but _will_ be respected during dependency resolution.
4207 ///
4208 /// This is equivalent to pip's `--constraint` option.
4209 #[arg(
4210 long,
4211 short,
4212 alias = "constraint",
4213 env = EnvVars::UV_CONSTRAINT,
4214 value_delimiter = ' ',
4215 value_parser = parse_maybe_file_path,
4216 value_hint = ValueHint::FilePath,
4217 )]
4218 pub constraints: Vec<Maybe<PathBuf>>,
4219
4220 /// Apply this marker to all added packages.
4221 #[arg(long, short, value_parser = MarkerTree::from_str, value_hint = ValueHint::Other)]
4222 pub marker: Option<MarkerTree>,
4223
4224 /// Add the requirements to the development dependency group.
4225 ///
4226 /// This option is an alias for `--group dev`.
4227 #[arg(
4228 long,
4229 conflicts_with("optional"),
4230 conflicts_with("group"),
4231 conflicts_with("script"),
4232 env = EnvVars::UV_DEV,
4233 value_parser = clap::builder::BoolishValueParser::new()
4234 )]
4235 pub dev: bool,
4236
4237 /// Add the requirements to the package's optional dependencies for the specified extra.
4238 ///
4239 /// The group may then be activated when installing the project with the `--extra` flag.
4240 ///
4241 /// To enable an optional extra for this requirement instead, see `--extra`.
4242 #[arg(long, conflicts_with("dev"), conflicts_with("group"), value_hint = ValueHint::Other)]
4243 pub optional: Option<ExtraName>,
4244
4245 /// Add the requirements to the specified dependency group.
4246 ///
4247 /// These requirements will not be included in the published metadata for the project.
4248 #[arg(
4249 long,
4250 conflicts_with("dev"),
4251 conflicts_with("optional"),
4252 conflicts_with("script"),
4253 value_hint = ValueHint::Other,
4254 )]
4255 pub group: Option<GroupName>,
4256
4257 /// Add the requirements as editable.
4258 #[arg(long, overrides_with = "no_editable")]
4259 pub editable: bool,
4260
4261 #[arg(long, overrides_with = "editable", hide = true, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
4262 pub no_editable: bool,
4263
4264 /// Add a dependency as provided.
4265 ///
4266 /// By default, uv will use the `tool.uv.sources` section to record source information for Git,
4267 /// local, editable, and direct URL requirements. When `--raw` is provided, uv will add source
4268 /// requirements to `project.dependencies`, rather than `tool.uv.sources`.
4269 ///
4270 /// Additionally, by default, uv will add bounds to your dependency, e.g., `foo>=1.0.0`. When
4271 /// `--raw` is provided, uv will add the dependency without bounds.
4272 #[arg(
4273 long,
4274 conflicts_with = "editable",
4275 conflicts_with = "no_editable",
4276 conflicts_with = "rev",
4277 conflicts_with = "tag",
4278 conflicts_with = "branch",
4279 alias = "raw-sources"
4280 )]
4281 pub raw: bool,
4282
4283 /// The kind of version specifier to use when adding dependencies.
4284 ///
4285 /// When adding a dependency to the project, if no constraint or URL is provided, a constraint
4286 /// is added based on the latest compatible version of the package. By default, a lower bound
4287 /// constraint is used, e.g., `>=1.2.3`.
4288 ///
4289 /// When `--frozen` is provided, no resolution is performed, and dependencies are always added
4290 /// without constraints.
4291 ///
4292 /// This option is in preview and may change in any future release.
4293 #[arg(long, value_enum)]
4294 pub bounds: Option<AddBoundsKind>,
4295
4296 /// Commit to use when adding a dependency from Git.
4297 #[arg(long, group = "git-ref", action = clap::ArgAction::Set, value_hint = ValueHint::Other)]
4298 pub rev: Option<String>,
4299
4300 /// Tag to use when adding a dependency from Git.
4301 #[arg(long, group = "git-ref", action = clap::ArgAction::Set, value_hint = ValueHint::Other)]
4302 pub tag: Option<String>,
4303
4304 /// Branch to use when adding a dependency from Git.
4305 #[arg(long, group = "git-ref", action = clap::ArgAction::Set, value_hint = ValueHint::Other)]
4306 pub branch: Option<String>,
4307
4308 /// Whether to use Git LFS when adding a dependency from Git.
4309 #[arg(long)]
4310 pub lfs: bool,
4311
4312 /// Extras to enable for the dependency.
4313 ///
4314 /// May be provided more than once.
4315 ///
4316 /// To add this dependency to an optional extra instead, see `--optional`.
4317 #[arg(long, value_hint = ValueHint::Other)]
4318 pub extra: Option<Vec<ExtraName>>,
4319
4320 /// Avoid syncing the virtual environment.
4321 #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
4322 pub no_sync: bool,
4323
4324 /// Assert that the `uv.lock` will remain unchanged.
4325 ///
4326 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4327 /// uv will exit with an error.
4328 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4329 pub locked: bool,
4330
4331 /// Add dependencies without re-locking the project.
4332 ///
4333 /// The project environment will not be synced.
4334 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4335 pub frozen: bool,
4336
4337 /// Prefer the active virtual environment over the project's virtual environment.
4338 ///
4339 /// If the project virtual environment is active or no virtual environment is active, this has
4340 /// no effect.
4341 #[arg(long, overrides_with = "no_active")]
4342 pub active: bool,
4343
4344 /// Prefer project's virtual environment over an active environment.
4345 ///
4346 /// This is the default behavior.
4347 #[arg(long, overrides_with = "active", hide = true)]
4348 pub no_active: bool,
4349
4350 #[command(flatten)]
4351 pub installer: ResolverInstallerArgs,
4352
4353 #[command(flatten)]
4354 pub build: BuildOptionsArgs,
4355
4356 #[command(flatten)]
4357 pub refresh: RefreshArgs,
4358
4359 /// Add the dependency to a specific package in the workspace.
4360 #[arg(long, conflicts_with = "isolated", value_hint = ValueHint::Other)]
4361 pub package: Option<PackageName>,
4362
4363 /// Add the dependency to the specified Python script, rather than to a project.
4364 ///
4365 /// If provided, uv will add the dependency to the script's inline metadata table, in adherence
4366 /// with PEP 723. If no such inline metadata table is present, a new one will be created and
4367 /// added to the script. When executed via `uv run`, uv will create a temporary environment for
4368 /// the script with all inline dependencies installed.
4369 #[arg(
4370 long,
4371 conflicts_with = "dev",
4372 conflicts_with = "optional",
4373 conflicts_with = "package",
4374 conflicts_with = "workspace",
4375 value_hint = ValueHint::FilePath,
4376 )]
4377 pub script: Option<PathBuf>,
4378
4379 /// The Python interpreter to use for resolving and syncing.
4380 ///
4381 /// See `uv help python` for details on Python discovery and supported request formats.
4382 #[arg(
4383 long,
4384 short,
4385 env = EnvVars::UV_PYTHON,
4386 verbatim_doc_comment,
4387 help_heading = "Python options",
4388 value_parser = parse_maybe_string,
4389 value_hint = ValueHint::Other,
4390 )]
4391 pub python: Option<Maybe<String>>,
4392
4393 /// Add the dependency as a workspace member.
4394 ///
4395 /// By default, uv will add path dependencies that are within the workspace directory
4396 /// as workspace members. When used with a path dependency, the package will be added
4397 /// to the workspace's `members` list in the root `pyproject.toml` file.
4398 #[arg(long, overrides_with = "no_workspace")]
4399 pub workspace: bool,
4400
4401 /// Don't add the dependency as a workspace member.
4402 ///
4403 /// By default, when adding a dependency that's a local path and is within the workspace
4404 /// directory, uv will add it as a workspace member; pass `--no-workspace` to add the package
4405 /// as direct path dependency instead.
4406 #[arg(long, overrides_with = "workspace")]
4407 pub no_workspace: bool,
4408
4409 /// Do not install the current project.
4410 ///
4411 /// By default, the current project is installed into the environment with all of its
4412 /// dependencies. The `--no-install-project` option allows the project to be excluded, but all of
4413 /// its dependencies are still installed. This is particularly useful in situations like building
4414 /// Docker images where installing the project separately from its dependencies allows optimal
4415 /// layer caching.
4416 ///
4417 /// The inverse `--only-install-project` can be used to install _only_ the project itself,
4418 /// excluding all dependencies.
4419 #[arg(
4420 long,
4421 conflicts_with = "frozen",
4422 conflicts_with = "no_sync",
4423 conflicts_with = "only_install_project"
4424 )]
4425 pub no_install_project: bool,
4426
4427 /// Only install the current project.
4428 #[arg(
4429 long,
4430 conflicts_with = "frozen",
4431 conflicts_with = "no_sync",
4432 conflicts_with = "no_install_project",
4433 hide = true
4434 )]
4435 pub only_install_project: bool,
4436
4437 /// Do not install any workspace members, including the current project.
4438 ///
4439 /// By default, all workspace members and their dependencies are installed into the
4440 /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
4441 /// members while retaining their dependencies. This is particularly useful in situations like
4442 /// building Docker images where installing the workspace separately from its dependencies
4443 /// allows optimal layer caching.
4444 ///
4445 /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
4446 /// excluding all other dependencies.
4447 #[arg(
4448 long,
4449 conflicts_with = "frozen",
4450 conflicts_with = "no_sync",
4451 conflicts_with = "only_install_workspace"
4452 )]
4453 pub no_install_workspace: bool,
4454
4455 /// Only install workspace members, including the current project.
4456 #[arg(
4457 long,
4458 conflicts_with = "frozen",
4459 conflicts_with = "no_sync",
4460 conflicts_with = "no_install_workspace",
4461 hide = true
4462 )]
4463 pub only_install_workspace: bool,
4464
4465 /// Do not install local path dependencies
4466 ///
4467 /// Skips the current project, workspace members, and any other local (path or editable)
4468 /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
4469 /// heavy third-party dependencies first and layer local packages separately.
4470 ///
4471 /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
4472 /// all remote dependencies.
4473 #[arg(
4474 long,
4475 conflicts_with = "frozen",
4476 conflicts_with = "no_sync",
4477 conflicts_with = "only_install_local"
4478 )]
4479 pub no_install_local: bool,
4480
4481 /// Only install local path dependencies
4482 #[arg(
4483 long,
4484 conflicts_with = "frozen",
4485 conflicts_with = "no_sync",
4486 conflicts_with = "no_install_local",
4487 hide = true
4488 )]
4489 pub only_install_local: bool,
4490
4491 /// Do not install the given package(s).
4492 ///
4493 /// By default, all project's dependencies are installed into the environment. The
4494 /// `--no-install-package` option allows exclusion of specific packages. Note this can result
4495 /// in a broken environment, and should be used with caution.
4496 ///
4497 /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
4498 /// excluding all others.
4499 #[arg(
4500 long,
4501 conflicts_with = "frozen",
4502 conflicts_with = "no_sync",
4503 conflicts_with = "only_install_package",
4504 value_hint = ValueHint::Other,
4505 )]
4506 pub no_install_package: Vec<PackageName>,
4507
4508 /// Only install the given package(s).
4509 #[arg(
4510 long,
4511 conflicts_with = "frozen",
4512 conflicts_with = "no_sync",
4513 conflicts_with = "no_install_package",
4514 hide = true,
4515 value_hint = ValueHint::Other,
4516 )]
4517 pub only_install_package: Vec<PackageName>,
4518}
4519
4520#[derive(Args)]
4521pub struct RemoveArgs {
4522 /// The names of the dependencies to remove (e.g., `ruff`).
4523 #[arg(required = true, value_hint = ValueHint::Other)]
4524 pub packages: Vec<Requirement<VerbatimParsedUrl>>,
4525
4526 /// Remove the packages from the development dependency group.
4527 ///
4528 /// This option is an alias for `--group dev`.
4529 #[arg(long, conflicts_with("optional"), conflicts_with("group"), env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4530 pub dev: bool,
4531
4532 /// Remove the packages from the project's optional dependencies for the specified extra.
4533 #[arg(
4534 long,
4535 conflicts_with("dev"),
4536 conflicts_with("group"),
4537 conflicts_with("script"),
4538 value_hint = ValueHint::Other,
4539 )]
4540 pub optional: Option<ExtraName>,
4541
4542 /// Remove the packages from the specified dependency group.
4543 #[arg(
4544 long,
4545 conflicts_with("dev"),
4546 conflicts_with("optional"),
4547 conflicts_with("script"),
4548 value_hint = ValueHint::Other,
4549 )]
4550 pub group: Option<GroupName>,
4551
4552 /// Avoid syncing the virtual environment after re-locking the project.
4553 #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
4554 pub no_sync: bool,
4555
4556 /// Prefer the active virtual environment over the project's virtual environment.
4557 ///
4558 /// If the project virtual environment is active or no virtual environment is active, this has
4559 /// no effect.
4560 #[arg(long, overrides_with = "no_active")]
4561 pub active: bool,
4562
4563 /// Prefer project's virtual environment over an active environment.
4564 ///
4565 /// This is the default behavior.
4566 #[arg(long, overrides_with = "active", hide = true)]
4567 pub no_active: bool,
4568
4569 /// Assert that the `uv.lock` will remain unchanged.
4570 ///
4571 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4572 /// uv will exit with an error.
4573 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4574 pub locked: bool,
4575
4576 /// Remove dependencies without re-locking the project.
4577 ///
4578 /// The project environment will not be synced.
4579 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4580 pub frozen: bool,
4581
4582 #[command(flatten)]
4583 pub installer: ResolverInstallerArgs,
4584
4585 #[command(flatten)]
4586 pub build: BuildOptionsArgs,
4587
4588 #[command(flatten)]
4589 pub refresh: RefreshArgs,
4590
4591 /// Remove the dependencies from a specific package in the workspace.
4592 #[arg(long, conflicts_with = "isolated", value_hint = ValueHint::Other)]
4593 pub package: Option<PackageName>,
4594
4595 /// Remove the dependency from the specified Python script, rather than from a project.
4596 ///
4597 /// If provided, uv will remove the dependency from the script's inline metadata table, in
4598 /// adherence with PEP 723.
4599 #[arg(long, value_hint = ValueHint::FilePath)]
4600 pub script: Option<PathBuf>,
4601
4602 /// The Python interpreter to use for resolving and syncing.
4603 ///
4604 /// See `uv help python` for details on Python discovery and supported request formats.
4605 #[arg(
4606 long,
4607 short,
4608 env = EnvVars::UV_PYTHON,
4609 verbatim_doc_comment,
4610 help_heading = "Python options",
4611 value_parser = parse_maybe_string,
4612 value_hint = ValueHint::Other,
4613 )]
4614 pub python: Option<Maybe<String>>,
4615}
4616
4617#[derive(Args)]
4618pub struct TreeArgs {
4619 /// Show a platform-independent dependency tree.
4620 ///
4621 /// Shows resolved package versions for all Python versions and platforms, rather than filtering
4622 /// to those that are relevant for the current environment.
4623 ///
4624 /// Multiple versions may be shown for a each package.
4625 #[arg(long)]
4626 pub universal: bool,
4627
4628 #[command(flatten)]
4629 pub tree: DisplayTreeArgs,
4630
4631 /// Include the development dependency group.
4632 ///
4633 /// Development dependencies are defined via `dependency-groups.dev` or
4634 /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
4635 ///
4636 /// This option is an alias for `--group dev`.
4637 #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4638 pub dev: bool,
4639
4640 /// Only include the development dependency group.
4641 ///
4642 /// The project and its dependencies will be omitted.
4643 ///
4644 /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
4645 #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
4646 pub only_dev: bool,
4647
4648 /// Disable the development dependency group.
4649 ///
4650 /// This option is an alias of `--no-group dev`.
4651 /// See `--no-default-groups` to disable all default groups instead.
4652 #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4653 pub no_dev: bool,
4654
4655 /// Include dependencies from the specified dependency group.
4656 ///
4657 /// May be provided multiple times.
4658 #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4659 pub group: Vec<GroupName>,
4660
4661 /// Disable the specified dependency group.
4662 ///
4663 /// This option always takes precedence over default groups,
4664 /// `--all-groups`, and `--group`.
4665 ///
4666 /// May be provided multiple times.
4667 #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
4668 pub no_group: Vec<GroupName>,
4669
4670 /// Ignore the default dependency groups.
4671 ///
4672 /// uv includes the groups defined in `tool.uv.default-groups` by default.
4673 /// This disables that option, however, specific groups can still be included with `--group`.
4674 #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
4675 pub no_default_groups: bool,
4676
4677 /// Only include dependencies from the specified dependency group.
4678 ///
4679 /// The project and its dependencies will be omitted.
4680 ///
4681 /// May be provided multiple times. Implies `--no-default-groups`.
4682 #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
4683 pub only_group: Vec<GroupName>,
4684
4685 /// Include dependencies from all dependency groups.
4686 ///
4687 /// `--no-group` can be used to exclude specific groups.
4688 #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4689 pub all_groups: bool,
4690
4691 /// Assert that the `uv.lock` will remain unchanged.
4692 ///
4693 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4694 /// uv will exit with an error.
4695 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4696 pub locked: bool,
4697
4698 /// Display the requirements without locking the project.
4699 ///
4700 /// If the lockfile is missing, uv will exit with an error.
4701 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4702 pub frozen: bool,
4703
4704 #[command(flatten)]
4705 pub build: BuildOptionsArgs,
4706
4707 #[command(flatten)]
4708 pub resolver: ResolverArgs,
4709
4710 /// Show the dependency tree the specified PEP 723 Python script, rather than the current
4711 /// project.
4712 ///
4713 /// If provided, uv will resolve the dependencies based on its inline metadata table, in
4714 /// adherence with PEP 723.
4715 #[arg(long, value_hint = ValueHint::FilePath)]
4716 pub script: Option<PathBuf>,
4717
4718 /// The Python version to use when filtering the tree.
4719 ///
4720 /// For example, pass `--python-version 3.10` to display the dependencies that would be included
4721 /// when installing on Python 3.10.
4722 ///
4723 /// Defaults to the version of the discovered Python interpreter.
4724 #[arg(long, conflicts_with = "universal")]
4725 pub python_version: Option<PythonVersion>,
4726
4727 /// The platform to use when filtering the tree.
4728 ///
4729 /// For example, pass `--platform windows` to display the dependencies that would be included
4730 /// when installing on Windows.
4731 ///
4732 /// Represented as a "target triple", a string that describes the target platform in terms of
4733 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
4734 /// `aarch64-apple-darwin`.
4735 #[arg(long, conflicts_with = "universal")]
4736 pub python_platform: Option<TargetTriple>,
4737
4738 /// The Python interpreter to use for locking and filtering.
4739 ///
4740 /// By default, the tree is filtered to match the platform as reported by the Python
4741 /// interpreter. Use `--universal` to display the tree for all platforms, or use
4742 /// `--python-version` or `--python-platform` to override a subset of markers.
4743 ///
4744 /// See `uv help python` for details on Python discovery and supported request formats.
4745 #[arg(
4746 long,
4747 short,
4748 env = EnvVars::UV_PYTHON,
4749 verbatim_doc_comment,
4750 help_heading = "Python options",
4751 value_parser = parse_maybe_string,
4752 value_hint = ValueHint::Other,
4753 )]
4754 pub python: Option<Maybe<String>>,
4755}
4756
4757#[derive(Args)]
4758pub struct ExportArgs {
4759 #[allow(clippy::doc_markdown)]
4760 /// The format to which `uv.lock` should be exported.
4761 ///
4762 /// Supports `requirements.txt`, `pylock.toml` (PEP 751) and CycloneDX v1.5 JSON output formats.
4763 ///
4764 /// uv will infer the output format from the file extension of the output file, if
4765 /// provided. Otherwise, defaults to `requirements.txt`.
4766 #[arg(long, value_enum)]
4767 pub format: Option<ExportFormat>,
4768
4769 /// Export the entire workspace.
4770 ///
4771 /// The dependencies for all workspace members will be included in the exported requirements
4772 /// file.
4773 ///
4774 /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
4775 /// to all workspace members.
4776 #[arg(long, conflicts_with = "package")]
4777 pub all_packages: bool,
4778
4779 /// Export the dependencies for specific packages in the workspace.
4780 ///
4781 /// If any workspace member does not exist, uv will exit with an error.
4782 #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
4783 pub package: Vec<PackageName>,
4784
4785 /// Prune the given package from the dependency tree.
4786 ///
4787 /// Pruned packages will be excluded from the exported requirements file, as will any
4788 /// dependencies that are no longer required after the pruned package is removed.
4789 #[arg(long, conflicts_with = "all_packages", value_name = "PACKAGE")]
4790 pub prune: Vec<PackageName>,
4791
4792 /// Include optional dependencies from the specified extra name.
4793 ///
4794 /// May be provided more than once.
4795 #[arg(long, conflicts_with = "all_extras", conflicts_with = "only_group", value_parser = extra_name_with_clap_error)]
4796 pub extra: Option<Vec<ExtraName>>,
4797
4798 /// Include all optional dependencies.
4799 #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
4800 pub all_extras: bool,
4801
4802 /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
4803 ///
4804 /// May be provided multiple times.
4805 #[arg(long)]
4806 pub no_extra: Vec<ExtraName>,
4807
4808 #[arg(long, overrides_with("all_extras"), hide = true)]
4809 pub no_all_extras: bool,
4810
4811 /// Include the development dependency group.
4812 ///
4813 /// This option is an alias for `--group dev`.
4814 #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4815 pub dev: bool,
4816
4817 /// Disable the development dependency group.
4818 ///
4819 /// This option is an alias of `--no-group dev`.
4820 /// See `--no-default-groups` to disable all default groups instead.
4821 #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4822 pub no_dev: bool,
4823
4824 /// Only include the development dependency group.
4825 ///
4826 /// The project and its dependencies will be omitted.
4827 ///
4828 /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
4829 #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
4830 pub only_dev: bool,
4831
4832 /// Include dependencies from the specified dependency group.
4833 ///
4834 /// May be provided multiple times.
4835 #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4836 pub group: Vec<GroupName>,
4837
4838 /// Disable the specified dependency group.
4839 ///
4840 /// This option always takes precedence over default groups,
4841 /// `--all-groups`, and `--group`.
4842 ///
4843 /// May be provided multiple times.
4844 #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
4845 pub no_group: Vec<GroupName>,
4846
4847 /// Ignore the default dependency groups.
4848 ///
4849 /// uv includes the groups defined in `tool.uv.default-groups` by default.
4850 /// This disables that option, however, specific groups can still be included with `--group`.
4851 #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
4852 pub no_default_groups: bool,
4853
4854 /// Only include dependencies from the specified dependency group.
4855 ///
4856 /// The project and its dependencies will be omitted.
4857 ///
4858 /// May be provided multiple times. Implies `--no-default-groups`.
4859 #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
4860 pub only_group: Vec<GroupName>,
4861
4862 /// Include dependencies from all dependency groups.
4863 ///
4864 /// `--no-group` can be used to exclude specific groups.
4865 #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4866 pub all_groups: bool,
4867
4868 /// Exclude comment annotations indicating the source of each package.
4869 #[arg(long, overrides_with("annotate"))]
4870 pub no_annotate: bool,
4871
4872 #[arg(long, overrides_with("no_annotate"), hide = true)]
4873 pub annotate: bool,
4874
4875 /// Exclude the comment header at the top of the generated output file.
4876 #[arg(long, overrides_with("header"))]
4877 pub no_header: bool,
4878
4879 #[arg(long, overrides_with("no_header"), hide = true)]
4880 pub header: bool,
4881
4882 /// Export any non-editable dependencies, including the project and any workspace members, as
4883 /// editable.
4884 #[arg(long, overrides_with = "no_editable", hide = true)]
4885 pub editable: bool,
4886
4887 /// Export any editable dependencies, including the project and any workspace members, as
4888 /// non-editable.
4889 #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
4890 pub no_editable: bool,
4891
4892 /// Include hashes for all dependencies.
4893 #[arg(long, overrides_with("no_hashes"), hide = true)]
4894 pub hashes: bool,
4895
4896 /// Omit hashes in the generated output.
4897 #[arg(long, overrides_with("hashes"))]
4898 pub no_hashes: bool,
4899
4900 /// Write the exported requirements to the given file.
4901 #[arg(long, short, value_hint = ValueHint::FilePath)]
4902 pub output_file: Option<PathBuf>,
4903
4904 /// Do not emit the current project.
4905 ///
4906 /// By default, the current project is included in the exported requirements file with all of
4907 /// its dependencies. The `--no-emit-project` option allows the project to be excluded, but all
4908 /// of its dependencies to remain included.
4909 ///
4910 /// The inverse `--only-emit-project` can be used to emit _only_ the project itself, excluding
4911 /// all dependencies.
4912 #[arg(
4913 long,
4914 alias = "no-install-project",
4915 conflicts_with = "only_emit_project"
4916 )]
4917 pub no_emit_project: bool,
4918
4919 /// Only emit the current project.
4920 #[arg(
4921 long,
4922 alias = "only-install-project",
4923 conflicts_with = "no_emit_project",
4924 hide = true
4925 )]
4926 pub only_emit_project: bool,
4927
4928 /// Do not emit any workspace members, including the root project.
4929 ///
4930 /// By default, all workspace members and their dependencies are included in the exported
4931 /// requirements file, with all of their dependencies. The `--no-emit-workspace` option allows
4932 /// exclusion of all the workspace members while retaining their dependencies.
4933 ///
4934 /// The inverse `--only-emit-workspace` can be used to emit _only_ workspace members, excluding
4935 /// all other dependencies.
4936 #[arg(
4937 long,
4938 alias = "no-install-workspace",
4939 conflicts_with = "only_emit_workspace"
4940 )]
4941 pub no_emit_workspace: bool,
4942
4943 /// Only emit workspace members, including the root project.
4944 #[arg(
4945 long,
4946 alias = "only-install-workspace",
4947 conflicts_with = "no_emit_workspace",
4948 hide = true
4949 )]
4950 pub only_emit_workspace: bool,
4951
4952 /// Do not include local path dependencies in the exported requirements.
4953 ///
4954 /// Omits the current project, workspace members, and any other local (path or editable)
4955 /// packages from the export. Only remote/indexed dependencies are written. Useful for Docker
4956 /// and CI flows that want to export and cache third-party dependencies first.
4957 ///
4958 /// The inverse `--only-emit-local` can be used to emit _only_ local packages, excluding all
4959 /// remote dependencies.
4960 #[arg(long, alias = "no-install-local", conflicts_with = "only_emit_local")]
4961 pub no_emit_local: bool,
4962
4963 /// Only include local path dependencies in the exported requirements.
4964 #[arg(
4965 long,
4966 alias = "only-install-local",
4967 conflicts_with = "no_emit_local",
4968 hide = true
4969 )]
4970 pub only_emit_local: bool,
4971
4972 /// Do not emit the given package(s).
4973 ///
4974 /// By default, all project's dependencies are included in the exported requirements
4975 /// file. The `--no-emit-package` option allows exclusion of specific packages.
4976 ///
4977 /// The inverse `--only-emit-package` can be used to emit _only_ the specified packages,
4978 /// excluding all others.
4979 #[arg(
4980 long,
4981 alias = "no-install-package",
4982 conflicts_with = "only_emit_package",
4983 value_hint = ValueHint::Other,
4984 )]
4985 pub no_emit_package: Vec<PackageName>,
4986
4987 /// Only emit the given package(s).
4988 #[arg(
4989 long,
4990 alias = "only-install-package",
4991 conflicts_with = "no_emit_package",
4992 hide = true,
4993 value_hint = ValueHint::Other,
4994 )]
4995 pub only_emit_package: Vec<PackageName>,
4996
4997 /// Assert that the `uv.lock` will remain unchanged.
4998 ///
4999 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
5000 /// uv will exit with an error.
5001 #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
5002 pub locked: bool,
5003
5004 /// Do not update the `uv.lock` before exporting.
5005 ///
5006 /// If a `uv.lock` does not exist, uv will exit with an error.
5007 #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
5008 pub frozen: bool,
5009
5010 #[command(flatten)]
5011 pub resolver: ResolverArgs,
5012
5013 #[command(flatten)]
5014 pub build: BuildOptionsArgs,
5015
5016 #[command(flatten)]
5017 pub refresh: RefreshArgs,
5018
5019 /// Export the dependencies for the specified PEP 723 Python script, rather than the current
5020 /// project.
5021 ///
5022 /// If provided, uv will resolve the dependencies based on its inline metadata table, in
5023 /// adherence with PEP 723.
5024 #[arg(
5025 long,
5026 conflicts_with_all = ["all_packages", "package", "no_emit_project", "no_emit_workspace"],
5027 value_hint = ValueHint::FilePath,
5028 )]
5029 pub script: Option<PathBuf>,
5030
5031 /// The Python interpreter to use during resolution.
5032 ///
5033 /// A Python interpreter is required for building source distributions to determine package
5034 /// metadata when there are not wheels.
5035 ///
5036 /// The interpreter is also used as the fallback value for the minimum Python version if
5037 /// `requires-python` is not set.
5038 ///
5039 /// See `uv help python` for details on Python discovery and supported request formats.
5040 #[arg(
5041 long,
5042 short,
5043 env = EnvVars::UV_PYTHON,
5044 verbatim_doc_comment,
5045 help_heading = "Python options",
5046 value_parser = parse_maybe_string,
5047 value_hint = ValueHint::Other,
5048 )]
5049 pub python: Option<Maybe<String>>,
5050}
5051
5052#[derive(Args)]
5053pub struct FormatArgs {
5054 /// Check if files are formatted without applying changes.
5055 #[arg(long)]
5056 pub check: bool,
5057
5058 /// Show a diff of formatting changes without applying them.
5059 ///
5060 /// Implies `--check`.
5061 #[arg(long)]
5062 pub diff: bool,
5063
5064 /// The version of Ruff to use for formatting.
5065 ///
5066 /// By default, a version of Ruff pinned by uv will be used.
5067 #[arg(long, value_hint = ValueHint::Other)]
5068 pub version: Option<String>,
5069
5070 /// Additional arguments to pass to Ruff.
5071 ///
5072 /// For example, use `uv format -- --line-length 100` to set the line length or
5073 /// `uv format -- src/module/foo.py` to format a specific file.
5074 #[arg(last = true, value_hint = ValueHint::Other)]
5075 pub extra_args: Vec<String>,
5076
5077 /// Avoid discovering a project or workspace.
5078 ///
5079 /// Instead of running the formatter in the context of the current project, run it in the
5080 /// context of the current directory. This is useful when the current directory is not a
5081 /// project.
5082 #[arg(long)]
5083 pub no_project: bool,
5084}
5085
5086#[derive(Args)]
5087pub struct AuthNamespace {
5088 #[command(subcommand)]
5089 pub command: AuthCommand,
5090}
5091
5092#[derive(Subcommand)]
5093pub enum AuthCommand {
5094 /// Login to a service
5095 Login(AuthLoginArgs),
5096 /// Logout of a service
5097 Logout(AuthLogoutArgs),
5098 /// Show the authentication token for a service
5099 Token(AuthTokenArgs),
5100 /// Show the path to the uv credentials directory.
5101 ///
5102 /// By default, credentials are stored in the uv data directory at
5103 /// `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and
5104 /// `%APPDATA%\uv\data\credentials` on Windows.
5105 ///
5106 /// The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`.
5107 ///
5108 /// Credentials are only stored in this directory when the plaintext backend is used, as
5109 /// opposed to the native backend, which uses the system keyring.
5110 Dir(AuthDirArgs),
5111 /// Act as a credential helper for external tools.
5112 ///
5113 /// Implements the Bazel credential helper protocol to provide credentials
5114 /// to external tools via JSON over stdin/stdout.
5115 ///
5116 /// This command is typically invoked by external tools.
5117 #[command(hide = true)]
5118 Helper(AuthHelperArgs),
5119}
5120
5121#[derive(Args)]
5122pub struct ToolNamespace {
5123 #[command(subcommand)]
5124 pub command: ToolCommand,
5125}
5126
5127#[derive(Subcommand)]
5128pub enum ToolCommand {
5129 /// Run a command provided by a Python package.
5130 ///
5131 /// By default, the package to install is assumed to match the command name.
5132 ///
5133 /// The name of the command can include an exact version in the format `<package>@<version>`,
5134 /// e.g., `uv tool run ruff@0.3.0`. If more complex version specification is desired or if the
5135 /// command is provided by a different package, use `--from`.
5136 ///
5137 /// `uvx` can be used to invoke Python, e.g., with `uvx python` or `uvx python@<version>`. A
5138 /// Python interpreter will be started in an isolated virtual environment.
5139 ///
5140 /// If the tool was previously installed, i.e., via `uv tool install`, the installed version
5141 /// will be used unless a version is requested or the `--isolated` flag is used.
5142 ///
5143 /// `uvx` is provided as a convenient alias for `uv tool run`, their behavior is identical.
5144 ///
5145 /// If no command is provided, the installed tools are displayed.
5146 ///
5147 /// Packages are installed into an ephemeral virtual environment in the uv cache directory.
5148 #[command(
5149 after_help = "Use `uvx` as a shortcut for `uv tool run`.\n\n\
5150 Use `uv help tool run` for more details.",
5151 after_long_help = ""
5152 )]
5153 Run(ToolRunArgs),
5154 /// Hidden alias for `uv tool run` for the `uvx` command
5155 #[command(
5156 hide = true,
5157 override_usage = "uvx [OPTIONS] [COMMAND]",
5158 about = "Run a command provided by a Python package.",
5159 after_help = "Use `uv help tool run` for more details.",
5160 after_long_help = "",
5161 display_name = "uvx",
5162 long_version = crate::version::uv_self_version()
5163 )]
5164 Uvx(UvxArgs),
5165 /// Install commands provided by a Python package.
5166 ///
5167 /// Packages are installed into an isolated virtual environment in the uv tools directory. The
5168 /// executables are linked the tool executable directory, which is determined according to the
5169 /// XDG standard and can be retrieved with `uv tool dir --bin`.
5170 ///
5171 /// If the tool was previously installed, the existing tool will generally be replaced.
5172 Install(ToolInstallArgs),
5173 /// Upgrade installed tools.
5174 ///
5175 /// If a tool was installed with version constraints, they will be respected on upgrade — to
5176 /// upgrade a tool beyond the originally provided constraints, use `uv tool install` again.
5177 ///
5178 /// If a tool was installed with specific settings, they will be respected on upgraded. For
5179 /// example, if `--prereleases allow` was provided during installation, it will continue to be
5180 /// respected in upgrades.
5181 #[command(alias = "update")]
5182 Upgrade(ToolUpgradeArgs),
5183 /// List installed tools.
5184 #[command(alias = "ls")]
5185 List(ToolListArgs),
5186 /// Uninstall a tool.
5187 Uninstall(ToolUninstallArgs),
5188 /// Ensure that the tool executable directory is on the `PATH`.
5189 ///
5190 /// If the tool executable directory is not present on the `PATH`, uv will attempt to add it to
5191 /// the relevant shell configuration files.
5192 ///
5193 /// If the shell configuration files already include a blurb to add the executable directory to
5194 /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5195 ///
5196 /// The tool executable directory is determined according to the XDG standard and can be
5197 /// retrieved with `uv tool dir --bin`.
5198 #[command(alias = "ensurepath")]
5199 UpdateShell,
5200 /// Show the path to the uv tools directory.
5201 ///
5202 /// The tools directory is used to store environments and metadata for installed tools.
5203 ///
5204 /// By default, tools are stored in the uv data directory at `$XDG_DATA_HOME/uv/tools` or
5205 /// `$HOME/.local/share/uv/tools` on Unix and `%APPDATA%\uv\data\tools` on Windows.
5206 ///
5207 /// The tool installation directory may be overridden with `$UV_TOOL_DIR`.
5208 ///
5209 /// To instead view the directory uv installs executables into, use the `--bin` flag.
5210 Dir(ToolDirArgs),
5211}
5212
5213#[derive(Args)]
5214pub struct ToolRunArgs {
5215 /// The command to run.
5216 ///
5217 /// WARNING: The documentation for [`Self::command`] is not included in help output
5218 #[command(subcommand)]
5219 pub command: Option<ExternalCommand>,
5220
5221 /// Use the given package to provide the command.
5222 ///
5223 /// By default, the package name is assumed to match the command name.
5224 #[arg(long, value_hint = ValueHint::Other)]
5225 pub from: Option<String>,
5226
5227 /// Run with the given packages installed.
5228 #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5229 pub with: Vec<comma::CommaSeparatedRequirements>,
5230
5231 /// Run with the given packages installed in editable mode
5232 ///
5233 /// When used in a project, these dependencies will be layered on top of the uv tool's
5234 /// environment in a separate, ephemeral environment. These dependencies are allowed to conflict
5235 /// with those specified.
5236 #[arg(long, value_hint = ValueHint::DirPath)]
5237 pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5238
5239 /// Run with the packages listed in the given files.
5240 ///
5241 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5242 /// and `pylock.toml`.
5243 #[arg(
5244 long,
5245 value_delimiter = ',',
5246 value_parser = parse_maybe_file_path,
5247 value_hint = ValueHint::FilePath,
5248 )]
5249 pub with_requirements: Vec<Maybe<PathBuf>>,
5250
5251 /// Constrain versions using the given requirements files.
5252 ///
5253 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5254 /// requirement that's installed. However, including a package in a constraints file will _not_
5255 /// trigger the installation of that package.
5256 ///
5257 /// This is equivalent to pip's `--constraint` option.
5258 #[arg(
5259 long,
5260 short,
5261 alias = "constraint",
5262 env = EnvVars::UV_CONSTRAINT,
5263 value_delimiter = ' ',
5264 value_parser = parse_maybe_file_path,
5265 value_hint = ValueHint::FilePath,
5266 )]
5267 pub constraints: Vec<Maybe<PathBuf>>,
5268
5269 /// Constrain build dependencies using the given requirements files when building source
5270 /// distributions.
5271 ///
5272 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5273 /// requirement that's installed. However, including a package in a constraints file will _not_
5274 /// trigger the installation of that package.
5275 #[arg(
5276 long,
5277 short,
5278 alias = "build-constraint",
5279 env = EnvVars::UV_BUILD_CONSTRAINT,
5280 value_delimiter = ' ',
5281 value_parser = parse_maybe_file_path,
5282 value_hint = ValueHint::FilePath,
5283 )]
5284 pub build_constraints: Vec<Maybe<PathBuf>>,
5285
5286 /// Override versions using the given requirements files.
5287 ///
5288 /// Overrides files are `requirements.txt`-like files that force a specific version of a
5289 /// requirement to be installed, regardless of the requirements declared by any constituent
5290 /// package, and regardless of whether this would be considered an invalid resolution.
5291 ///
5292 /// While constraints are _additive_, in that they're combined with the requirements of the
5293 /// constituent packages, overrides are _absolute_, in that they completely replace the
5294 /// requirements of the constituent packages.
5295 #[arg(
5296 long,
5297 alias = "override",
5298 env = EnvVars::UV_OVERRIDE,
5299 value_delimiter = ' ',
5300 value_parser = parse_maybe_file_path,
5301 value_hint = ValueHint::FilePath,
5302 )]
5303 pub overrides: Vec<Maybe<PathBuf>>,
5304
5305 /// Run the tool in an isolated virtual environment, ignoring any already-installed tools.
5306 #[arg(long, env = EnvVars::UV_ISOLATED, value_parser = clap::builder::BoolishValueParser::new())]
5307 pub isolated: bool,
5308
5309 /// Load environment variables from a `.env` file.
5310 ///
5311 /// Can be provided multiple times, with subsequent files overriding values defined in previous
5312 /// files.
5313 #[arg(long, value_delimiter = ' ', env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
5314 pub env_file: Vec<PathBuf>,
5315
5316 /// Avoid reading environment variables from a `.env` file.
5317 #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_ENV_FILE)]
5318 pub no_env_file: bool,
5319
5320 #[command(flatten)]
5321 pub installer: ResolverInstallerArgs,
5322
5323 #[command(flatten)]
5324 pub build: BuildOptionsArgs,
5325
5326 #[command(flatten)]
5327 pub refresh: RefreshArgs,
5328
5329 /// Whether to use Git LFS when adding a dependency from Git.
5330 #[arg(long)]
5331 pub lfs: bool,
5332
5333 /// The Python interpreter to use to build the run environment.
5334 ///
5335 /// See `uv help python` for details on Python discovery and supported request formats.
5336 #[arg(
5337 long,
5338 short,
5339 env = EnvVars::UV_PYTHON,
5340 verbatim_doc_comment,
5341 help_heading = "Python options",
5342 value_parser = parse_maybe_string,
5343 value_hint = ValueHint::Other,
5344 )]
5345 pub python: Option<Maybe<String>>,
5346
5347 /// Whether to show resolver and installer output from any environment modifications.
5348 ///
5349 /// By default, environment modifications are omitted, but enabled under `--verbose`.
5350 #[arg(long, env = EnvVars::UV_SHOW_RESOLUTION, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
5351 pub show_resolution: bool,
5352
5353 /// The platform for which requirements should be installed.
5354 ///
5355 /// Represented as a "target triple", a string that describes the target platform in terms of
5356 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5357 /// `aarch64-apple-darwin`.
5358 ///
5359 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5360 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5361 ///
5362 /// When targeting iOS, the default minimum version is `13.0`. Use
5363 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5364 ///
5365 /// When targeting Android, the default minimum Android API level is `24`. Use
5366 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5367 ///
5368 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5369 /// platform; as a result, the installed distributions may not be compatible with the _current_
5370 /// platform. Conversely, any distributions that are built from source may be incompatible with
5371 /// the _target_ platform, as they will be built for the _current_ platform. The
5372 /// `--python-platform` option is intended for advanced use cases.
5373 #[arg(long)]
5374 pub python_platform: Option<TargetTriple>,
5375
5376 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5377 ///
5378 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5379 /// and will instead use the defined backend.
5380 ///
5381 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5382 /// uv will use the PyTorch index for CUDA 12.6.
5383 ///
5384 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5385 /// installed CUDA drivers.
5386 ///
5387 /// This option is in preview and may change in any future release.
5388 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5389 pub torch_backend: Option<TorchMode>,
5390
5391 #[arg(long, hide = true)]
5392 pub generate_shell_completion: Option<clap_complete_command::Shell>,
5393}
5394
5395#[derive(Args)]
5396pub struct UvxArgs {
5397 #[command(flatten)]
5398 pub tool_run: ToolRunArgs,
5399
5400 /// Display the uvx version.
5401 #[arg(short = 'V', long, action = clap::ArgAction::Version)]
5402 pub version: Option<bool>,
5403}
5404
5405#[derive(Args)]
5406pub struct ToolInstallArgs {
5407 /// The package to install commands from.
5408 #[arg(value_hint = ValueHint::Other)]
5409 pub package: String,
5410
5411 /// The package to install commands from.
5412 ///
5413 /// This option is provided for parity with `uv tool run`, but is redundant with `package`.
5414 #[arg(long, hide = true, value_hint = ValueHint::Other)]
5415 pub from: Option<String>,
5416
5417 /// Include the following additional requirements.
5418 #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5419 pub with: Vec<comma::CommaSeparatedRequirements>,
5420
5421 /// Run with the packages listed in the given files.
5422 ///
5423 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5424 /// and `pylock.toml`.
5425 #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
5426 pub with_requirements: Vec<Maybe<PathBuf>>,
5427
5428 /// Install the target package in editable mode, such that changes in the package's source
5429 /// directory are reflected without reinstallation.
5430 #[arg(short, long)]
5431 pub editable: bool,
5432
5433 /// Include the given packages in editable mode.
5434 #[arg(long, value_hint = ValueHint::DirPath)]
5435 pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5436
5437 /// Install executables from the following packages.
5438 #[arg(long, value_hint = ValueHint::Other)]
5439 pub with_executables_from: Vec<comma::CommaSeparatedRequirements>,
5440
5441 /// Constrain versions using the given requirements files.
5442 ///
5443 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5444 /// requirement that's installed. However, including a package in a constraints file will _not_
5445 /// trigger the installation of that package.
5446 ///
5447 /// This is equivalent to pip's `--constraint` option.
5448 #[arg(
5449 long,
5450 short,
5451 alias = "constraint",
5452 env = EnvVars::UV_CONSTRAINT,
5453 value_delimiter = ' ',
5454 value_parser = parse_maybe_file_path,
5455 value_hint = ValueHint::FilePath,
5456 )]
5457 pub constraints: Vec<Maybe<PathBuf>>,
5458
5459 /// Override versions using the given requirements files.
5460 ///
5461 /// Overrides files are `requirements.txt`-like files that force a specific version of a
5462 /// requirement to be installed, regardless of the requirements declared by any constituent
5463 /// package, and regardless of whether this would be considered an invalid resolution.
5464 ///
5465 /// While constraints are _additive_, in that they're combined with the requirements of the
5466 /// constituent packages, overrides are _absolute_, in that they completely replace the
5467 /// requirements of the constituent packages.
5468 #[arg(
5469 long,
5470 alias = "override",
5471 env = EnvVars::UV_OVERRIDE,
5472 value_delimiter = ' ',
5473 value_parser = parse_maybe_file_path,
5474 value_hint = ValueHint::FilePath,
5475 )]
5476 pub overrides: Vec<Maybe<PathBuf>>,
5477
5478 /// Exclude packages from resolution using the given requirements files.
5479 ///
5480 /// Excludes files are `requirements.txt`-like files that specify packages to exclude
5481 /// from the resolution. When a package is excluded, it will be omitted from the
5482 /// dependency list entirely and its own dependencies will be ignored during the resolution
5483 /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
5484 /// any package listed in the provided file will be omitted from all resolved environments.
5485 #[arg(
5486 long,
5487 alias = "exclude",
5488 env = EnvVars::UV_EXCLUDE,
5489 value_delimiter = ' ',
5490 value_parser = parse_maybe_file_path,
5491 value_hint = ValueHint::FilePath,
5492 )]
5493 pub excludes: Vec<Maybe<PathBuf>>,
5494
5495 /// Constrain build dependencies using the given requirements files when building source
5496 /// distributions.
5497 ///
5498 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5499 /// requirement that's installed. However, including a package in a constraints file will _not_
5500 /// trigger the installation of that package.
5501 #[arg(
5502 long,
5503 short,
5504 alias = "build-constraint",
5505 env = EnvVars::UV_BUILD_CONSTRAINT,
5506 value_delimiter = ' ',
5507 value_parser = parse_maybe_file_path,
5508 value_hint = ValueHint::FilePath,
5509 )]
5510 pub build_constraints: Vec<Maybe<PathBuf>>,
5511
5512 #[command(flatten)]
5513 pub installer: ResolverInstallerArgs,
5514
5515 #[command(flatten)]
5516 pub build: BuildOptionsArgs,
5517
5518 #[command(flatten)]
5519 pub refresh: RefreshArgs,
5520
5521 /// Force installation of the tool.
5522 ///
5523 /// Will replace any existing entry points with the same name in the executable directory.
5524 #[arg(long)]
5525 pub force: bool,
5526
5527 /// Whether to use Git LFS when adding a dependency from Git.
5528 #[arg(long)]
5529 pub lfs: bool,
5530
5531 /// The Python interpreter to use to build the tool environment.
5532 ///
5533 /// See `uv help python` for details on Python discovery and supported request formats.
5534 #[arg(
5535 long,
5536 short,
5537 env = EnvVars::UV_PYTHON,
5538 verbatim_doc_comment,
5539 help_heading = "Python options",
5540 value_parser = parse_maybe_string,
5541 value_hint = ValueHint::Other,
5542 )]
5543 pub python: Option<Maybe<String>>,
5544
5545 /// The platform for which requirements should be installed.
5546 ///
5547 /// Represented as a "target triple", a string that describes the target platform in terms of
5548 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5549 /// `aarch64-apple-darwin`.
5550 ///
5551 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5552 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5553 ///
5554 /// When targeting iOS, the default minimum version is `13.0`. Use
5555 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5556 ///
5557 /// When targeting Android, the default minimum Android API level is `24`. Use
5558 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5559 ///
5560 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5561 /// platform; as a result, the installed distributions may not be compatible with the _current_
5562 /// platform. Conversely, any distributions that are built from source may be incompatible with
5563 /// the _target_ platform, as they will be built for the _current_ platform. The
5564 /// `--python-platform` option is intended for advanced use cases.
5565 #[arg(long)]
5566 pub python_platform: Option<TargetTriple>,
5567
5568 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5569 ///
5570 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5571 /// and will instead use the defined backend.
5572 ///
5573 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5574 /// uv will use the PyTorch index for CUDA 12.6.
5575 ///
5576 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5577 /// installed CUDA drivers.
5578 ///
5579 /// This option is in preview and may change in any future release.
5580 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5581 pub torch_backend: Option<TorchMode>,
5582}
5583
5584#[derive(Args)]
5585pub struct ToolListArgs {
5586 /// Whether to display the path to each tool environment and installed executable.
5587 #[arg(long)]
5588 pub show_paths: bool,
5589
5590 /// Whether to display the version specifier(s) used to install each tool.
5591 #[arg(long)]
5592 pub show_version_specifiers: bool,
5593
5594 /// Whether to display the additional requirements installed with each tool.
5595 #[arg(long)]
5596 pub show_with: bool,
5597
5598 /// Whether to display the extra requirements installed with each tool.
5599 #[arg(long)]
5600 pub show_extras: bool,
5601
5602 /// Whether to display the Python version associated with each tool.
5603 #[arg(long)]
5604 pub show_python: bool,
5605
5606 // Hide unused global Python options.
5607 #[arg(long, hide = true)]
5608 pub python_preference: Option<PythonPreference>,
5609
5610 #[arg(long, hide = true)]
5611 pub no_python_downloads: bool,
5612}
5613
5614#[derive(Args)]
5615pub struct ToolDirArgs {
5616 /// Show the directory into which `uv tool` will install executables.
5617 ///
5618 /// By default, `uv tool dir` shows the directory into which the tool Python environments
5619 /// themselves are installed, rather than the directory containing the linked executables.
5620 ///
5621 /// The tool executable directory is determined according to the XDG standard and is derived
5622 /// from the following environment variables, in order of preference:
5623 ///
5624 /// - `$UV_TOOL_BIN_DIR`
5625 /// - `$XDG_BIN_HOME`
5626 /// - `$XDG_DATA_HOME/../bin`
5627 /// - `$HOME/.local/bin`
5628 #[arg(long, verbatim_doc_comment)]
5629 pub bin: bool,
5630}
5631
5632#[derive(Args)]
5633pub struct ToolUninstallArgs {
5634 /// The name of the tool to uninstall.
5635 #[arg(required = true, value_hint = ValueHint::Other)]
5636 pub name: Vec<PackageName>,
5637
5638 /// Uninstall all tools.
5639 #[arg(long, conflicts_with("name"))]
5640 pub all: bool,
5641}
5642
5643#[derive(Args)]
5644pub struct ToolUpgradeArgs {
5645 /// The name of the tool to upgrade, along with an optional version specifier.
5646 #[arg(required = true, value_hint = ValueHint::Other)]
5647 pub name: Vec<String>,
5648
5649 /// Upgrade all tools.
5650 #[arg(long, conflicts_with("name"))]
5651 pub all: bool,
5652
5653 /// Upgrade a tool, and specify it to use the given Python interpreter to build its environment.
5654 /// Use with `--all` to apply to all tools.
5655 ///
5656 /// See `uv help python` for details on Python discovery and supported request formats.
5657 #[arg(
5658 long,
5659 short,
5660 env = EnvVars::UV_PYTHON,
5661 verbatim_doc_comment,
5662 help_heading = "Python options",
5663 value_parser = parse_maybe_string,
5664 value_hint = ValueHint::Other,
5665 )]
5666 pub python: Option<Maybe<String>>,
5667
5668 /// The platform for which requirements should be installed.
5669 ///
5670 /// Represented as a "target triple", a string that describes the target platform in terms of
5671 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5672 /// `aarch64-apple-darwin`.
5673 ///
5674 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5675 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5676 ///
5677 /// When targeting iOS, the default minimum version is `13.0`. Use
5678 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5679 ///
5680 /// When targeting Android, the default minimum Android API level is `24`. Use
5681 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5682 ///
5683 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5684 /// platform; as a result, the installed distributions may not be compatible with the _current_
5685 /// platform. Conversely, any distributions that are built from source may be incompatible with
5686 /// the _target_ platform, as they will be built for the _current_ platform. The
5687 /// `--python-platform` option is intended for advanced use cases.
5688 #[arg(long)]
5689 pub python_platform: Option<TargetTriple>,
5690
5691 // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`, and
5692 // `--upgrade-package` options hidden, and the `--no-upgrade` option removed.
5693 /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
5694 /// `--refresh`.
5695 #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")]
5696 pub upgrade: bool,
5697
5698 /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
5699 /// file. Implies `--refresh-package`.
5700 #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")]
5701 pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
5702
5703 #[command(flatten)]
5704 pub index_args: IndexArgs,
5705
5706 /// Reinstall all packages, regardless of whether they're already installed. Implies
5707 /// `--refresh`.
5708 #[arg(
5709 long,
5710 alias = "force-reinstall",
5711 overrides_with("no_reinstall"),
5712 help_heading = "Installer options"
5713 )]
5714 pub reinstall: bool,
5715
5716 #[arg(
5717 long,
5718 overrides_with("reinstall"),
5719 hide = true,
5720 help_heading = "Installer options"
5721 )]
5722 pub no_reinstall: bool,
5723
5724 /// Reinstall a specific package, regardless of whether it's already installed. Implies
5725 /// `--refresh-package`.
5726 #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
5727 pub reinstall_package: Vec<PackageName>,
5728
5729 /// The strategy to use when resolving against multiple index URLs.
5730 ///
5731 /// By default, uv will stop at the first index on which a given package is available, and limit
5732 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
5733 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
5734 /// to an alternate index.
5735 #[arg(
5736 long,
5737 value_enum,
5738 env = EnvVars::UV_INDEX_STRATEGY,
5739 help_heading = "Index options"
5740 )]
5741 pub index_strategy: Option<IndexStrategy>,
5742
5743 /// Attempt to use `keyring` for authentication for index URLs.
5744 ///
5745 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
5746 /// the `keyring` CLI to handle authentication.
5747 ///
5748 /// Defaults to `disabled`.
5749 #[arg(
5750 long,
5751 value_enum,
5752 env = EnvVars::UV_KEYRING_PROVIDER,
5753 help_heading = "Index options"
5754 )]
5755 pub keyring_provider: Option<KeyringProviderType>,
5756
5757 /// The strategy to use when selecting between the different compatible versions for a given
5758 /// package requirement.
5759 ///
5760 /// By default, uv will use the latest compatible version of each package (`highest`).
5761 #[arg(
5762 long,
5763 value_enum,
5764 env = EnvVars::UV_RESOLUTION,
5765 help_heading = "Resolver options"
5766 )]
5767 pub resolution: Option<ResolutionMode>,
5768
5769 /// The strategy to use when considering pre-release versions.
5770 ///
5771 /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
5772 /// with first-party requirements that contain an explicit pre-release marker in the declared
5773 /// specifiers (`if-necessary-or-explicit`).
5774 #[arg(
5775 long,
5776 value_enum,
5777 env = EnvVars::UV_PRERELEASE,
5778 help_heading = "Resolver options"
5779 )]
5780 pub prerelease: Option<PrereleaseMode>,
5781
5782 #[arg(long, hide = true)]
5783 pub pre: bool,
5784
5785 /// The strategy to use when selecting multiple versions of a given package across Python
5786 /// versions and platforms.
5787 ///
5788 /// By default, uv will optimize for selecting the latest version of each package for each
5789 /// supported Python version (`requires-python`), while minimizing the number of selected
5790 /// versions across platforms.
5791 ///
5792 /// Under `fewest`, uv will minimize the number of selected versions for each package,
5793 /// preferring older versions that are compatible with a wider range of supported Python
5794 /// versions or platforms.
5795 #[arg(
5796 long,
5797 value_enum,
5798 env = EnvVars::UV_FORK_STRATEGY,
5799 help_heading = "Resolver options"
5800 )]
5801 pub fork_strategy: Option<ForkStrategy>,
5802
5803 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
5804 #[arg(
5805 long,
5806 short = 'C',
5807 alias = "config-settings",
5808 help_heading = "Build options"
5809 )]
5810 pub config_setting: Option<Vec<ConfigSettingEntry>>,
5811
5812 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
5813 #[arg(
5814 long,
5815 alias = "config-settings-package",
5816 help_heading = "Build options"
5817 )]
5818 pub config_setting_package: Option<Vec<ConfigSettingPackageEntry>>,
5819
5820 /// Disable isolation when building source distributions.
5821 ///
5822 /// Assumes that build dependencies specified by PEP 518 are already installed.
5823 #[arg(
5824 long,
5825 overrides_with("build_isolation"),
5826 help_heading = "Build options",
5827 env = EnvVars::UV_NO_BUILD_ISOLATION,
5828 value_parser = clap::builder::BoolishValueParser::new(),
5829 )]
5830 pub no_build_isolation: bool,
5831
5832 /// Disable isolation when building source distributions for a specific package.
5833 ///
5834 /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
5835 #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
5836 pub no_build_isolation_package: Vec<PackageName>,
5837
5838 #[arg(
5839 long,
5840 overrides_with("no_build_isolation"),
5841 hide = true,
5842 help_heading = "Build options"
5843 )]
5844 pub build_isolation: bool,
5845
5846 /// Limit candidate packages to those that were uploaded prior to the given date.
5847 ///
5848 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
5849 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
5850 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
5851 /// `P7D`, `P30D`).
5852 ///
5853 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
5854 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
5855 /// Calendar units such as months and years are not allowed.
5856 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
5857 pub exclude_newer: Option<ExcludeNewerValue>,
5858
5859 /// Limit candidate packages for specific packages to those that were uploaded prior to the
5860 /// given date.
5861 ///
5862 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
5863 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
5864 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
5865 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
5866 /// `P30D`).
5867 ///
5868 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
5869 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
5870 /// Calendar units such as months and years are not allowed.
5871 ///
5872 /// Can be provided multiple times for different packages.
5873 #[arg(long, help_heading = "Resolver options")]
5874 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
5875
5876 /// The method to use when installing packages from the global cache.
5877 ///
5878 /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
5879 /// Windows.
5880 ///
5881 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
5882 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
5883 /// will break all installed packages by way of removing the underlying source files. Use
5884 /// symlinks with caution.
5885 #[arg(
5886 long,
5887 value_enum,
5888 env = EnvVars::UV_LINK_MODE,
5889 help_heading = "Installer options"
5890 )]
5891 pub link_mode: Option<uv_install_wheel::LinkMode>,
5892
5893 /// Compile Python files to bytecode after installation.
5894 ///
5895 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
5896 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
5897 /// in which start time is critical, such as CLI applications and Docker containers, this option
5898 /// can be enabled to trade longer installation times for faster start times.
5899 ///
5900 /// When enabled, uv will process the entire site-packages directory (including packages that
5901 /// are not being modified by the current operation) for consistency. Like pip, it will also
5902 /// ignore errors.
5903 #[arg(
5904 long,
5905 alias = "compile",
5906 overrides_with("no_compile_bytecode"),
5907 help_heading = "Installer options",
5908 env = EnvVars::UV_COMPILE_BYTECODE,
5909 value_parser = clap::builder::BoolishValueParser::new(),
5910 )]
5911 pub compile_bytecode: bool,
5912
5913 #[arg(
5914 long,
5915 alias = "no-compile",
5916 overrides_with("compile_bytecode"),
5917 hide = true,
5918 help_heading = "Installer options"
5919 )]
5920 pub no_compile_bytecode: bool,
5921
5922 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
5923 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
5924 /// URL, or local path sources.
5925 #[arg(
5926 long,
5927 env = EnvVars::UV_NO_SOURCES,
5928 value_parser = clap::builder::BoolishValueParser::new(),
5929 help_heading = "Resolver options",
5930 )]
5931 pub no_sources: bool,
5932
5933 #[command(flatten)]
5934 pub build: BuildOptionsArgs,
5935}
5936
5937#[derive(Args)]
5938pub struct PythonNamespace {
5939 #[command(subcommand)]
5940 pub command: PythonCommand,
5941}
5942
5943#[derive(Subcommand)]
5944pub enum PythonCommand {
5945 /// List the available Python installations.
5946 ///
5947 /// By default, installed Python versions and the downloads for latest available patch version
5948 /// of each supported Python major version are shown.
5949 ///
5950 /// Use `--managed-python` to view only managed Python versions.
5951 ///
5952 /// Use `--no-managed-python` to omit managed Python versions.
5953 ///
5954 /// Use `--all-versions` to view all available patch versions.
5955 ///
5956 /// Use `--only-installed` to omit available downloads.
5957 #[command(alias = "ls")]
5958 List(PythonListArgs),
5959
5960 /// Download and install Python versions.
5961 ///
5962 /// Supports CPython and PyPy. CPython distributions are downloaded from the Astral
5963 /// `python-build-standalone` project. PyPy distributions are downloaded from `python.org`. The
5964 /// available Python versions are bundled with each uv release. To install new Python versions,
5965 /// you may need upgrade uv.
5966 ///
5967 /// Python versions are installed into the uv Python directory, which can be retrieved with `uv
5968 /// python dir`.
5969 ///
5970 /// By default, Python executables are added to a directory on the path with a minor version
5971 /// suffix, e.g., `python3.13`. To install `python3` and `python`, use the `--default` flag. Use
5972 /// `uv python dir --bin` to see the target directory.
5973 ///
5974 /// Multiple Python versions may be requested.
5975 ///
5976 /// See `uv help python` to view supported request formats.
5977 Install(PythonInstallArgs),
5978
5979 /// Upgrade installed Python versions.
5980 ///
5981 /// Upgrades versions to the latest supported patch release. Requires the `python-upgrade`
5982 /// preview feature.
5983 ///
5984 /// A target Python minor version to upgrade may be provided, e.g., `3.13`. Multiple versions
5985 /// may be provided to perform more than one upgrade.
5986 ///
5987 /// If no target version is provided, then uv will upgrade all managed CPython versions.
5988 ///
5989 /// During an upgrade, uv will not uninstall outdated patch versions.
5990 ///
5991 /// When an upgrade is performed, virtual environments created by uv will automatically
5992 /// use the new version. However, if the virtual environment was created before the
5993 /// upgrade functionality was added, it will continue to use the old Python version; to enable
5994 /// upgrades, the environment must be recreated.
5995 ///
5996 /// Upgrades are not yet supported for alternative implementations, like PyPy.
5997 Upgrade(PythonUpgradeArgs),
5998
5999 /// Search for a Python installation.
6000 ///
6001 /// Displays the path to the Python executable.
6002 ///
6003 /// See `uv help python` to view supported request formats and details on discovery behavior.
6004 Find(PythonFindArgs),
6005
6006 /// Pin to a specific Python version.
6007 ///
6008 /// Writes the pinned Python version to a `.python-version` file, which is used by other uv
6009 /// commands to determine the required Python version.
6010 ///
6011 /// If no version is provided, uv will look for an existing `.python-version` file and display
6012 /// the currently pinned version. If no `.python-version` file is found, uv will exit with an
6013 /// error.
6014 ///
6015 /// See `uv help python` to view supported request formats.
6016 Pin(PythonPinArgs),
6017
6018 /// Show the uv Python installation directory.
6019 ///
6020 /// By default, Python installations are stored in the uv data directory at
6021 /// `$XDG_DATA_HOME/uv/python` or `$HOME/.local/share/uv/python` on Unix and
6022 /// `%APPDATA%\uv\data\python` on Windows.
6023 ///
6024 /// The Python installation directory may be overridden with `$UV_PYTHON_INSTALL_DIR`.
6025 ///
6026 /// To view the directory where uv installs Python executables instead, use the `--bin` flag.
6027 /// The Python executable directory may be overridden with `$UV_PYTHON_BIN_DIR`. Note that
6028 /// Python executables are only installed when preview mode is enabled.
6029 Dir(PythonDirArgs),
6030
6031 /// Uninstall Python versions.
6032 Uninstall(PythonUninstallArgs),
6033
6034 /// Ensure that the Python executable directory is on the `PATH`.
6035 ///
6036 /// If the Python executable directory is not present on the `PATH`, uv will attempt to add it to
6037 /// the relevant shell configuration files.
6038 ///
6039 /// If the shell configuration files already include a blurb to add the executable directory to
6040 /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
6041 ///
6042 /// The Python executable directory is determined according to the XDG standard and can be
6043 /// retrieved with `uv python dir --bin`.
6044 #[command(alias = "ensurepath")]
6045 UpdateShell,
6046}
6047
6048#[derive(Args)]
6049pub struct PythonListArgs {
6050 /// A Python request to filter by.
6051 ///
6052 /// See `uv help python` to view supported request formats.
6053 pub request: Option<String>,
6054
6055 /// List all Python versions, including old patch versions.
6056 ///
6057 /// By default, only the latest patch version is shown for each minor version.
6058 #[arg(long)]
6059 pub all_versions: bool,
6060
6061 /// List Python downloads for all platforms.
6062 ///
6063 /// By default, only downloads for the current platform are shown.
6064 #[arg(long)]
6065 pub all_platforms: bool,
6066
6067 /// List Python downloads for all architectures.
6068 ///
6069 /// By default, only downloads for the current architecture are shown.
6070 #[arg(long, alias = "all_architectures")]
6071 pub all_arches: bool,
6072
6073 /// Only show installed Python versions.
6074 ///
6075 /// By default, installed distributions and available downloads for the current platform are shown.
6076 #[arg(long, conflicts_with("only_downloads"))]
6077 pub only_installed: bool,
6078
6079 /// Only show available Python downloads.
6080 ///
6081 /// By default, installed distributions and available downloads for the current platform are shown.
6082 #[arg(long, conflicts_with("only_installed"))]
6083 pub only_downloads: bool,
6084
6085 /// Show the URLs of available Python downloads.
6086 ///
6087 /// By default, these display as `<download available>`.
6088 #[arg(long)]
6089 pub show_urls: bool,
6090
6091 /// Select the output format.
6092 #[arg(long, value_enum, default_value_t = PythonListFormat::default())]
6093 pub output_format: PythonListFormat,
6094
6095 /// URL pointing to JSON of custom Python installations.
6096 #[arg(long, value_hint = ValueHint::Other)]
6097 pub python_downloads_json_url: Option<String>,
6098}
6099
6100#[derive(Args)]
6101pub struct PythonDirArgs {
6102 /// Show the directory into which `uv python` will install Python executables.
6103 ///
6104 /// Note that this directory is only used when installing Python with preview mode enabled.
6105 ///
6106 /// The Python executable directory is determined according to the XDG standard and is derived
6107 /// from the following environment variables, in order of preference:
6108 ///
6109 /// - `$UV_PYTHON_BIN_DIR`
6110 /// - `$XDG_BIN_HOME`
6111 /// - `$XDG_DATA_HOME/../bin`
6112 /// - `$HOME/.local/bin`
6113 #[arg(long, verbatim_doc_comment)]
6114 pub bin: bool,
6115}
6116
6117#[derive(Args)]
6118pub struct PythonInstallArgs {
6119 /// The directory to store the Python installation in.
6120 ///
6121 /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6122 /// discover the Python installation.
6123 ///
6124 /// See `uv python dir` to view the current Python installation directory. Defaults to
6125 /// `~/.local/share/uv/python`.
6126 #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6127 pub install_dir: Option<PathBuf>,
6128
6129 /// Install a Python executable into the `bin` directory.
6130 ///
6131 /// This is the default behavior. If this flag is provided explicitly, uv will error if the
6132 /// executable cannot be installed.
6133 ///
6134 /// This can also be set with `UV_PYTHON_INSTALL_BIN=1`.
6135 ///
6136 /// See `UV_PYTHON_BIN_DIR` to customize the target directory.
6137 #[arg(long, overrides_with("no_bin"), hide = true)]
6138 pub bin: bool,
6139
6140 /// Do not install a Python executable into the `bin` directory.
6141 ///
6142 /// This can also be set with `UV_PYTHON_INSTALL_BIN=0`.
6143 #[arg(long, overrides_with("bin"), conflicts_with("default"))]
6144 pub no_bin: bool,
6145
6146 /// Register the Python installation in the Windows registry.
6147 ///
6148 /// This is the default behavior on Windows. If this flag is provided explicitly, uv will error if the
6149 /// registry entry cannot be created.
6150 ///
6151 /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=1`.
6152 #[arg(long, overrides_with("no_registry"), hide = true)]
6153 pub registry: bool,
6154
6155 /// Do not register the Python installation in the Windows registry.
6156 ///
6157 /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=0`.
6158 #[arg(long, overrides_with("registry"))]
6159 pub no_registry: bool,
6160
6161 /// The Python version(s) to install.
6162 ///
6163 /// If not provided, the requested Python version(s) will be read from the `UV_PYTHON`
6164 /// environment variable then `.python-versions` or `.python-version` files. If none of the
6165 /// above are present, uv will check if it has installed any Python versions. If not, it will
6166 /// install the latest stable version of Python.
6167 ///
6168 /// See `uv help python` to view supported request formats.
6169 #[arg(env = EnvVars::UV_PYTHON)]
6170 pub targets: Vec<String>,
6171
6172 /// Set the URL to use as the source for downloading Python installations.
6173 ///
6174 /// The provided URL will replace
6175 /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6176 /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6177 ///
6178 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6179 #[arg(long, value_hint = ValueHint::Url)]
6180 pub mirror: Option<String>,
6181
6182 /// Set the URL to use as the source for downloading PyPy installations.
6183 ///
6184 /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6185 /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6186 ///
6187 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6188 #[arg(long, value_hint = ValueHint::Url)]
6189 pub pypy_mirror: Option<String>,
6190
6191 /// URL pointing to JSON of custom Python installations.
6192 #[arg(long, value_hint = ValueHint::Other)]
6193 pub python_downloads_json_url: Option<String>,
6194
6195 /// Reinstall the requested Python version, if it's already installed.
6196 ///
6197 /// By default, uv will exit successfully if the version is already
6198 /// installed.
6199 #[arg(long, short)]
6200 pub reinstall: bool,
6201
6202 /// Replace existing Python executables during installation.
6203 ///
6204 /// By default, uv will refuse to replace executables that it does not manage.
6205 ///
6206 /// Implies `--reinstall`.
6207 #[arg(long, short)]
6208 pub force: bool,
6209
6210 /// Upgrade existing Python installations to the latest patch version.
6211 ///
6212 /// By default, uv will not upgrade already-installed Python versions to newer patch releases.
6213 /// With `--upgrade`, uv will upgrade to the latest available patch version for the specified
6214 /// minor version(s).
6215 ///
6216 /// If the requested versions are not yet installed, uv will install them.
6217 ///
6218 /// This option is only supported for minor version requests, e.g., `3.12`; uv will exit with an
6219 /// error if a patch version, e.g., `3.12.2`, is requested.
6220 #[arg(long, short = 'U')]
6221 pub upgrade: bool,
6222
6223 /// Use as the default Python version.
6224 ///
6225 /// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
6226 /// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
6227 /// also installed.
6228 ///
6229 /// Alternative Python variants will still include their tag. For example, installing
6230 /// 3.13+freethreaded with `--default` will include in `python3t` and `pythont`, not `python3`
6231 /// and `python`.
6232 ///
6233 /// If multiple Python versions are requested, uv will exit with an error.
6234 #[arg(long, conflicts_with("no_bin"))]
6235 pub default: bool,
6236}
6237
6238impl PythonInstallArgs {
6239 #[must_use]
6240 pub fn install_mirrors(&self) -> PythonInstallMirrors {
6241 PythonInstallMirrors {
6242 python_install_mirror: self.mirror.clone(),
6243 pypy_install_mirror: self.pypy_mirror.clone(),
6244 python_downloads_json_url: self.python_downloads_json_url.clone(),
6245 }
6246 }
6247}
6248
6249#[derive(Args)]
6250pub struct PythonUpgradeArgs {
6251 /// The directory Python installations are stored in.
6252 ///
6253 /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6254 /// discover the Python installation.
6255 ///
6256 /// See `uv python dir` to view the current Python installation directory. Defaults to
6257 /// `~/.local/share/uv/python`.
6258 #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6259 pub install_dir: Option<PathBuf>,
6260
6261 /// The Python minor version(s) to upgrade.
6262 ///
6263 /// If no target version is provided, then uv will upgrade all managed CPython versions.
6264 #[arg(env = EnvVars::UV_PYTHON)]
6265 pub targets: Vec<String>,
6266
6267 /// Set the URL to use as the source for downloading Python installations.
6268 ///
6269 /// The provided URL will replace
6270 /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6271 /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6272 ///
6273 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6274 #[arg(long, value_hint = ValueHint::Url)]
6275 pub mirror: Option<String>,
6276
6277 /// Set the URL to use as the source for downloading PyPy installations.
6278 ///
6279 /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6280 /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6281 ///
6282 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6283 #[arg(long, value_hint = ValueHint::Url)]
6284 pub pypy_mirror: Option<String>,
6285
6286 /// Reinstall the latest Python patch, if it's already installed.
6287 ///
6288 /// By default, uv will exit successfully if the latest patch is already
6289 /// installed.
6290 #[arg(long, short)]
6291 pub reinstall: bool,
6292
6293 /// URL pointing to JSON of custom Python installations.
6294 #[arg(long, value_hint = ValueHint::Other)]
6295 pub python_downloads_json_url: Option<String>,
6296}
6297
6298impl PythonUpgradeArgs {
6299 #[must_use]
6300 pub fn install_mirrors(&self) -> PythonInstallMirrors {
6301 PythonInstallMirrors {
6302 python_install_mirror: self.mirror.clone(),
6303 pypy_install_mirror: self.pypy_mirror.clone(),
6304 python_downloads_json_url: self.python_downloads_json_url.clone(),
6305 }
6306 }
6307}
6308
6309#[derive(Args)]
6310pub struct PythonUninstallArgs {
6311 /// The directory where the Python was installed.
6312 #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6313 pub install_dir: Option<PathBuf>,
6314
6315 /// The Python version(s) to uninstall.
6316 ///
6317 /// See `uv help python` to view supported request formats.
6318 #[arg(required = true)]
6319 pub targets: Vec<String>,
6320
6321 /// Uninstall all managed Python versions.
6322 #[arg(long, conflicts_with("targets"))]
6323 pub all: bool,
6324}
6325
6326#[derive(Args)]
6327pub struct PythonFindArgs {
6328 /// The Python request.
6329 ///
6330 /// See `uv help python` to view supported request formats.
6331 pub request: Option<String>,
6332
6333 /// Avoid discovering a project or workspace.
6334 ///
6335 /// Otherwise, when no request is provided, the Python requirement of a project in the current
6336 /// directory or parent directories will be used.
6337 #[arg(long, alias = "no_workspace")]
6338 pub no_project: bool,
6339
6340 /// Only find system Python interpreters.
6341 ///
6342 /// By default, uv will report the first Python interpreter it would use, including those in an
6343 /// active virtual environment or a virtual environment in the current working directory or any
6344 /// parent directory.
6345 ///
6346 /// The `--system` option instructs uv to skip virtual environment Python interpreters and
6347 /// restrict its search to the system path.
6348 #[arg(
6349 long,
6350 env = EnvVars::UV_SYSTEM_PYTHON,
6351 value_parser = clap::builder::BoolishValueParser::new(),
6352 overrides_with("no_system")
6353 )]
6354 pub system: bool,
6355
6356 #[arg(long, overrides_with("system"), hide = true)]
6357 pub no_system: bool,
6358
6359 /// Find the environment for a Python script, rather than the current project.
6360 #[arg(
6361 long,
6362 conflicts_with = "request",
6363 conflicts_with = "no_project",
6364 conflicts_with = "system",
6365 conflicts_with = "no_system",
6366 value_hint = ValueHint::FilePath,
6367 )]
6368 pub script: Option<PathBuf>,
6369
6370 /// Show the Python version that would be used instead of the path to the interpreter.
6371 #[arg(long)]
6372 pub show_version: bool,
6373
6374 /// URL pointing to JSON of custom Python installations.
6375 #[arg(long, value_hint = ValueHint::Other)]
6376 pub python_downloads_json_url: Option<String>,
6377}
6378
6379#[derive(Args)]
6380pub struct PythonPinArgs {
6381 /// The Python version request.
6382 ///
6383 /// uv supports more formats than other tools that read `.python-version` files, i.e., `pyenv`.
6384 /// If compatibility with those tools is needed, only use version numbers instead of complex
6385 /// requests such as `cpython@3.10`.
6386 ///
6387 /// If no request is provided, the currently pinned version will be shown.
6388 ///
6389 /// See `uv help python` to view supported request formats.
6390 pub request: Option<String>,
6391
6392 /// Write the resolved Python interpreter path instead of the request.
6393 ///
6394 /// Ensures that the exact same interpreter is used.
6395 ///
6396 /// This option is usually not safe to use when committing the `.python-version` file to version
6397 /// control.
6398 #[arg(long, overrides_with("resolved"))]
6399 pub resolved: bool,
6400
6401 #[arg(long, overrides_with("no_resolved"), hide = true)]
6402 pub no_resolved: bool,
6403
6404 /// Avoid validating the Python pin is compatible with the project or workspace.
6405 ///
6406 /// By default, a project or workspace is discovered in the current directory or any parent
6407 /// directory. If a workspace is found, the Python pin is validated against the workspace's
6408 /// `requires-python` constraint.
6409 #[arg(long, alias = "no-workspace")]
6410 pub no_project: bool,
6411
6412 /// Update the global Python version pin.
6413 ///
6414 /// Writes the pinned Python version to a `.python-version` file in the uv user configuration
6415 /// directory: `XDG_CONFIG_HOME/uv` on Linux/macOS and `%APPDATA%/uv` on Windows.
6416 ///
6417 /// When a local Python version pin is not found in the working directory or an ancestor
6418 /// directory, this version will be used instead.
6419 #[arg(long)]
6420 pub global: bool,
6421
6422 /// Remove the Python version pin.
6423 #[arg(long, conflicts_with = "request", conflicts_with = "resolved")]
6424 pub rm: bool,
6425}
6426
6427#[derive(Args)]
6428pub struct AuthLogoutArgs {
6429 /// The domain or URL of the service to logout from.
6430 pub service: Service,
6431
6432 /// The username to logout.
6433 #[arg(long, short, value_hint = ValueHint::Other)]
6434 pub username: Option<String>,
6435
6436 /// The keyring provider to use for storage of credentials.
6437 ///
6438 /// Only `--keyring-provider native` is supported for `logout`, which uses the system keyring
6439 /// via an integration built into uv.
6440 #[arg(
6441 long,
6442 value_enum,
6443 env = EnvVars::UV_KEYRING_PROVIDER,
6444 )]
6445 pub keyring_provider: Option<KeyringProviderType>,
6446}
6447
6448#[derive(Args)]
6449pub struct AuthLoginArgs {
6450 /// The domain or URL of the service to log into.
6451 #[arg(value_hint = ValueHint::Url)]
6452 pub service: Service,
6453
6454 /// The username to use for the service.
6455 #[arg(long, short, conflicts_with = "token", value_hint = ValueHint::Other)]
6456 pub username: Option<String>,
6457
6458 /// The password to use for the service.
6459 ///
6460 /// Use `-` to read the password from stdin.
6461 #[arg(long, conflicts_with = "token", value_hint = ValueHint::Other)]
6462 pub password: Option<String>,
6463
6464 /// The token to use for the service.
6465 ///
6466 /// The username will be set to `__token__`.
6467 ///
6468 /// Use `-` to read the token from stdin.
6469 #[arg(long, short, conflicts_with = "username", conflicts_with = "password", value_hint = ValueHint::Other)]
6470 pub token: Option<String>,
6471
6472 /// The keyring provider to use for storage of credentials.
6473 ///
6474 /// Only `--keyring-provider native` is supported for `login`, which uses the system keyring via
6475 /// an integration built into uv.
6476 #[arg(
6477 long,
6478 value_enum,
6479 env = EnvVars::UV_KEYRING_PROVIDER,
6480 )]
6481 pub keyring_provider: Option<KeyringProviderType>,
6482}
6483
6484#[derive(Args)]
6485pub struct AuthTokenArgs {
6486 /// The domain or URL of the service to lookup.
6487 #[arg(value_hint = ValueHint::Url)]
6488 pub service: Service,
6489
6490 /// The username to lookup.
6491 #[arg(long, short, value_hint = ValueHint::Other)]
6492 pub username: Option<String>,
6493
6494 /// The keyring provider to use for reading credentials.
6495 #[arg(
6496 long,
6497 value_enum,
6498 env = EnvVars::UV_KEYRING_PROVIDER,
6499 )]
6500 pub keyring_provider: Option<KeyringProviderType>,
6501}
6502
6503#[derive(Args)]
6504pub struct AuthDirArgs {
6505 /// The domain or URL of the service to lookup.
6506 #[arg(value_hint = ValueHint::Url)]
6507 pub service: Option<Service>,
6508}
6509
6510#[derive(Args)]
6511pub struct AuthHelperArgs {
6512 #[command(subcommand)]
6513 pub command: AuthHelperCommand,
6514
6515 /// The credential helper protocol to use
6516 #[arg(long, value_enum, required = true)]
6517 pub protocol: AuthHelperProtocol,
6518}
6519
6520/// Credential helper protocols supported by uv
6521#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
6522pub enum AuthHelperProtocol {
6523 /// Bazel credential helper protocol as described in [the
6524 /// spec](https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md)
6525 Bazel,
6526}
6527
6528#[derive(Subcommand)]
6529pub enum AuthHelperCommand {
6530 /// Retrieve credentials for a URI
6531 Get,
6532}
6533
6534#[derive(Args)]
6535pub struct GenerateShellCompletionArgs {
6536 /// The shell to generate the completion script for
6537 pub shell: clap_complete_command::Shell,
6538
6539 // Hide unused global options.
6540 #[arg(long, short, hide = true)]
6541 pub no_cache: bool,
6542 #[arg(long, hide = true)]
6543 pub cache_dir: Option<PathBuf>,
6544
6545 #[arg(long, hide = true)]
6546 pub python_preference: Option<PythonPreference>,
6547 #[arg(long, hide = true)]
6548 pub no_python_downloads: bool,
6549
6550 #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
6551 pub quiet: u8,
6552 #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
6553 pub verbose: u8,
6554 #[arg(long, conflicts_with = "no_color", hide = true)]
6555 pub color: Option<ColorChoice>,
6556 #[arg(long, hide = true)]
6557 pub native_tls: bool,
6558 #[arg(long, hide = true)]
6559 pub offline: bool,
6560 #[arg(long, hide = true)]
6561 pub no_progress: bool,
6562 #[arg(long, hide = true)]
6563 pub config_file: Option<PathBuf>,
6564 #[arg(long, hide = true)]
6565 pub no_config: bool,
6566 #[arg(long, short, action = clap::ArgAction::HelpShort, hide = true)]
6567 pub help: Option<bool>,
6568 #[arg(short = 'V', long, hide = true)]
6569 pub version: bool,
6570}
6571
6572#[derive(Args)]
6573pub struct IndexArgs {
6574 /// The URLs to use when resolving dependencies, in addition to the default index.
6575 ///
6576 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6577 /// directory laid out in the same format.
6578 ///
6579 /// All indexes provided via this flag take priority over the index specified by
6580 /// `--default-index` (which defaults to PyPI). When multiple `--index` flags are provided,
6581 /// earlier values take priority.
6582 ///
6583 /// Index names are not supported as values. Relative paths must be disambiguated from index
6584 /// names with `./` or `../` on Unix or `.\\`, `..\\`, `./` or `../` on Windows.
6585 //
6586 // The nested Vec structure (`Vec<Vec<Maybe<Index>>>`) is required for clap's
6587 // value parsing mechanism, which processes one value at a time, in order to handle
6588 // `UV_INDEX` the same way pip handles `PIP_EXTRA_INDEX_URL`.
6589 #[arg(long, env = EnvVars::UV_INDEX, value_parser = parse_indices, help_heading = "Index options")]
6590 pub index: Option<Vec<Vec<Maybe<Index>>>>,
6591
6592 /// The URL of the default package index (by default: <https://pypi.org/simple>).
6593 ///
6594 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6595 /// directory laid out in the same format.
6596 ///
6597 /// The index given by this flag is given lower priority than all other indexes specified via
6598 /// the `--index` flag.
6599 #[arg(long, env = EnvVars::UV_DEFAULT_INDEX, value_parser = parse_default_index, help_heading = "Index options")]
6600 pub default_index: Option<Maybe<Index>>,
6601
6602 /// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default:
6603 /// <https://pypi.org/simple>).
6604 ///
6605 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6606 /// directory laid out in the same format.
6607 ///
6608 /// The index given by this flag is given lower priority than all other indexes specified via
6609 /// the `--extra-index-url` flag.
6610 #[arg(long, short, env = EnvVars::UV_INDEX_URL, value_parser = parse_index_url, help_heading = "Index options")]
6611 pub index_url: Option<Maybe<PipIndex>>,
6612
6613 /// (Deprecated: use `--index` instead) Extra URLs of package indexes to use, in addition to
6614 /// `--index-url`.
6615 ///
6616 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6617 /// directory laid out in the same format.
6618 ///
6619 /// All indexes provided via this flag take priority over the index specified by `--index-url`
6620 /// (which defaults to PyPI). When multiple `--extra-index-url` flags are provided, earlier
6621 /// values take priority.
6622 #[arg(long, env = EnvVars::UV_EXTRA_INDEX_URL, value_delimiter = ' ', value_parser = parse_extra_index_url, help_heading = "Index options")]
6623 pub extra_index_url: Option<Vec<Maybe<PipExtraIndex>>>,
6624
6625 /// Locations to search for candidate distributions, in addition to those found in the registry
6626 /// indexes.
6627 ///
6628 /// If a path, the target must be a directory that contains packages as wheel files (`.whl`) or
6629 /// source distributions (e.g., `.tar.gz` or `.zip`) at the top level.
6630 ///
6631 /// If a URL, the page must contain a flat list of links to package files adhering to the
6632 /// formats described above.
6633 #[arg(
6634 long,
6635 short,
6636 env = EnvVars::UV_FIND_LINKS,
6637 value_delimiter = ',',
6638 value_parser = parse_find_links,
6639 help_heading = "Index options"
6640 )]
6641 pub find_links: Option<Vec<Maybe<PipFindLinks>>>,
6642
6643 /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
6644 /// provided via `--find-links`.
6645 #[arg(long, help_heading = "Index options")]
6646 pub no_index: bool,
6647}
6648
6649#[derive(Args)]
6650pub struct RefreshArgs {
6651 /// Refresh all cached data.
6652 #[arg(
6653 long,
6654 conflicts_with("offline"),
6655 overrides_with("no_refresh"),
6656 help_heading = "Cache options"
6657 )]
6658 pub refresh: bool,
6659
6660 #[arg(
6661 long,
6662 conflicts_with("offline"),
6663 overrides_with("refresh"),
6664 hide = true,
6665 help_heading = "Cache options"
6666 )]
6667 pub no_refresh: bool,
6668
6669 /// Refresh cached data for a specific package.
6670 #[arg(long, help_heading = "Cache options", value_hint = ValueHint::Other)]
6671 pub refresh_package: Vec<PackageName>,
6672}
6673
6674#[derive(Args)]
6675pub struct BuildOptionsArgs {
6676 /// Don't build source distributions.
6677 ///
6678 /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
6679 /// already-built source distributions will be reused, but operations that require building
6680 /// distributions will exit with an error.
6681 #[arg(
6682 long,
6683 env = EnvVars::UV_NO_BUILD,
6684 overrides_with("build"),
6685 value_parser = clap::builder::BoolishValueParser::new(),
6686 help_heading = "Build options",
6687 )]
6688 pub no_build: bool,
6689
6690 #[arg(
6691 long,
6692 overrides_with("no_build"),
6693 hide = true,
6694 help_heading = "Build options"
6695 )]
6696 pub build: bool,
6697
6698 /// Don't build source distributions for a specific package.
6699 #[arg(
6700 long,
6701 help_heading = "Build options",
6702 env = EnvVars::UV_NO_BUILD_PACKAGE,
6703 value_delimiter = ' ',
6704 value_hint = ValueHint::Other,
6705 )]
6706 pub no_build_package: Vec<PackageName>,
6707
6708 /// Don't install pre-built wheels.
6709 ///
6710 /// The given packages will be built and installed from source. The resolver will still use
6711 /// pre-built wheels to extract package metadata, if available.
6712 #[arg(
6713 long,
6714 env = EnvVars::UV_NO_BINARY,
6715 overrides_with("binary"),
6716 value_parser = clap::builder::BoolishValueParser::new(),
6717 help_heading = "Build options"
6718 )]
6719 pub no_binary: bool,
6720
6721 #[arg(
6722 long,
6723 overrides_with("no_binary"),
6724 hide = true,
6725 help_heading = "Build options"
6726 )]
6727 pub binary: bool,
6728
6729 /// Don't install pre-built wheels for a specific package.
6730 #[arg(
6731 long,
6732 help_heading = "Build options",
6733 env = EnvVars::UV_NO_BINARY_PACKAGE,
6734 value_delimiter = ' ',
6735 value_hint = ValueHint::Other,
6736 )]
6737 pub no_binary_package: Vec<PackageName>,
6738}
6739
6740/// Arguments that are used by commands that need to install (but not resolve) packages.
6741#[derive(Args)]
6742pub struct InstallerArgs {
6743 #[command(flatten)]
6744 pub index_args: IndexArgs,
6745
6746 /// Reinstall all packages, regardless of whether they're already installed. Implies
6747 /// `--refresh`.
6748 #[arg(
6749 long,
6750 alias = "force-reinstall",
6751 overrides_with("no_reinstall"),
6752 help_heading = "Installer options"
6753 )]
6754 pub reinstall: bool,
6755
6756 #[arg(
6757 long,
6758 overrides_with("reinstall"),
6759 hide = true,
6760 help_heading = "Installer options"
6761 )]
6762 pub no_reinstall: bool,
6763
6764 /// Reinstall a specific package, regardless of whether it's already installed. Implies
6765 /// `--refresh-package`.
6766 #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
6767 pub reinstall_package: Vec<PackageName>,
6768
6769 /// The strategy to use when resolving against multiple index URLs.
6770 ///
6771 /// By default, uv will stop at the first index on which a given package is available, and limit
6772 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6773 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6774 /// to an alternate index.
6775 #[arg(
6776 long,
6777 value_enum,
6778 env = EnvVars::UV_INDEX_STRATEGY,
6779 help_heading = "Index options"
6780 )]
6781 pub index_strategy: Option<IndexStrategy>,
6782
6783 /// Attempt to use `keyring` for authentication for index URLs.
6784 ///
6785 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6786 /// the `keyring` CLI to handle authentication.
6787 ///
6788 /// Defaults to `disabled`.
6789 #[arg(
6790 long,
6791 value_enum,
6792 env = EnvVars::UV_KEYRING_PROVIDER,
6793 help_heading = "Index options"
6794 )]
6795 pub keyring_provider: Option<KeyringProviderType>,
6796
6797 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
6798 #[arg(
6799 long,
6800 short = 'C',
6801 alias = "config-settings",
6802 help_heading = "Build options"
6803 )]
6804 pub config_setting: Option<Vec<ConfigSettingEntry>>,
6805
6806 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
6807 #[arg(
6808 long,
6809 alias = "config-settings-package",
6810 help_heading = "Build options"
6811 )]
6812 pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
6813
6814 /// Disable isolation when building source distributions.
6815 ///
6816 /// Assumes that build dependencies specified by PEP 518 are already installed.
6817 #[arg(
6818 long,
6819 overrides_with("build_isolation"),
6820 help_heading = "Build options",
6821 env = EnvVars::UV_NO_BUILD_ISOLATION,
6822 value_parser = clap::builder::BoolishValueParser::new(),
6823 )]
6824 pub no_build_isolation: bool,
6825
6826 #[arg(
6827 long,
6828 overrides_with("no_build_isolation"),
6829 hide = true,
6830 help_heading = "Build options"
6831 )]
6832 pub build_isolation: bool,
6833
6834 /// Limit candidate packages to those that were uploaded prior to the given date.
6835 ///
6836 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
6837 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
6838 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
6839 /// `P7D`, `P30D`).
6840 ///
6841 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6842 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6843 /// Calendar units such as months and years are not allowed.
6844 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6845 pub exclude_newer: Option<ExcludeNewerValue>,
6846
6847 /// Limit candidate packages for specific packages to those that were uploaded prior to the
6848 /// given date.
6849 ///
6850 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
6851 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
6852 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
6853 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
6854 /// `P30D`).
6855 ///
6856 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6857 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6858 /// Calendar units such as months and years are not allowed.
6859 ///
6860 /// Can be provided multiple times for different packages.
6861 #[arg(long, help_heading = "Resolver options")]
6862 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6863
6864 /// The method to use when installing packages from the global cache.
6865 ///
6866 /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
6867 /// Windows.
6868 ///
6869 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
6870 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
6871 /// will break all installed packages by way of removing the underlying source files. Use
6872 /// symlinks with caution.
6873 #[arg(
6874 long,
6875 value_enum,
6876 env = EnvVars::UV_LINK_MODE,
6877 help_heading = "Installer options"
6878 )]
6879 pub link_mode: Option<uv_install_wheel::LinkMode>,
6880
6881 /// Compile Python files to bytecode after installation.
6882 ///
6883 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6884 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6885 /// in which start time is critical, such as CLI applications and Docker containers, this option
6886 /// can be enabled to trade longer installation times for faster start times.
6887 ///
6888 /// When enabled, uv will process the entire site-packages directory (including packages that
6889 /// are not being modified by the current operation) for consistency. Like pip, it will also
6890 /// ignore errors.
6891 #[arg(
6892 long,
6893 alias = "compile",
6894 overrides_with("no_compile_bytecode"),
6895 help_heading = "Installer options",
6896 env = EnvVars::UV_COMPILE_BYTECODE,
6897 value_parser = clap::builder::BoolishValueParser::new(),
6898 )]
6899 pub compile_bytecode: bool,
6900
6901 #[arg(
6902 long,
6903 alias = "no-compile",
6904 overrides_with("compile_bytecode"),
6905 hide = true,
6906 help_heading = "Installer options"
6907 )]
6908 pub no_compile_bytecode: bool,
6909
6910 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6911 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6912 /// URL, or local path sources.
6913 #[arg(
6914 long,
6915 env = EnvVars::UV_NO_SOURCES,
6916 value_parser = clap::builder::BoolishValueParser::new(),
6917 help_heading = "Resolver options"
6918 )]
6919 pub no_sources: bool,
6920}
6921
6922/// Arguments that are used by commands that need to resolve (but not install) packages.
6923#[derive(Args)]
6924pub struct ResolverArgs {
6925 #[command(flatten)]
6926 pub index_args: IndexArgs,
6927
6928 /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
6929 /// `--refresh`.
6930 #[arg(
6931 long,
6932 short = 'U',
6933 overrides_with("no_upgrade"),
6934 help_heading = "Resolver options"
6935 )]
6936 pub upgrade: bool,
6937
6938 #[arg(
6939 long,
6940 overrides_with("upgrade"),
6941 hide = true,
6942 help_heading = "Resolver options"
6943 )]
6944 pub no_upgrade: bool,
6945
6946 /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
6947 /// file. Implies `--refresh-package`.
6948 #[arg(long, short = 'P', help_heading = "Resolver options")]
6949 pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
6950
6951 /// The strategy to use when resolving against multiple index URLs.
6952 ///
6953 /// By default, uv will stop at the first index on which a given package is available, and limit
6954 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6955 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6956 /// to an alternate index.
6957 #[arg(
6958 long,
6959 value_enum,
6960 env = EnvVars::UV_INDEX_STRATEGY,
6961 help_heading = "Index options"
6962 )]
6963 pub index_strategy: Option<IndexStrategy>,
6964
6965 /// Attempt to use `keyring` for authentication for index URLs.
6966 ///
6967 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6968 /// the `keyring` CLI to handle authentication.
6969 ///
6970 /// Defaults to `disabled`.
6971 #[arg(
6972 long,
6973 value_enum,
6974 env = EnvVars::UV_KEYRING_PROVIDER,
6975 help_heading = "Index options"
6976 )]
6977 pub keyring_provider: Option<KeyringProviderType>,
6978
6979 /// The strategy to use when selecting between the different compatible versions for a given
6980 /// package requirement.
6981 ///
6982 /// By default, uv will use the latest compatible version of each package (`highest`).
6983 #[arg(
6984 long,
6985 value_enum,
6986 env = EnvVars::UV_RESOLUTION,
6987 help_heading = "Resolver options"
6988 )]
6989 pub resolution: Option<ResolutionMode>,
6990
6991 /// The strategy to use when considering pre-release versions.
6992 ///
6993 /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
6994 /// with first-party requirements that contain an explicit pre-release marker in the declared
6995 /// specifiers (`if-necessary-or-explicit`).
6996 #[arg(
6997 long,
6998 value_enum,
6999 env = EnvVars::UV_PRERELEASE,
7000 help_heading = "Resolver options"
7001 )]
7002 pub prerelease: Option<PrereleaseMode>,
7003
7004 #[arg(long, hide = true, help_heading = "Resolver options")]
7005 pub pre: bool,
7006
7007 /// The strategy to use when selecting multiple versions of a given package across Python
7008 /// versions and platforms.
7009 ///
7010 /// By default, uv will optimize for selecting the latest version of each package for each
7011 /// supported Python version (`requires-python`), while minimizing the number of selected
7012 /// versions across platforms.
7013 ///
7014 /// Under `fewest`, uv will minimize the number of selected versions for each package,
7015 /// preferring older versions that are compatible with a wider range of supported Python
7016 /// versions or platforms.
7017 #[arg(
7018 long,
7019 value_enum,
7020 env = EnvVars::UV_FORK_STRATEGY,
7021 help_heading = "Resolver options"
7022 )]
7023 pub fork_strategy: Option<ForkStrategy>,
7024
7025 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7026 #[arg(
7027 long,
7028 short = 'C',
7029 alias = "config-settings",
7030 help_heading = "Build options"
7031 )]
7032 pub config_setting: Option<Vec<ConfigSettingEntry>>,
7033
7034 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7035 #[arg(
7036 long,
7037 alias = "config-settings-package",
7038 help_heading = "Build options"
7039 )]
7040 pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7041
7042 /// Disable isolation when building source distributions.
7043 ///
7044 /// Assumes that build dependencies specified by PEP 518 are already installed.
7045 #[arg(
7046 long,
7047 overrides_with("build_isolation"),
7048 help_heading = "Build options",
7049 env = EnvVars::UV_NO_BUILD_ISOLATION,
7050 value_parser = clap::builder::BoolishValueParser::new(),
7051 )]
7052 pub no_build_isolation: bool,
7053
7054 /// Disable isolation when building source distributions for a specific package.
7055 ///
7056 /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7057 #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7058 pub no_build_isolation_package: Vec<PackageName>,
7059
7060 #[arg(
7061 long,
7062 overrides_with("no_build_isolation"),
7063 hide = true,
7064 help_heading = "Build options"
7065 )]
7066 pub build_isolation: bool,
7067
7068 /// Limit candidate packages to those that were uploaded prior to the given date.
7069 ///
7070 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7071 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7072 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7073 /// `P7D`, `P30D`).
7074 ///
7075 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7076 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7077 /// Calendar units such as months and years are not allowed.
7078 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7079 pub exclude_newer: Option<ExcludeNewerValue>,
7080
7081 /// Limit candidate packages for specific packages to those that were uploaded prior to the
7082 /// given date.
7083 ///
7084 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7085 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7086 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7087 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7088 /// `P30D`).
7089 ///
7090 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7091 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7092 /// Calendar units such as months and years are not allowed.
7093 ///
7094 /// Can be provided multiple times for different packages.
7095 #[arg(long, help_heading = "Resolver options")]
7096 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7097
7098 /// The method to use when installing packages from the global cache.
7099 ///
7100 /// This option is only used when building source distributions.
7101 ///
7102 /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
7103 /// Windows.
7104 ///
7105 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7106 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7107 /// will break all installed packages by way of removing the underlying source files. Use
7108 /// symlinks with caution.
7109 #[arg(
7110 long,
7111 value_enum,
7112 env = EnvVars::UV_LINK_MODE,
7113 help_heading = "Installer options"
7114 )]
7115 pub link_mode: Option<uv_install_wheel::LinkMode>,
7116
7117 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7118 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7119 /// URL, or local path sources.
7120 #[arg(
7121 long,
7122 env = EnvVars::UV_NO_SOURCES,
7123 value_parser = clap::builder::BoolishValueParser::new(),
7124 help_heading = "Resolver options",
7125 )]
7126 pub no_sources: bool,
7127}
7128
7129/// Arguments that are used by commands that need to resolve and install packages.
7130#[derive(Args)]
7131pub struct ResolverInstallerArgs {
7132 #[command(flatten)]
7133 pub index_args: IndexArgs,
7134
7135 /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7136 /// `--refresh`.
7137 #[arg(
7138 long,
7139 short = 'U',
7140 overrides_with("no_upgrade"),
7141 help_heading = "Resolver options"
7142 )]
7143 pub upgrade: bool,
7144
7145 #[arg(
7146 long,
7147 overrides_with("upgrade"),
7148 hide = true,
7149 help_heading = "Resolver options"
7150 )]
7151 pub no_upgrade: bool,
7152
7153 /// Allow upgrades for a specific package, ignoring pinned versions in any existing output file.
7154 /// Implies `--refresh-package`.
7155 #[arg(long, short = 'P', help_heading = "Resolver options", value_hint = ValueHint::Other)]
7156 pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7157
7158 /// Reinstall all packages, regardless of whether they're already installed. Implies
7159 /// `--refresh`.
7160 #[arg(
7161 long,
7162 alias = "force-reinstall",
7163 overrides_with("no_reinstall"),
7164 help_heading = "Installer options"
7165 )]
7166 pub reinstall: bool,
7167
7168 #[arg(
7169 long,
7170 overrides_with("reinstall"),
7171 hide = true,
7172 help_heading = "Installer options"
7173 )]
7174 pub no_reinstall: bool,
7175
7176 /// Reinstall a specific package, regardless of whether it's already installed. Implies
7177 /// `--refresh-package`.
7178 #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7179 pub reinstall_package: Vec<PackageName>,
7180
7181 /// The strategy to use when resolving against multiple index URLs.
7182 ///
7183 /// By default, uv will stop at the first index on which a given package is available, and limit
7184 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7185 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7186 /// to an alternate index.
7187 #[arg(
7188 long,
7189 value_enum,
7190 env = EnvVars::UV_INDEX_STRATEGY,
7191 help_heading = "Index options"
7192 )]
7193 pub index_strategy: Option<IndexStrategy>,
7194
7195 /// Attempt to use `keyring` for authentication for index URLs.
7196 ///
7197 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7198 /// the `keyring` CLI to handle authentication.
7199 ///
7200 /// Defaults to `disabled`.
7201 #[arg(
7202 long,
7203 value_enum,
7204 env = EnvVars::UV_KEYRING_PROVIDER,
7205 help_heading = "Index options"
7206 )]
7207 pub keyring_provider: Option<KeyringProviderType>,
7208
7209 /// The strategy to use when selecting between the different compatible versions for a given
7210 /// package requirement.
7211 ///
7212 /// By default, uv will use the latest compatible version of each package (`highest`).
7213 #[arg(
7214 long,
7215 value_enum,
7216 env = EnvVars::UV_RESOLUTION,
7217 help_heading = "Resolver options"
7218 )]
7219 pub resolution: Option<ResolutionMode>,
7220
7221 /// The strategy to use when considering pre-release versions.
7222 ///
7223 /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
7224 /// with first-party requirements that contain an explicit pre-release marker in the declared
7225 /// specifiers (`if-necessary-or-explicit`).
7226 #[arg(
7227 long,
7228 value_enum,
7229 env = EnvVars::UV_PRERELEASE,
7230 help_heading = "Resolver options"
7231 )]
7232 pub prerelease: Option<PrereleaseMode>,
7233
7234 #[arg(long, hide = true)]
7235 pub pre: bool,
7236
7237 /// The strategy to use when selecting multiple versions of a given package across Python
7238 /// versions and platforms.
7239 ///
7240 /// By default, uv will optimize for selecting the latest version of each package for each
7241 /// supported Python version (`requires-python`), while minimizing the number of selected
7242 /// versions across platforms.
7243 ///
7244 /// Under `fewest`, uv will minimize the number of selected versions for each package,
7245 /// preferring older versions that are compatible with a wider range of supported Python
7246 /// versions or platforms.
7247 #[arg(
7248 long,
7249 value_enum,
7250 env = EnvVars::UV_FORK_STRATEGY,
7251 help_heading = "Resolver options"
7252 )]
7253 pub fork_strategy: Option<ForkStrategy>,
7254
7255 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7256 #[arg(
7257 long,
7258 short = 'C',
7259 alias = "config-settings",
7260 help_heading = "Build options",
7261 value_hint = ValueHint::Other,
7262 )]
7263 pub config_setting: Option<Vec<ConfigSettingEntry>>,
7264
7265 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7266 #[arg(
7267 long,
7268 alias = "config-settings-package",
7269 help_heading = "Build options",
7270 value_hint = ValueHint::Other,
7271 )]
7272 pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7273
7274 /// Disable isolation when building source distributions.
7275 ///
7276 /// Assumes that build dependencies specified by PEP 518 are already installed.
7277 #[arg(
7278 long,
7279 overrides_with("build_isolation"),
7280 help_heading = "Build options",
7281 env = EnvVars::UV_NO_BUILD_ISOLATION,
7282 value_parser = clap::builder::BoolishValueParser::new(),
7283 )]
7284 pub no_build_isolation: bool,
7285
7286 /// Disable isolation when building source distributions for a specific package.
7287 ///
7288 /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7289 #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7290 pub no_build_isolation_package: Vec<PackageName>,
7291
7292 #[arg(
7293 long,
7294 overrides_with("no_build_isolation"),
7295 hide = true,
7296 help_heading = "Build options"
7297 )]
7298 pub build_isolation: bool,
7299
7300 /// Limit candidate packages to those that were uploaded prior to the given date.
7301 ///
7302 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7303 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7304 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7305 /// `P7D`, `P30D`).
7306 ///
7307 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7308 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7309 /// Calendar units such as months and years are not allowed.
7310 #[arg(
7311 long,
7312 env = EnvVars::UV_EXCLUDE_NEWER,
7313 help_heading = "Resolver options",
7314 value_hint = ValueHint::Other,
7315 )]
7316 pub exclude_newer: Option<ExcludeNewerValue>,
7317
7318 /// Limit candidate packages for specific packages to those that were uploaded prior to the
7319 /// given date.
7320 ///
7321 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7322 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7323 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7324 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7325 /// `P30D`).
7326 ///
7327 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7328 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7329 /// Calendar units such as months and years are not allowed.
7330 ///
7331 /// Can be provided multiple times for different packages.
7332 #[arg(long, help_heading = "Resolver options", value_hint = ValueHint::Other)]
7333 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7334
7335 /// The method to use when installing packages from the global cache.
7336 ///
7337 /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
7338 /// Windows.
7339 ///
7340 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7341 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7342 /// will break all installed packages by way of removing the underlying source files. Use
7343 /// symlinks with caution.
7344 #[arg(
7345 long,
7346 value_enum,
7347 env = EnvVars::UV_LINK_MODE,
7348 help_heading = "Installer options"
7349 )]
7350 pub link_mode: Option<uv_install_wheel::LinkMode>,
7351
7352 /// Compile Python files to bytecode after installation.
7353 ///
7354 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7355 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7356 /// in which start time is critical, such as CLI applications and Docker containers, this option
7357 /// can be enabled to trade longer installation times for faster start times.
7358 ///
7359 /// When enabled, uv will process the entire site-packages directory (including packages that
7360 /// are not being modified by the current operation) for consistency. Like pip, it will also
7361 /// ignore errors.
7362 #[arg(
7363 long,
7364 alias = "compile",
7365 overrides_with("no_compile_bytecode"),
7366 help_heading = "Installer options",
7367 env = EnvVars::UV_COMPILE_BYTECODE,
7368 value_parser = clap::builder::BoolishValueParser::new(),
7369 )]
7370 pub compile_bytecode: bool,
7371
7372 #[arg(
7373 long,
7374 alias = "no-compile",
7375 overrides_with("compile_bytecode"),
7376 hide = true,
7377 help_heading = "Installer options"
7378 )]
7379 pub no_compile_bytecode: bool,
7380
7381 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7382 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7383 /// URL, or local path sources.
7384 #[arg(
7385 long,
7386 env = EnvVars::UV_NO_SOURCES,
7387 value_parser = clap::builder::BoolishValueParser::new(),
7388 help_heading = "Resolver options",
7389 )]
7390 pub no_sources: bool,
7391}
7392
7393/// Arguments that are used by commands that need to fetch from the Simple API.
7394#[derive(Args)]
7395pub struct FetchArgs {
7396 #[command(flatten)]
7397 pub index_args: IndexArgs,
7398
7399 /// The strategy to use when resolving against multiple index URLs.
7400 ///
7401 /// By default, uv will stop at the first index on which a given package is available, and limit
7402 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7403 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7404 /// to an alternate index.
7405 #[arg(
7406 long,
7407 value_enum,
7408 env = EnvVars::UV_INDEX_STRATEGY,
7409 help_heading = "Index options"
7410 )]
7411 pub index_strategy: Option<IndexStrategy>,
7412
7413 /// Attempt to use `keyring` for authentication for index URLs.
7414 ///
7415 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7416 /// the `keyring` CLI to handle authentication.
7417 ///
7418 /// Defaults to `disabled`.
7419 #[arg(
7420 long,
7421 value_enum,
7422 env = EnvVars::UV_KEYRING_PROVIDER,
7423 help_heading = "Index options"
7424 )]
7425 pub keyring_provider: Option<KeyringProviderType>,
7426
7427 /// Limit candidate packages to those that were uploaded prior to the given date.
7428 ///
7429 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7430 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7431 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7432 /// `P7D`, `P30D`).
7433 ///
7434 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7435 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7436 /// Calendar units such as months and years are not allowed.
7437 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7438 pub exclude_newer: Option<ExcludeNewerValue>,
7439}
7440
7441#[derive(Args)]
7442pub struct DisplayTreeArgs {
7443 /// Maximum display depth of the dependency tree
7444 #[arg(long, short, default_value_t = 255)]
7445 pub depth: u8,
7446
7447 /// Prune the given package from the display of the dependency tree.
7448 #[arg(long, value_hint = ValueHint::Other)]
7449 pub prune: Vec<PackageName>,
7450
7451 /// Display only the specified packages.
7452 #[arg(long, value_hint = ValueHint::Other)]
7453 pub package: Vec<PackageName>,
7454
7455 /// Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its
7456 /// dependencies, further occurrences will not re-display its dependencies, and will include a
7457 /// (*) to indicate it has already been shown. This flag will cause those duplicates to be
7458 /// repeated.
7459 #[arg(long)]
7460 pub no_dedupe: bool,
7461
7462 /// Show the reverse dependencies for the given package. This flag will invert the tree and
7463 /// display the packages that depend on the given package.
7464 #[arg(long, alias = "reverse")]
7465 pub invert: bool,
7466
7467 /// Show the latest available version of each package in the tree.
7468 #[arg(long)]
7469 pub outdated: bool,
7470
7471 /// Show compressed wheel sizes for packages in the tree.
7472 #[arg(long)]
7473 pub show_sizes: bool,
7474}
7475
7476#[derive(Args, Debug)]
7477pub struct PublishArgs {
7478 /// Paths to the files to upload. Accepts glob expressions.
7479 ///
7480 /// Defaults to the `dist` directory. Selects only wheels and source distributions
7481 /// and their attestations, while ignoring other files.
7482 #[arg(default_value = "dist/*", value_hint = ValueHint::FilePath)]
7483 pub files: Vec<String>,
7484
7485 /// The name of an index in the configuration to use for publishing.
7486 ///
7487 /// The index must have a `publish-url` setting, for example:
7488 ///
7489 /// ```toml
7490 /// [[tool.uv.index]]
7491 /// name = "pypi"
7492 /// url = "https://pypi.org/simple"
7493 /// publish-url = "https://upload.pypi.org/legacy/"
7494 /// ```
7495 ///
7496 /// The index `url` will be used to check for existing files to skip duplicate uploads.
7497 ///
7498 /// With these settings, the following two calls are equivalent:
7499 ///
7500 /// ```shell
7501 /// uv publish --index pypi
7502 /// uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pypi.org/simple
7503 /// ```
7504 #[arg(
7505 long,
7506 verbatim_doc_comment,
7507 env = EnvVars::UV_PUBLISH_INDEX,
7508 conflicts_with = "publish_url",
7509 conflicts_with = "check_url",
7510 value_hint = ValueHint::Other,
7511 )]
7512 pub index: Option<String>,
7513
7514 /// The username for the upload.
7515 #[arg(short, long, env = EnvVars::UV_PUBLISH_USERNAME, value_hint = ValueHint::Other)]
7516 pub username: Option<String>,
7517
7518 /// The password for the upload.
7519 #[arg(short, long, env = EnvVars::UV_PUBLISH_PASSWORD, value_hint = ValueHint::Other)]
7520 pub password: Option<String>,
7521
7522 /// The token for the upload.
7523 ///
7524 /// Using a token is equivalent to passing `__token__` as `--username` and the token as
7525 /// `--password` password.
7526 #[arg(
7527 short,
7528 long,
7529 env = EnvVars::UV_PUBLISH_TOKEN,
7530 conflicts_with = "username",
7531 conflicts_with = "password",
7532 value_hint = ValueHint::Other,
7533 )]
7534 pub token: Option<String>,
7535
7536 /// Configure trusted publishing.
7537 ///
7538 /// By default, uv checks for trusted publishing when running in a supported environment, but
7539 /// ignores it if it isn't configured.
7540 ///
7541 /// uv's supported environments for trusted publishing include GitHub Actions and GitLab CI/CD.
7542 #[arg(long)]
7543 pub trusted_publishing: Option<TrustedPublishing>,
7544
7545 /// Attempt to use `keyring` for authentication for remote requirements files.
7546 ///
7547 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7548 /// the `keyring` CLI to handle authentication.
7549 ///
7550 /// Defaults to `disabled`.
7551 #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
7552 pub keyring_provider: Option<KeyringProviderType>,
7553
7554 /// The URL of the upload endpoint (not the index URL).
7555 ///
7556 /// Note that there are typically different URLs for index access (e.g., `https:://.../simple`)
7557 /// and index upload.
7558 ///
7559 /// Defaults to PyPI's publish URL (<https://upload.pypi.org/legacy/>).
7560 #[arg(long, env = EnvVars::UV_PUBLISH_URL)]
7561 pub publish_url: Option<DisplaySafeUrl>,
7562
7563 /// Check an index URL for existing files to skip duplicate uploads.
7564 ///
7565 /// This option allows retrying publishing that failed after only some, but not all files have
7566 /// been uploaded, and handles errors due to parallel uploads of the same file.
7567 ///
7568 /// Before uploading, the index is checked. If the exact same file already exists in the index,
7569 /// the file will not be uploaded. If an error occurred during the upload, the index is checked
7570 /// again, to handle cases where the identical file was uploaded twice in parallel.
7571 ///
7572 /// The exact behavior will vary based on the index. When uploading to PyPI, uploading the same
7573 /// file succeeds even without `--check-url`, while most other indexes error. When uploading to
7574 /// pyx, the index URL can be inferred automatically from the publish URL.
7575 ///
7576 /// The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).
7577 #[arg(long, env = EnvVars::UV_PUBLISH_CHECK_URL)]
7578 pub check_url: Option<IndexUrl>,
7579
7580 #[arg(long, hide = true)]
7581 pub skip_existing: bool,
7582
7583 /// Perform a dry run without uploading files.
7584 ///
7585 /// When enabled, the command will check for existing files if `--check-url` is provided,
7586 /// and will perform validation against the index if supported, but will not upload any files.
7587 #[arg(long)]
7588 pub dry_run: bool,
7589
7590 /// Do not upload attestations for the published files.
7591 ///
7592 /// By default, uv attempts to upload matching PEP 740 attestations with each distribution
7593 /// that is published.
7594 #[arg(long, env = EnvVars::UV_PUBLISH_NO_ATTESTATIONS)]
7595 pub no_attestations: bool,
7596}
7597
7598#[derive(Args)]
7599pub struct WorkspaceNamespace {
7600 #[command(subcommand)]
7601 pub command: WorkspaceCommand,
7602}
7603
7604#[derive(Subcommand)]
7605pub enum WorkspaceCommand {
7606 /// View metadata about the current workspace.
7607 ///
7608 /// The output of this command is not yet stable.
7609 Metadata(MetadataArgs),
7610 /// Display the path of a workspace member.
7611 ///
7612 /// By default, the path to the workspace root directory is displayed.
7613 /// The `--package` option can be used to display the path to a workspace member instead.
7614 ///
7615 /// If used outside of a workspace, i.e., if a `pyproject.toml` cannot be found, uv will exit with an error.
7616 Dir(WorkspaceDirArgs),
7617 /// List the members of a workspace.
7618 ///
7619 /// Displays newline separated names of workspace members.
7620 #[command(hide = true)]
7621 List(WorkspaceListArgs),
7622}
7623
7624#[derive(Args, Debug)]
7625pub struct MetadataArgs;
7626
7627#[derive(Args, Debug)]
7628pub struct WorkspaceDirArgs {
7629 /// Display the path to a specific package in the workspace.
7630 #[arg(long, value_hint = ValueHint::Other)]
7631 pub package: Option<PackageName>,
7632}
7633
7634#[derive(Args, Debug)]
7635pub struct WorkspaceListArgs {
7636 /// Show paths instead of names.
7637 #[arg(long)]
7638 pub paths: bool,
7639}
7640
7641/// See [PEP 517](https://peps.python.org/pep-0517/) and
7642/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.
7643#[derive(Subcommand)]
7644pub enum BuildBackendCommand {
7645 /// PEP 517 hook `build_sdist`.
7646 BuildSdist { sdist_directory: PathBuf },
7647 /// PEP 517 hook `build_wheel`.
7648 BuildWheel {
7649 wheel_directory: PathBuf,
7650 #[arg(long)]
7651 metadata_directory: Option<PathBuf>,
7652 },
7653 /// PEP 660 hook `build_editable`.
7654 BuildEditable {
7655 wheel_directory: PathBuf,
7656 #[arg(long)]
7657 metadata_directory: Option<PathBuf>,
7658 },
7659 /// PEP 517 hook `get_requires_for_build_sdist`.
7660 GetRequiresForBuildSdist,
7661 /// PEP 517 hook `get_requires_for_build_wheel`.
7662 GetRequiresForBuildWheel,
7663 /// PEP 517 hook `prepare_metadata_for_build_wheel`.
7664 PrepareMetadataForBuildWheel { wheel_directory: PathBuf },
7665 /// PEP 660 hook `get_requires_for_build_editable`.
7666 GetRequiresForBuildEditable,
7667 /// PEP 660 hook `prepare_metadata_for_build_editable`.
7668 PrepareMetadataForBuildEditable { wheel_directory: PathBuf },
7669}