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