Skip to main content

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