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