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