Skip to main content

uv_cli/
lib.rs

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