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