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