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