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