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    /// (Deprecated: use `--system-certs` instead.) Whether to load TLS certificates from the
240    /// platform's native certificate store [env: 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::PipUninstallCompatArgs,
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(
3119        long,
3120        alias = "no-workspace",
3121        env = EnvVars::UV_NO_PROJECT,
3122        value_parser = clap::builder::BoolishValueParser::new()
3123    )]
3124    pub no_project: bool,
3125
3126    /// Install seed packages (one or more of: `pip`, `setuptools`, and `wheel`) into the virtual
3127    /// environment [env: UV_VENV_SEED=]
3128    ///
3129    /// Note that `setuptools` and `wheel` are not included in Python 3.12+ environments.
3130    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3131    pub seed: bool,
3132
3133    /// Remove any existing files or directories at the target path [env: UV_VENV_CLEAR=]
3134    ///
3135    /// By default, `uv venv` will exit with an error if the given path is non-empty. The
3136    /// `--clear` option will instead clear a non-empty path before creating a new virtual
3137    /// environment.
3138    #[clap(long, short, overrides_with = "allow_existing", value_parser = clap::builder::BoolishValueParser::new())]
3139    pub clear: bool,
3140
3141    /// Fail without prompting if any existing files or directories are present at the target path.
3142    ///
3143    /// By default, when a TTY is available, `uv venv` will prompt to clear a non-empty directory.
3144    /// When `--no-clear` is used, the command will exit with an error instead of prompting.
3145    #[clap(
3146        long,
3147        overrides_with = "clear",
3148        conflicts_with = "allow_existing",
3149        hide = true
3150    )]
3151    pub no_clear: bool,
3152
3153    /// Preserve any existing files or directories at the target path.
3154    ///
3155    /// By default, `uv venv` will exit with an error if the given path is non-empty. The
3156    /// `--allow-existing` option will instead write to the given path, regardless of its contents,
3157    /// and without clearing it beforehand.
3158    ///
3159    /// WARNING: This option can lead to unexpected behavior if the existing virtual environment and
3160    /// the newly-created virtual environment are linked to different Python interpreters.
3161    #[clap(long, overrides_with = "clear")]
3162    pub allow_existing: bool,
3163
3164    /// The path to the virtual environment to create.
3165    ///
3166    /// Default to `.venv` in the working directory.
3167    ///
3168    /// Relative paths are resolved relative to the working directory.
3169    #[arg(value_hint = ValueHint::DirPath)]
3170    pub path: Option<PathBuf>,
3171
3172    /// Provide an alternative prompt prefix for the virtual environment.
3173    ///
3174    /// By default, the prompt is dependent on whether a path was provided to `uv venv`. If provided
3175    /// (e.g, `uv venv project`), the prompt is set to the directory name. If not provided
3176    /// (`uv venv`), the prompt is set to the current directory's name.
3177    ///
3178    /// If "." is provided, the current directory name will be used regardless of whether a path was
3179    /// provided to `uv venv`.
3180    #[arg(long, verbatim_doc_comment, value_hint = ValueHint::Other)]
3181    pub prompt: Option<String>,
3182
3183    /// Give the virtual environment access to the system site packages directory.
3184    ///
3185    /// Unlike `pip`, when a virtual environment is created with `--system-site-packages`, uv will
3186    /// _not_ take system site packages into account when running commands like `uv pip list` or `uv
3187    /// pip install`. The `--system-site-packages` flag will provide the virtual environment with
3188    /// access to the system site packages directory at runtime, but will not affect the behavior of
3189    /// uv commands.
3190    #[arg(long)]
3191    pub system_site_packages: bool,
3192
3193    /// Make the virtual environment relocatable [env: UV_VENV_RELOCATABLE=]
3194    ///
3195    /// A relocatable virtual environment can be moved around and redistributed without invalidating
3196    /// its associated entrypoint and activation scripts.
3197    ///
3198    /// Note that this can only be guaranteed for standard `console_scripts` and `gui_scripts`.
3199    /// Other scripts may be adjusted if they ship with a generic `#!python[w]` shebang, and
3200    /// binaries are left as-is.
3201    ///
3202    /// As a result of making the environment relocatable (by way of writing relative, rather than
3203    /// absolute paths), the entrypoints and scripts themselves will _not_ be relocatable. In other
3204    /// words, copying those entrypoints and scripts to a location outside the environment will not
3205    /// work, as they reference paths relative to the environment itself.
3206    #[expect(clippy::doc_markdown)]
3207    #[arg(long, overrides_with("no_relocatable"))]
3208    pub relocatable: bool,
3209
3210    /// Don't make the virtual environment relocatable.
3211    ///
3212    /// Disables the default relocatable behavior when the `relocatable-envs-default` preview
3213    /// feature is enabled.
3214    #[arg(long, overrides_with("relocatable"), hide = true)]
3215    pub no_relocatable: bool,
3216
3217    #[command(flatten)]
3218    pub index_args: IndexArgs,
3219
3220    /// The strategy to use when resolving against multiple index URLs.
3221    ///
3222    /// By default, uv will stop at the first index on which a given package is available, and
3223    /// limit resolutions to those present on that first index (`first-index`). This prevents
3224    /// "dependency confusion" attacks, whereby an attacker can upload a malicious package under the
3225    /// same name to an alternate index.
3226    #[arg(long, value_enum, env = EnvVars::UV_INDEX_STRATEGY)]
3227    pub index_strategy: Option<IndexStrategy>,
3228
3229    /// Attempt to use `keyring` for authentication for index URLs.
3230    ///
3231    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
3232    /// the `keyring` CLI to handle authentication.
3233    ///
3234    /// Defaults to `disabled`.
3235    #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
3236    pub keyring_provider: Option<KeyringProviderType>,
3237
3238    /// Limit candidate packages to those that were uploaded prior to the given date.
3239    ///
3240    /// The date is compared against the upload time of each individual distribution artifact
3241    /// (i.e., when each file was uploaded to the package index), not the release date of the
3242    /// package version.
3243    ///
3244    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
3245    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
3246    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
3247    /// `P7D`, `P30D`).
3248    ///
3249    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
3250    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
3251    /// Calendar units such as months and years are not allowed.
3252    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER)]
3253    pub exclude_newer: Option<ExcludeNewerValue>,
3254
3255    /// Limit candidate packages for a specific package to those that were uploaded prior to the
3256    /// given date.
3257    ///
3258    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
3259    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
3260    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
3261    /// (e.g., `24 hours`, `1 week`, `30 days`), or a ISO 8601 duration (e.g., `PT24H`, `P7D`,
3262    /// `P30D`).
3263    ///
3264    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
3265    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
3266    /// Calendar units such as months and years are not allowed.
3267    ///
3268    /// Can be provided multiple times for different packages.
3269    #[arg(long)]
3270    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
3271
3272    /// The method to use when installing packages from the global cache.
3273    ///
3274    /// This option is only used for installing seed packages.
3275    ///
3276    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
3277    /// Windows.
3278    ///
3279    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
3280    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
3281    /// will break all installed packages by way of removing the underlying source files. Use
3282    /// symlinks with caution.
3283    #[arg(long, value_enum, env = EnvVars::UV_LINK_MODE)]
3284    pub link_mode: Option<uv_install_wheel::LinkMode>,
3285
3286    #[command(flatten)]
3287    pub refresh: RefreshArgs,
3288
3289    #[command(flatten)]
3290    pub compat_args: compat::VenvCompatArgs,
3291}
3292
3293#[derive(Parser, Debug, Clone)]
3294pub enum ExternalCommand {
3295    #[command(external_subcommand)]
3296    Cmd(Vec<OsString>),
3297}
3298
3299impl Deref for ExternalCommand {
3300    type Target = Vec<OsString>;
3301
3302    fn deref(&self) -> &Self::Target {
3303        match self {
3304            Self::Cmd(cmd) => cmd,
3305        }
3306    }
3307}
3308
3309impl DerefMut for ExternalCommand {
3310    fn deref_mut(&mut self) -> &mut Self::Target {
3311        match self {
3312            Self::Cmd(cmd) => cmd,
3313        }
3314    }
3315}
3316
3317impl ExternalCommand {
3318    pub fn split(&self) -> (Option<&OsString>, &[OsString]) {
3319        match self.as_slice() {
3320            [] => (None, &[]),
3321            [cmd, args @ ..] => (Some(cmd), args),
3322        }
3323    }
3324}
3325
3326#[derive(Debug, Default, Copy, Clone, clap::ValueEnum)]
3327pub enum AuthorFrom {
3328    /// Fetch the author information from some sources (e.g., Git) automatically.
3329    #[default]
3330    Auto,
3331    /// Fetch the author information from Git configuration only.
3332    Git,
3333    /// Do not infer the author information.
3334    None,
3335}
3336
3337#[derive(Args)]
3338pub struct InitArgs {
3339    /// The path to use for the project/script.
3340    ///
3341    /// Defaults to the current working directory when initializing an app or library; required when
3342    /// initializing a script. Accepts relative and absolute paths.
3343    ///
3344    /// If a `pyproject.toml` is found in any of the parent directories of the target path, the
3345    /// project will be added as a workspace member of the parent, unless `--no-workspace` is
3346    /// provided.
3347    #[arg(required_if_eq("script", "true"), value_hint = ValueHint::DirPath)]
3348    pub path: Option<PathBuf>,
3349
3350    /// The name of the project.
3351    ///
3352    /// Defaults to the name of the directory.
3353    #[arg(long, conflicts_with = "script", value_hint = ValueHint::Other)]
3354    pub name: Option<PackageName>,
3355
3356    /// Only create a `pyproject.toml`.
3357    ///
3358    /// Disables creating extra files like `README.md`, the `src/` tree, `.python-version` files,
3359    /// etc.
3360    ///
3361    /// When combined with `--script`, the script will only contain the inline metadata header.
3362    #[arg(long)]
3363    pub bare: bool,
3364
3365    /// Create a virtual project, rather than a package.
3366    ///
3367    /// This option is deprecated and will be removed in a future release.
3368    #[arg(long, hide = true, conflicts_with = "package")]
3369    pub r#virtual: bool,
3370
3371    /// Set up the project to be built as a Python package.
3372    ///
3373    /// Defines a `[build-system]` for the project.
3374    ///
3375    /// This is the default behavior when using `--lib` or `--build-backend`.
3376    ///
3377    /// When using `--app`, this will include a `[project.scripts]` entrypoint and use a `src/`
3378    /// project structure.
3379    #[arg(long, overrides_with = "no_package")]
3380    pub r#package: bool,
3381
3382    /// Do not set up the project to be built as a Python package.
3383    ///
3384    /// Does not include a `[build-system]` for the project.
3385    ///
3386    /// This is the default behavior when using `--app`.
3387    #[arg(long, overrides_with = "package", conflicts_with_all = ["lib", "build_backend"])]
3388    pub r#no_package: bool,
3389
3390    /// Create a project for an application.
3391    ///
3392    /// This is the default behavior if `--lib` is not requested.
3393    ///
3394    /// This project kind is for web servers, scripts, and command-line interfaces.
3395    ///
3396    /// By default, an application is not intended to be built and distributed as a Python package.
3397    /// The `--package` option can be used to create an application that is distributable, e.g., if
3398    /// you want to distribute a command-line interface via PyPI.
3399    #[arg(long, alias = "application", conflicts_with_all = ["lib", "script"])]
3400    pub r#app: bool,
3401
3402    /// Create a project for a library.
3403    ///
3404    /// A library is a project that is intended to be built and distributed as a Python package.
3405    #[arg(long, alias = "library", conflicts_with_all=["app", "script"])]
3406    pub r#lib: bool,
3407
3408    /// Create a script.
3409    ///
3410    /// A script is a standalone file with embedded metadata enumerating its dependencies, along
3411    /// with any Python version requirements, as defined in the PEP 723 specification.
3412    ///
3413    /// PEP 723 scripts can be executed directly with `uv run`.
3414    ///
3415    /// By default, adds a requirement on the system Python version; use `--python` to specify an
3416    /// alternative Python version requirement.
3417    #[arg(long, conflicts_with_all=["app", "lib", "package", "build_backend", "description"])]
3418    pub r#script: bool,
3419
3420    /// Set the project description.
3421    #[arg(long, conflicts_with = "script", overrides_with = "no_description", value_hint = ValueHint::Other)]
3422    pub description: Option<String>,
3423
3424    /// Disable the description for the project.
3425    #[arg(long, conflicts_with = "script", overrides_with = "description")]
3426    pub no_description: bool,
3427
3428    /// Initialize a version control system for the project.
3429    ///
3430    /// By default, uv will initialize a Git repository (`git`). Use `--vcs none` to explicitly
3431    /// avoid initializing a version control system.
3432    #[arg(long, value_enum, conflicts_with = "script")]
3433    pub vcs: Option<VersionControlSystem>,
3434
3435    /// Initialize a build-backend of choice for the project.
3436    ///
3437    /// Implicitly sets `--package`.
3438    #[arg(long, value_enum, conflicts_with_all=["script", "no_package"], env = EnvVars::UV_INIT_BUILD_BACKEND)]
3439    pub build_backend: Option<ProjectBuildBackend>,
3440
3441    /// Invalid option name for build backend.
3442    #[arg(
3443        long,
3444        required(false),
3445        action(clap::ArgAction::SetTrue),
3446        value_parser=clap::builder::UnknownArgumentValueParser::suggest_arg("--build-backend"),
3447        hide(true)
3448    )]
3449    backend: Option<String>,
3450
3451    /// Do not create a `README.md` file.
3452    #[arg(long)]
3453    pub no_readme: bool,
3454
3455    /// Fill in the `authors` field in the `pyproject.toml`.
3456    ///
3457    /// By default, uv will attempt to infer the author information from some sources (e.g., Git)
3458    /// (`auto`). Use `--author-from git` to only infer from Git configuration. Use `--author-from
3459    /// none` to avoid inferring the author information.
3460    #[arg(long, value_enum)]
3461    pub author_from: Option<AuthorFrom>,
3462
3463    /// Do not create a `.python-version` file for the project.
3464    ///
3465    /// By default, uv will create a `.python-version` file containing the minor version of the
3466    /// discovered Python interpreter, which will cause subsequent uv commands to use that version.
3467    #[arg(long)]
3468    pub no_pin_python: bool,
3469
3470    /// Create a `.python-version` file for the project.
3471    ///
3472    /// This is the default.
3473    #[arg(long, hide = true)]
3474    pub pin_python: bool,
3475
3476    /// Avoid discovering a workspace and create a standalone project.
3477    ///
3478    /// By default, uv searches for workspaces in the current directory or any parent directory.
3479    #[arg(long, alias = "no-project")]
3480    pub no_workspace: bool,
3481
3482    /// The Python interpreter to use to determine the minimum supported Python version.
3483    ///
3484    /// See `uv help python` to view supported request formats.
3485    #[arg(
3486        long,
3487        short,
3488        env = EnvVars::UV_PYTHON,
3489        verbatim_doc_comment,
3490        help_heading = "Python options",
3491        value_parser = parse_maybe_string,
3492        value_hint = ValueHint::Other,
3493    )]
3494    pub python: Option<Maybe<String>>,
3495}
3496
3497#[derive(Args)]
3498pub struct RunArgs {
3499    /// Include optional dependencies from the specified extra name.
3500    ///
3501    /// May be provided more than once.
3502    ///
3503    /// This option is only available when running in a project.
3504    #[arg(
3505        long,
3506        conflicts_with = "all_extras",
3507        conflicts_with = "only_group",
3508        value_delimiter = ',',
3509        value_parser = extra_name_with_clap_error,
3510        value_hint = ValueHint::Other,
3511    )]
3512    pub extra: Option<Vec<ExtraName>>,
3513
3514    /// Include all optional dependencies.
3515    ///
3516    /// This option is only available when running in a project.
3517    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3518    pub all_extras: bool,
3519
3520    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3521    ///
3522    /// May be provided multiple times.
3523    #[arg(long, value_hint = ValueHint::Other)]
3524    pub no_extra: Vec<ExtraName>,
3525
3526    #[arg(long, overrides_with("all_extras"), hide = true)]
3527    pub no_all_extras: bool,
3528
3529    /// Include the development dependency group [env: UV_DEV=]
3530    ///
3531    /// Development dependencies are defined via `dependency-groups.dev` or
3532    /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
3533    ///
3534    /// This option is an alias for `--group dev`.
3535    ///
3536    /// This option is only available when running in a project.
3537    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
3538    pub dev: bool,
3539
3540    /// Disable the development dependency group [env: UV_NO_DEV=]
3541    ///
3542    /// This option is an alias of `--no-group dev`.
3543    /// See `--no-default-groups` to disable all default groups instead.
3544    ///
3545    /// This option is only available when running in a project.
3546    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
3547    pub no_dev: bool,
3548
3549    /// Include dependencies from the specified dependency group.
3550    ///
3551    /// May be provided multiple times.
3552    #[arg(long, conflicts_with_all = ["only_group", "only_dev"], value_hint = ValueHint::Other)]
3553    pub group: Vec<GroupName>,
3554
3555    /// Disable the specified dependency group.
3556    ///
3557    /// This option always takes precedence over default groups,
3558    /// `--all-groups`, and `--group`.
3559    ///
3560    /// May be provided multiple times.
3561    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ', value_hint = ValueHint::Other)]
3562    pub no_group: Vec<GroupName>,
3563
3564    /// Ignore the default dependency groups.
3565    ///
3566    /// uv includes the groups defined in `tool.uv.default-groups` by default.
3567    /// This disables that option, however, specific groups can still be included with `--group`.
3568    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
3569    pub no_default_groups: bool,
3570
3571    /// Only include dependencies from the specified dependency group.
3572    ///
3573    /// The project and its dependencies will be omitted.
3574    ///
3575    /// May be provided multiple times. Implies `--no-default-groups`.
3576    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
3577    pub only_group: Vec<GroupName>,
3578
3579    /// Include dependencies from all dependency groups.
3580    ///
3581    /// `--no-group` can be used to exclude specific groups.
3582    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3583    pub all_groups: bool,
3584
3585    /// Run a Python module.
3586    ///
3587    /// Equivalent to `python -m <module>`.
3588    #[arg(short, long, conflicts_with_all = ["script", "gui_script"])]
3589    pub module: bool,
3590
3591    /// Only include the development dependency group.
3592    ///
3593    /// The project and its dependencies will be omitted.
3594    ///
3595    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3596    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3597    pub only_dev: bool,
3598
3599    /// Install any non-editable dependencies, including the project and any workspace members, as
3600    /// editable.
3601    #[arg(long, overrides_with = "no_editable", hide = true)]
3602    pub editable: bool,
3603
3604    /// Install any editable dependencies, including the project and any workspace members, as
3605    /// non-editable [env: UV_NO_EDITABLE=]
3606    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new())]
3607    pub no_editable: bool,
3608
3609    /// Do not remove extraneous packages present in the environment.
3610    #[arg(long, overrides_with("exact"), alias = "no-exact", hide = true)]
3611    pub inexact: bool,
3612
3613    /// Perform an exact sync, removing extraneous packages.
3614    ///
3615    /// When enabled, uv will remove any extraneous packages from the environment. By default, `uv
3616    /// run` will make the minimum necessary changes to satisfy the requirements.
3617    #[arg(long, overrides_with("inexact"))]
3618    pub exact: bool,
3619
3620    /// Load environment variables from a `.env` file.
3621    ///
3622    /// Can be provided multiple times, with subsequent files overriding values defined in previous
3623    /// files.
3624    #[arg(long, env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
3625    pub env_file: Vec<String>,
3626
3627    /// Avoid reading environment variables from a `.env` file [env: UV_NO_ENV_FILE=]
3628    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3629    pub no_env_file: bool,
3630
3631    /// The command to run.
3632    ///
3633    /// If the path to a Python script (i.e., ending in `.py`), it will be
3634    /// executed with the Python interpreter.
3635    #[command(subcommand)]
3636    pub command: Option<ExternalCommand>,
3637
3638    /// Run with the given packages installed.
3639    ///
3640    /// When used in a project, these dependencies will be layered on top of the project environment
3641    /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3642    /// specified by the project.
3643    #[arg(short = 'w', long, value_hint = ValueHint::Other)]
3644    pub with: Vec<comma::CommaSeparatedRequirements>,
3645
3646    /// Run with the given packages installed in editable mode.
3647    ///
3648    /// When used in a project, these dependencies will be layered on top of the project environment
3649    /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3650    /// specified by the project.
3651    #[arg(long, value_hint = ValueHint::DirPath)]
3652    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
3653
3654    /// Run with the packages listed in the given files.
3655    ///
3656    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
3657    /// and `pylock.toml`.
3658    ///
3659    /// The same environment semantics as `--with` apply.
3660    ///
3661    /// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed.
3662    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
3663    pub with_requirements: Vec<Maybe<PathBuf>>,
3664
3665    /// Run the command in an isolated virtual environment [env: UV_ISOLATED=]
3666    ///
3667    /// Usually, the project environment is reused for performance. This option forces a fresh
3668    /// environment to be used for the project, enforcing strict isolation between dependencies and
3669    /// declaration of requirements.
3670    ///
3671    /// An editable installation is still used for the project.
3672    ///
3673    /// When used with `--with` or `--with-requirements`, the additional dependencies will still be
3674    /// layered in a second environment.
3675    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3676    pub isolated: bool,
3677
3678    /// Prefer the active virtual environment over the project's virtual environment.
3679    ///
3680    /// If the project virtual environment is active or no virtual environment is active, this has
3681    /// no effect.
3682    #[arg(long, overrides_with = "no_active")]
3683    pub active: bool,
3684
3685    /// Prefer project's virtual environment over an active environment.
3686    ///
3687    /// This is the default behavior.
3688    #[arg(long, overrides_with = "active", hide = true)]
3689    pub no_active: bool,
3690
3691    /// Avoid syncing the virtual environment [env: UV_NO_SYNC=]
3692    ///
3693    /// Implies `--frozen`, as the project dependencies will be ignored (i.e., the lockfile will not
3694    /// be updated, since the environment will not be synced regardless).
3695    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3696    pub no_sync: bool,
3697
3698    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
3699    ///
3700    /// Requires that the lockfile is up-to-date. If the lockfile is missing or
3701    /// needs to be updated, uv will exit with an error.
3702    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
3703    pub locked: bool,
3704
3705    /// Run without updating the `uv.lock` file [env: UV_FROZEN=]
3706    ///
3707    /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3708    /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3709    /// `pyproject.toml` includes changes to dependencies that have not been included in the
3710    /// lockfile yet, they will not be present in the environment.
3711    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3712    pub frozen: bool,
3713
3714    /// Run the given path as a Python script.
3715    ///
3716    /// Using `--script` will attempt to parse the path as a PEP 723 script,
3717    /// irrespective of its extension.
3718    #[arg(long, short, conflicts_with_all = ["module", "gui_script"])]
3719    pub script: bool,
3720
3721    /// Run the given path as a Python GUI script.
3722    ///
3723    /// Using `--gui-script` will attempt to parse the path as a PEP 723 script and run it with
3724    /// `pythonw.exe`, irrespective of its extension. Only available on Windows.
3725    #[arg(long, conflicts_with_all = ["script", "module"])]
3726    pub gui_script: bool,
3727
3728    #[command(flatten)]
3729    pub installer: ResolverInstallerArgs,
3730
3731    #[command(flatten)]
3732    pub build: BuildOptionsArgs,
3733
3734    #[command(flatten)]
3735    pub refresh: RefreshArgs,
3736
3737    /// Run the command with all workspace members installed.
3738    ///
3739    /// The workspace's environment (`.venv`) is updated to include all workspace members.
3740    ///
3741    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
3742    /// to all workspace members.
3743    #[arg(long, conflicts_with = "package")]
3744    pub all_packages: bool,
3745
3746    /// Run the command in a specific package in the workspace.
3747    ///
3748    /// If the workspace member does not exist, uv will exit with an error.
3749    #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
3750    pub package: Option<PackageName>,
3751
3752    /// Avoid discovering the project or workspace.
3753    ///
3754    /// Instead of searching for projects in the current directory and parent directories, run in an
3755    /// isolated, ephemeral environment populated by the `--with` requirements.
3756    ///
3757    /// If a virtual environment is active or found in a current or parent directory, it will be
3758    /// used as if there was no project or workspace.
3759    #[arg(
3760        long,
3761        alias = "no_workspace",
3762        env = EnvVars::UV_NO_PROJECT,
3763        value_parser = clap::builder::BoolishValueParser::new(),
3764        conflicts_with = "package"
3765    )]
3766    pub no_project: bool,
3767
3768    /// The Python interpreter to use for the run environment.
3769    ///
3770    /// If the interpreter request is satisfied by a discovered environment, the environment will be
3771    /// used.
3772    ///
3773    /// See `uv help python` to view supported request formats.
3774    #[arg(
3775        long,
3776        short,
3777        env = EnvVars::UV_PYTHON,
3778        verbatim_doc_comment,
3779        help_heading = "Python options",
3780        value_parser = parse_maybe_string,
3781        value_hint = ValueHint::Other,
3782    )]
3783    pub python: Option<Maybe<String>>,
3784
3785    /// Whether to show resolver and installer output from any environment modifications [env:
3786    /// UV_SHOW_RESOLUTION=]
3787    ///
3788    /// By default, environment modifications are omitted, but enabled under `--verbose`.
3789    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
3790    pub show_resolution: bool,
3791
3792    /// Number of times that `uv run` will allow recursive invocations.
3793    ///
3794    /// The current recursion depth is tracked by environment variable. If environment variables are
3795    /// cleared, uv will fail to detect the recursion depth.
3796    ///
3797    /// If uv reaches the maximum recursion depth, it will exit with an error.
3798    #[arg(long, hide = true, env = EnvVars::UV_RUN_MAX_RECURSION_DEPTH)]
3799    pub max_recursion_depth: Option<u32>,
3800
3801    /// The platform for which requirements should be installed.
3802    ///
3803    /// Represented as a "target triple", a string that describes the target platform in terms of
3804    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
3805    /// `aarch64-apple-darwin`.
3806    ///
3807    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
3808    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3809    ///
3810    /// When targeting iOS, the default minimum version is `13.0`. Use
3811    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3812    ///
3813    /// When targeting Android, the default minimum Android API level is `24`. Use
3814    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
3815    ///
3816    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
3817    /// platform; as a result, the installed distributions may not be compatible with the _current_
3818    /// platform. Conversely, any distributions that are built from source may be incompatible with
3819    /// the _target_ platform, as they will be built for the _current_ platform. The
3820    /// `--python-platform` option is intended for advanced use cases.
3821    #[arg(long)]
3822    pub python_platform: Option<TargetTriple>,
3823}
3824
3825#[derive(Args)]
3826pub struct SyncArgs {
3827    /// Include optional dependencies from the specified extra name.
3828    ///
3829    /// May be provided more than once.
3830    ///
3831    /// When multiple extras or groups are specified that appear in `tool.uv.conflicts`, uv will
3832    /// report an error.
3833    ///
3834    /// Note that all optional dependencies are always included in the resolution; this option only
3835    /// affects the selection of packages to install.
3836    #[arg(
3837        long,
3838        conflicts_with = "all_extras",
3839        conflicts_with = "only_group",
3840        value_delimiter = ',',
3841        value_parser = extra_name_with_clap_error,
3842        value_hint = ValueHint::Other,
3843    )]
3844    pub extra: Option<Vec<ExtraName>>,
3845
3846    /// Select the output format.
3847    #[arg(long, value_enum, default_value_t = SyncFormat::default())]
3848    pub output_format: SyncFormat,
3849
3850    /// Include all optional dependencies.
3851    ///
3852    /// When two or more extras are declared as conflicting in `tool.uv.conflicts`, using this flag
3853    /// will always result in an error.
3854    ///
3855    /// Note that all optional dependencies are always included in the resolution; this option only
3856    /// affects the selection of packages to install.
3857    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3858    pub all_extras: bool,
3859
3860    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3861    ///
3862    /// May be provided multiple times.
3863    #[arg(long, value_hint = ValueHint::Other)]
3864    pub no_extra: Vec<ExtraName>,
3865
3866    #[arg(long, overrides_with("all_extras"), hide = true)]
3867    pub no_all_extras: bool,
3868
3869    /// Include the development dependency group [env: UV_DEV=]
3870    ///
3871    /// This option is an alias for `--group dev`.
3872    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
3873    pub dev: bool,
3874
3875    /// Disable the development dependency group [env: UV_NO_DEV=]
3876    ///
3877    /// This option is an alias of `--no-group dev`.
3878    /// See `--no-default-groups` to disable all default groups instead.
3879    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
3880    pub no_dev: bool,
3881
3882    /// Only include the development dependency group.
3883    ///
3884    /// The project and its dependencies will be omitted.
3885    ///
3886    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3887    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3888    pub only_dev: bool,
3889
3890    /// Include dependencies from the specified dependency group.
3891    ///
3892    /// When multiple extras or groups are specified that appear in
3893    /// `tool.uv.conflicts`, uv will report an error.
3894    ///
3895    /// May be provided multiple times.
3896    #[arg(long, conflicts_with_all = ["only_group", "only_dev"], value_hint = ValueHint::Other)]
3897    pub group: Vec<GroupName>,
3898
3899    /// Disable the specified dependency group.
3900    ///
3901    /// This option always takes precedence over default groups,
3902    /// `--all-groups`, and `--group`.
3903    ///
3904    /// May be provided multiple times.
3905    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ', value_hint = ValueHint::Other)]
3906    pub no_group: Vec<GroupName>,
3907
3908    /// Ignore the default dependency groups.
3909    ///
3910    /// uv includes the groups defined in `tool.uv.default-groups` by default.
3911    /// This disables that option, however, specific groups can still be included with `--group`.
3912    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
3913    pub no_default_groups: bool,
3914
3915    /// Only include dependencies from the specified dependency group.
3916    ///
3917    /// The project and its dependencies will be omitted.
3918    ///
3919    /// May be provided multiple times. Implies `--no-default-groups`.
3920    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
3921    pub only_group: Vec<GroupName>,
3922
3923    /// Include dependencies from all dependency groups.
3924    ///
3925    /// `--no-group` can be used to exclude specific groups.
3926    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3927    pub all_groups: bool,
3928
3929    /// Install any non-editable dependencies, including the project and any workspace members, as
3930    /// editable.
3931    #[arg(long, overrides_with = "no_editable", hide = true)]
3932    pub editable: bool,
3933
3934    /// Install any editable dependencies, including the project and any workspace members, as
3935    /// non-editable [env: UV_NO_EDITABLE=]
3936    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new())]
3937    pub no_editable: bool,
3938
3939    /// Do not remove extraneous packages present in the environment.
3940    ///
3941    /// When enabled, uv will make the minimum necessary changes to satisfy the requirements.
3942    /// By default, syncing will remove any extraneous packages from the environment
3943    #[arg(long, overrides_with("exact"), alias = "no-exact")]
3944    pub inexact: bool,
3945
3946    /// Perform an exact sync, removing extraneous packages.
3947    #[arg(long, overrides_with("inexact"), hide = true)]
3948    pub exact: bool,
3949
3950    /// Sync dependencies to the active virtual environment.
3951    ///
3952    /// Instead of creating or updating the virtual environment for the project or script, the
3953    /// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
3954    /// set.
3955    #[arg(long, overrides_with = "no_active")]
3956    pub active: bool,
3957
3958    /// Prefer project's virtual environment over an active environment.
3959    ///
3960    /// This is the default behavior.
3961    #[arg(long, overrides_with = "active", hide = true)]
3962    pub no_active: bool,
3963
3964    /// Do not install the current project.
3965    ///
3966    /// By default, the current project is installed into the environment with all of its
3967    /// dependencies. The `--no-install-project` option allows the project to be excluded, but all
3968    /// of its dependencies are still installed. This is particularly useful in situations like
3969    /// building Docker images where installing the project separately from its dependencies allows
3970    /// optimal layer caching.
3971    ///
3972    /// The inverse `--only-install-project` can be used to install _only_ the project itself,
3973    /// excluding all dependencies.
3974    #[arg(long, conflicts_with = "only_install_project")]
3975    pub no_install_project: bool,
3976
3977    /// Only install the current project.
3978    #[arg(long, conflicts_with = "no_install_project", hide = true)]
3979    pub only_install_project: bool,
3980
3981    /// Do not install any workspace members, including the root project.
3982    ///
3983    /// By default, all workspace members and their dependencies are installed into the
3984    /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
3985    /// members while retaining their dependencies. This is particularly useful in situations like
3986    /// building Docker images where installing the workspace separately from its dependencies
3987    /// allows optimal layer caching.
3988    ///
3989    /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
3990    /// excluding all other dependencies.
3991    #[arg(long, conflicts_with = "only_install_workspace")]
3992    pub no_install_workspace: bool,
3993
3994    /// Only install workspace members, including the root project.
3995    #[arg(long, conflicts_with = "no_install_workspace", hide = true)]
3996    pub only_install_workspace: bool,
3997
3998    /// Do not install local path dependencies
3999    ///
4000    /// Skips the current project, workspace members, and any other local (path or editable)
4001    /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
4002    /// heavy third-party dependencies first and layer local packages separately.
4003    ///
4004    /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
4005    /// all remote dependencies.
4006    #[arg(long, conflicts_with = "only_install_local")]
4007    pub no_install_local: bool,
4008
4009    /// Only install local path dependencies
4010    #[arg(long, conflicts_with = "no_install_local", hide = true)]
4011    pub only_install_local: bool,
4012
4013    /// Do not install the given package(s).
4014    ///
4015    /// By default, all of the project's dependencies are installed into the environment. The
4016    /// `--no-install-package` option allows exclusion of specific packages. Note this can result
4017    /// in a broken environment, and should be used with caution.
4018    ///
4019    /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
4020    /// excluding all others.
4021    #[arg(long, conflicts_with = "only_install_package", value_hint = ValueHint::Other)]
4022    pub no_install_package: Vec<PackageName>,
4023
4024    /// Only install the given package(s).
4025    #[arg(long, conflicts_with = "no_install_package", hide = true, value_hint = ValueHint::Other)]
4026    pub only_install_package: Vec<PackageName>,
4027
4028    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
4029    ///
4030    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4031    /// uv will exit with an error.
4032    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
4033    pub locked: bool,
4034
4035    /// Sync without updating the `uv.lock` file [env: UV_FROZEN=]
4036    ///
4037    /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
4038    /// source of truth. If the lockfile is missing, uv will exit with an error. If the
4039    /// `pyproject.toml` includes changes to dependencies that have not been included in the
4040    /// lockfile yet, they will not be present in the environment.
4041    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4042    pub frozen: bool,
4043
4044    /// Perform a dry run, without writing the lockfile or modifying the project environment.
4045    ///
4046    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
4047    /// changes to both the lockfile and the project environment, but will not modify either.
4048    #[arg(long)]
4049    pub dry_run: bool,
4050
4051    #[command(flatten)]
4052    pub installer: ResolverInstallerArgs,
4053
4054    #[command(flatten)]
4055    pub build: BuildOptionsArgs,
4056
4057    #[command(flatten)]
4058    pub refresh: RefreshArgs,
4059
4060    /// Sync all packages in the workspace.
4061    ///
4062    /// The workspace's environment (`.venv`) is updated to include all workspace members.
4063    ///
4064    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
4065    /// to all workspace members.
4066    #[arg(long, conflicts_with = "package")]
4067    pub all_packages: bool,
4068
4069    /// Sync for specific packages in the workspace.
4070    ///
4071    /// The workspace's environment (`.venv`) is updated to reflect the subset of dependencies
4072    /// declared by the specified workspace member packages.
4073    ///
4074    /// If any workspace member does not exist, uv will exit with an error.
4075    #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
4076    pub package: Vec<PackageName>,
4077
4078    /// Sync the environment for a Python script, rather than the current project.
4079    ///
4080    /// If provided, uv will sync the dependencies based on the script's inline metadata table, in
4081    /// adherence with PEP 723.
4082    #[arg(
4083        long,
4084        conflicts_with = "all_packages",
4085        conflicts_with = "package",
4086        conflicts_with = "no_install_project",
4087        conflicts_with = "no_install_workspace",
4088        conflicts_with = "no_install_local",
4089        conflicts_with = "extra",
4090        conflicts_with = "all_extras",
4091        conflicts_with = "no_extra",
4092        conflicts_with = "no_all_extras",
4093        conflicts_with = "dev",
4094        conflicts_with = "no_dev",
4095        conflicts_with = "only_dev",
4096        conflicts_with = "group",
4097        conflicts_with = "no_group",
4098        conflicts_with = "no_default_groups",
4099        conflicts_with = "only_group",
4100        conflicts_with = "all_groups",
4101        value_hint = ValueHint::FilePath,
4102    )]
4103    pub script: Option<PathBuf>,
4104
4105    /// The Python interpreter to use for the project environment.
4106    ///
4107    /// By default, the first interpreter that meets the project's `requires-python` constraint is
4108    /// used.
4109    ///
4110    /// If a Python interpreter in a virtual environment is provided, the packages will not be
4111    /// synced to the given environment. The interpreter will be used to create a virtual
4112    /// environment in the project.
4113    ///
4114    /// See `uv help python` for details on Python discovery and supported request formats.
4115    #[arg(
4116        long,
4117        short,
4118        env = EnvVars::UV_PYTHON,
4119        verbatim_doc_comment,
4120        help_heading = "Python options",
4121        value_parser = parse_maybe_string,
4122        value_hint = ValueHint::Other,
4123    )]
4124    pub python: Option<Maybe<String>>,
4125
4126    /// The platform for which requirements should be installed.
4127    ///
4128    /// Represented as a "target triple", a string that describes the target platform in terms of
4129    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
4130    /// `aarch64-apple-darwin`.
4131    ///
4132    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
4133    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
4134    ///
4135    /// When targeting iOS, the default minimum version is `13.0`. Use
4136    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
4137    ///
4138    /// When targeting Android, the default minimum Android API level is `24`. Use
4139    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
4140    ///
4141    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
4142    /// platform; as a result, the installed distributions may not be compatible with the _current_
4143    /// platform. Conversely, any distributions that are built from source may be incompatible with
4144    /// the _target_ platform, as they will be built for the _current_ platform. The
4145    /// `--python-platform` option is intended for advanced use cases.
4146    #[arg(long)]
4147    pub python_platform: Option<TargetTriple>,
4148
4149    /// Check if the Python environment is synchronized with the project.
4150    ///
4151    /// If the environment is not up to date, uv will exit with an error.
4152    #[arg(long, overrides_with("no_check"))]
4153    pub check: bool,
4154
4155    #[arg(long, overrides_with("check"), hide = true)]
4156    pub no_check: bool,
4157}
4158
4159#[derive(Args)]
4160pub struct LockArgs {
4161    /// Check if the lockfile is up-to-date.
4162    ///
4163    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
4164    /// missing or needs to be updated, uv will exit with an error.
4165    ///
4166    /// Equivalent to `--locked`.
4167    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check_exists", "upgrade"], overrides_with = "check")]
4168    pub check: bool,
4169
4170    /// Check if the lockfile is up-to-date [env: UV_LOCKED=]
4171    ///
4172    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
4173    /// missing or needs to be updated, uv will exit with an error.
4174    ///
4175    /// Equivalent to `--check`.
4176    #[arg(long, conflicts_with_all = ["check_exists", "upgrade"], hide = true)]
4177    pub locked: bool,
4178
4179    /// Assert that a `uv.lock` exists without checking if it is up-to-date [env: UV_FROZEN=]
4180    ///
4181    /// Equivalent to `--frozen`.
4182    #[arg(long, alias = "frozen", conflicts_with_all = ["check", "locked"])]
4183    pub check_exists: bool,
4184
4185    /// Perform a dry run, without writing the lockfile.
4186    ///
4187    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
4188    /// changes, but will not write the lockfile to disk.
4189    #[arg(
4190        long,
4191        conflicts_with = "check_exists",
4192        conflicts_with = "check",
4193        conflicts_with = "locked"
4194    )]
4195    pub dry_run: bool,
4196
4197    /// Lock the specified Python script, rather than the current project.
4198    ///
4199    /// If provided, uv will lock the script (based on its inline metadata table, in adherence with
4200    /// PEP 723) to a `.lock` file adjacent to the script itself.
4201    #[arg(long, value_hint = ValueHint::FilePath)]
4202    pub script: Option<PathBuf>,
4203
4204    #[command(flatten)]
4205    pub resolver: ResolverArgs,
4206
4207    #[command(flatten)]
4208    pub build: BuildOptionsArgs,
4209
4210    #[command(flatten)]
4211    pub refresh: RefreshArgs,
4212
4213    /// The Python interpreter to use during resolution.
4214    ///
4215    /// A Python interpreter is required for building source distributions to determine package
4216    /// metadata when there are not wheels.
4217    ///
4218    /// The interpreter is also used as the fallback value for the minimum Python version if
4219    /// `requires-python` is not set.
4220    ///
4221    /// See `uv help python` for details on Python discovery and supported request formats.
4222    #[arg(
4223        long,
4224        short,
4225        env = EnvVars::UV_PYTHON,
4226        verbatim_doc_comment,
4227        help_heading = "Python options",
4228        value_parser = parse_maybe_string,
4229        value_hint = ValueHint::Other,
4230    )]
4231    pub python: Option<Maybe<String>>,
4232}
4233
4234#[derive(Args)]
4235#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
4236pub struct AddArgs {
4237    /// The packages to add, as PEP 508 requirements (e.g., `ruff==0.5.0`).
4238    #[arg(group = "sources", value_hint = ValueHint::Other)]
4239    pub packages: Vec<String>,
4240
4241    /// Add the packages listed in the given files.
4242    ///
4243    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
4244    /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
4245    #[arg(
4246        long,
4247        short,
4248        alias = "requirement",
4249        group = "sources",
4250        value_parser = parse_file_path,
4251        value_hint = ValueHint::FilePath,
4252    )]
4253    pub requirements: Vec<PathBuf>,
4254
4255    /// Constrain versions using the given requirements files.
4256    ///
4257    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
4258    /// requirement that's installed. The constraints will _not_ be added to the project's
4259    /// `pyproject.toml` file, but _will_ be respected during dependency resolution.
4260    ///
4261    /// This is equivalent to pip's `--constraint` option.
4262    #[arg(
4263        long,
4264        short,
4265        alias = "constraint",
4266        env = EnvVars::UV_CONSTRAINT,
4267        value_delimiter = ' ',
4268        value_parser = parse_maybe_file_path,
4269        value_hint = ValueHint::FilePath,
4270    )]
4271    pub constraints: Vec<Maybe<PathBuf>>,
4272
4273    /// Apply this marker to all added packages.
4274    #[arg(long, short, value_parser = MarkerTree::from_str, value_hint = ValueHint::Other)]
4275    pub marker: Option<MarkerTree>,
4276
4277    /// Add the requirements to the development dependency group [env: UV_DEV=]
4278    ///
4279    /// This option is an alias for `--group dev`.
4280    #[arg(
4281        long,
4282        conflicts_with("optional"),
4283        conflicts_with("group"),
4284        conflicts_with("script"),
4285        value_parser = clap::builder::BoolishValueParser::new()
4286    )]
4287    pub dev: bool,
4288
4289    /// Add the requirements to the package's optional dependencies for the specified extra.
4290    ///
4291    /// The group may then be activated when installing the project with the `--extra` flag.
4292    ///
4293    /// To enable an optional extra for this requirement instead, see `--extra`.
4294    #[arg(long, conflicts_with("dev"), conflicts_with("group"), value_hint = ValueHint::Other)]
4295    pub optional: Option<ExtraName>,
4296
4297    /// Add the requirements to the specified dependency group.
4298    ///
4299    /// These requirements will not be included in the published metadata for the project.
4300    #[arg(
4301        long,
4302        conflicts_with("dev"),
4303        conflicts_with("optional"),
4304        conflicts_with("script"),
4305        value_hint = ValueHint::Other,
4306    )]
4307    pub group: Option<GroupName>,
4308
4309    /// Add the requirements as editable.
4310    #[arg(long, overrides_with = "no_editable")]
4311    pub editable: bool,
4312
4313    /// Don't add the requirements as editable [env: UV_NO_EDITABLE=]
4314    #[arg(long, overrides_with = "editable", hide = true, value_parser = clap::builder::BoolishValueParser::new())]
4315    pub no_editable: bool,
4316
4317    /// Add a dependency as provided.
4318    ///
4319    /// By default, uv will use the `tool.uv.sources` section to record source information for Git,
4320    /// local, editable, and direct URL requirements. When `--raw` is provided, uv will add source
4321    /// requirements to `project.dependencies`, rather than `tool.uv.sources`.
4322    ///
4323    /// Additionally, by default, uv will add bounds to your dependency, e.g., `foo>=1.0.0`. When
4324    /// `--raw` is provided, uv will add the dependency without bounds.
4325    #[arg(
4326        long,
4327        conflicts_with = "editable",
4328        conflicts_with = "no_editable",
4329        conflicts_with = "rev",
4330        conflicts_with = "tag",
4331        conflicts_with = "branch",
4332        alias = "raw-sources"
4333    )]
4334    pub raw: bool,
4335
4336    /// The kind of version specifier to use when adding dependencies.
4337    ///
4338    /// When adding a dependency to the project, if no constraint or URL is provided, a constraint
4339    /// is added based on the latest compatible version of the package. By default, a lower bound
4340    /// constraint is used, e.g., `>=1.2.3`.
4341    ///
4342    /// When `--frozen` is provided, no resolution is performed, and dependencies are always added
4343    /// without constraints.
4344    ///
4345    /// This option is in preview and may change in any future release.
4346    #[arg(long, value_enum)]
4347    pub bounds: Option<AddBoundsKind>,
4348
4349    /// Commit to use when adding a dependency from Git.
4350    #[arg(long, group = "git-ref", action = clap::ArgAction::Set, value_hint = ValueHint::Other)]
4351    pub rev: Option<String>,
4352
4353    /// Tag to use when adding a dependency from Git.
4354    #[arg(long, group = "git-ref", action = clap::ArgAction::Set, value_hint = ValueHint::Other)]
4355    pub tag: Option<String>,
4356
4357    /// Branch to use when adding a dependency from Git.
4358    #[arg(long, group = "git-ref", action = clap::ArgAction::Set, value_hint = ValueHint::Other)]
4359    pub branch: Option<String>,
4360
4361    /// Whether to use Git LFS when adding a dependency from Git.
4362    #[arg(long)]
4363    pub lfs: bool,
4364
4365    /// Extras to enable for the dependency.
4366    ///
4367    /// May be provided more than once.
4368    ///
4369    /// To add this dependency to an optional extra instead, see `--optional`.
4370    #[arg(long, value_hint = ValueHint::Other)]
4371    pub extra: Option<Vec<ExtraName>>,
4372
4373    /// Avoid syncing the virtual environment [env: UV_NO_SYNC=]
4374    #[arg(long)]
4375    pub no_sync: bool,
4376
4377    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
4378    ///
4379    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4380    /// uv will exit with an error.
4381    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
4382    pub locked: bool,
4383
4384    /// Add dependencies without re-locking the project [env: UV_FROZEN=]
4385    ///
4386    /// The project environment will not be synced.
4387    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4388    pub frozen: bool,
4389
4390    /// Prefer the active virtual environment over the project's virtual environment.
4391    ///
4392    /// If the project virtual environment is active or no virtual environment is active, this has
4393    /// no effect.
4394    #[arg(long, overrides_with = "no_active")]
4395    pub active: bool,
4396
4397    /// Prefer project's virtual environment over an active environment.
4398    ///
4399    /// This is the default behavior.
4400    #[arg(long, overrides_with = "active", hide = true)]
4401    pub no_active: bool,
4402
4403    #[command(flatten)]
4404    pub installer: ResolverInstallerArgs,
4405
4406    #[command(flatten)]
4407    pub build: BuildOptionsArgs,
4408
4409    #[command(flatten)]
4410    pub refresh: RefreshArgs,
4411
4412    /// Add the dependency to a specific package in the workspace.
4413    #[arg(long, conflicts_with = "isolated", value_hint = ValueHint::Other)]
4414    pub package: Option<PackageName>,
4415
4416    /// Add the dependency to the specified Python script, rather than to a project.
4417    ///
4418    /// If provided, uv will add the dependency to the script's inline metadata table, in adherence
4419    /// with PEP 723. If no such inline metadata table is present, a new one will be created and
4420    /// added to the script. When executed via `uv run`, uv will create a temporary environment for
4421    /// the script with all inline dependencies installed.
4422    #[arg(
4423        long,
4424        conflicts_with = "dev",
4425        conflicts_with = "optional",
4426        conflicts_with = "package",
4427        conflicts_with = "workspace",
4428        value_hint = ValueHint::FilePath,
4429    )]
4430    pub script: Option<PathBuf>,
4431
4432    /// The Python interpreter to use for resolving and syncing.
4433    ///
4434    /// See `uv help python` for details on Python discovery and supported request formats.
4435    #[arg(
4436        long,
4437        short,
4438        env = EnvVars::UV_PYTHON,
4439        verbatim_doc_comment,
4440        help_heading = "Python options",
4441        value_parser = parse_maybe_string,
4442        value_hint = ValueHint::Other,
4443    )]
4444    pub python: Option<Maybe<String>>,
4445
4446    /// Add the dependency as a workspace member.
4447    ///
4448    /// By default, uv will add path dependencies that are within the workspace directory
4449    /// as workspace members. When used with a path dependency, the package will be added
4450    /// to the workspace's `members` list in the root `pyproject.toml` file.
4451    #[arg(long, overrides_with = "no_workspace")]
4452    pub workspace: bool,
4453
4454    /// Don't add the dependency as a workspace member.
4455    ///
4456    /// By default, when adding a dependency that's a local path and is within the workspace
4457    /// directory, uv will add it as a workspace member; pass `--no-workspace` to add the package
4458    /// as direct path dependency instead.
4459    #[arg(long, overrides_with = "workspace")]
4460    pub no_workspace: bool,
4461
4462    /// Do not install the current project.
4463    ///
4464    /// By default, the current project is installed into the environment with all of its
4465    /// dependencies. The `--no-install-project` option allows the project to be excluded, but all of
4466    /// its dependencies are still installed. This is particularly useful in situations like building
4467    /// Docker images where installing the project separately from its dependencies allows optimal
4468    /// layer caching.
4469    ///
4470    /// The inverse `--only-install-project` can be used to install _only_ the project itself,
4471    /// excluding all dependencies.
4472    #[arg(
4473        long,
4474        conflicts_with = "frozen",
4475        conflicts_with = "no_sync",
4476        conflicts_with = "only_install_project"
4477    )]
4478    pub no_install_project: bool,
4479
4480    /// Only install the current project.
4481    #[arg(
4482        long,
4483        conflicts_with = "frozen",
4484        conflicts_with = "no_sync",
4485        conflicts_with = "no_install_project",
4486        hide = true
4487    )]
4488    pub only_install_project: bool,
4489
4490    /// Do not install any workspace members, including the current project.
4491    ///
4492    /// By default, all workspace members and their dependencies are installed into the
4493    /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
4494    /// members while retaining their dependencies. This is particularly useful in situations like
4495    /// building Docker images where installing the workspace separately from its dependencies
4496    /// allows optimal layer caching.
4497    ///
4498    /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
4499    /// excluding all other dependencies.
4500    #[arg(
4501        long,
4502        conflicts_with = "frozen",
4503        conflicts_with = "no_sync",
4504        conflicts_with = "only_install_workspace"
4505    )]
4506    pub no_install_workspace: bool,
4507
4508    /// Only install workspace members, including the current project.
4509    #[arg(
4510        long,
4511        conflicts_with = "frozen",
4512        conflicts_with = "no_sync",
4513        conflicts_with = "no_install_workspace",
4514        hide = true
4515    )]
4516    pub only_install_workspace: bool,
4517
4518    /// Do not install local path dependencies
4519    ///
4520    /// Skips the current project, workspace members, and any other local (path or editable)
4521    /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
4522    /// heavy third-party dependencies first and layer local packages separately.
4523    ///
4524    /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
4525    /// all remote dependencies.
4526    #[arg(
4527        long,
4528        conflicts_with = "frozen",
4529        conflicts_with = "no_sync",
4530        conflicts_with = "only_install_local"
4531    )]
4532    pub no_install_local: bool,
4533
4534    /// Only install local path dependencies
4535    #[arg(
4536        long,
4537        conflicts_with = "frozen",
4538        conflicts_with = "no_sync",
4539        conflicts_with = "no_install_local",
4540        hide = true
4541    )]
4542    pub only_install_local: bool,
4543
4544    /// Do not install the given package(s).
4545    ///
4546    /// By default, all project's dependencies are installed into the environment. The
4547    /// `--no-install-package` option allows exclusion of specific packages. Note this can result
4548    /// in a broken environment, and should be used with caution.
4549    ///
4550    /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
4551    /// excluding all others.
4552    #[arg(
4553        long,
4554        conflicts_with = "frozen",
4555        conflicts_with = "no_sync",
4556        conflicts_with = "only_install_package",
4557        value_hint = ValueHint::Other,
4558    )]
4559    pub no_install_package: Vec<PackageName>,
4560
4561    /// Only install the given package(s).
4562    #[arg(
4563        long,
4564        conflicts_with = "frozen",
4565        conflicts_with = "no_sync",
4566        conflicts_with = "no_install_package",
4567        hide = true,
4568        value_hint = ValueHint::Other,
4569    )]
4570    pub only_install_package: Vec<PackageName>,
4571}
4572
4573#[derive(Args)]
4574pub struct RemoveArgs {
4575    /// The names of the dependencies to remove (e.g., `ruff`).
4576    #[arg(required = true, value_hint = ValueHint::Other)]
4577    pub packages: Vec<Requirement<VerbatimParsedUrl>>,
4578
4579    /// Remove the packages from the development dependency group [env: UV_DEV=]
4580    ///
4581    /// This option is an alias for `--group dev`.
4582    #[arg(long, conflicts_with("optional"), conflicts_with("group"), value_parser = clap::builder::BoolishValueParser::new())]
4583    pub dev: bool,
4584
4585    /// Remove the packages from the project's optional dependencies for the specified extra.
4586    #[arg(
4587        long,
4588        conflicts_with("dev"),
4589        conflicts_with("group"),
4590        conflicts_with("script"),
4591        value_hint = ValueHint::Other,
4592    )]
4593    pub optional: Option<ExtraName>,
4594
4595    /// Remove the packages from the specified dependency group.
4596    #[arg(
4597        long,
4598        conflicts_with("dev"),
4599        conflicts_with("optional"),
4600        conflicts_with("script"),
4601        value_hint = ValueHint::Other,
4602    )]
4603    pub group: Option<GroupName>,
4604
4605    /// Avoid syncing the virtual environment after re-locking the project [env: UV_NO_SYNC=]
4606    #[arg(long)]
4607    pub no_sync: bool,
4608
4609    /// Prefer the active virtual environment over the project's virtual environment.
4610    ///
4611    /// If the project virtual environment is active or no virtual environment is active, this has
4612    /// no effect.
4613    #[arg(long, overrides_with = "no_active")]
4614    pub active: bool,
4615
4616    /// Prefer project's virtual environment over an active environment.
4617    ///
4618    /// This is the default behavior.
4619    #[arg(long, overrides_with = "active", hide = true)]
4620    pub no_active: bool,
4621
4622    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
4623    ///
4624    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4625    /// uv will exit with an error.
4626    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
4627    pub locked: bool,
4628
4629    /// Remove dependencies without re-locking the project [env: UV_FROZEN=]
4630    ///
4631    /// The project environment will not be synced.
4632    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4633    pub frozen: bool,
4634
4635    #[command(flatten)]
4636    pub installer: ResolverInstallerArgs,
4637
4638    #[command(flatten)]
4639    pub build: BuildOptionsArgs,
4640
4641    #[command(flatten)]
4642    pub refresh: RefreshArgs,
4643
4644    /// Remove the dependencies from a specific package in the workspace.
4645    #[arg(long, conflicts_with = "isolated", value_hint = ValueHint::Other)]
4646    pub package: Option<PackageName>,
4647
4648    /// Remove the dependency from the specified Python script, rather than from a project.
4649    ///
4650    /// If provided, uv will remove the dependency from the script's inline metadata table, in
4651    /// adherence with PEP 723.
4652    #[arg(long, value_hint = ValueHint::FilePath)]
4653    pub script: Option<PathBuf>,
4654
4655    /// The Python interpreter to use for resolving and syncing.
4656    ///
4657    /// See `uv help python` for details on Python discovery and supported request formats.
4658    #[arg(
4659        long,
4660        short,
4661        env = EnvVars::UV_PYTHON,
4662        verbatim_doc_comment,
4663        help_heading = "Python options",
4664        value_parser = parse_maybe_string,
4665        value_hint = ValueHint::Other,
4666    )]
4667    pub python: Option<Maybe<String>>,
4668}
4669
4670#[derive(Args)]
4671pub struct TreeArgs {
4672    /// Show a platform-independent dependency tree.
4673    ///
4674    /// Shows resolved package versions for all Python versions and platforms, rather than filtering
4675    /// to those that are relevant for the current environment.
4676    ///
4677    /// Multiple versions may be shown for a each package.
4678    #[arg(long)]
4679    pub universal: bool,
4680
4681    #[command(flatten)]
4682    pub tree: DisplayTreeArgs,
4683
4684    /// Include the development dependency group [env: UV_DEV=]
4685    ///
4686    /// Development dependencies are defined via `dependency-groups.dev` or
4687    /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
4688    ///
4689    /// This option is an alias for `--group dev`.
4690    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
4691    pub dev: bool,
4692
4693    /// Only include the development dependency group.
4694    ///
4695    /// The project and its dependencies will be omitted.
4696    ///
4697    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
4698    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
4699    pub only_dev: bool,
4700
4701    /// Disable the development dependency group [env: UV_NO_DEV=]
4702    ///
4703    /// This option is an alias of `--no-group dev`.
4704    /// See `--no-default-groups` to disable all default groups instead.
4705    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
4706    pub no_dev: bool,
4707
4708    /// Include dependencies from the specified dependency group.
4709    ///
4710    /// May be provided multiple times.
4711    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4712    pub group: Vec<GroupName>,
4713
4714    /// Disable the specified dependency group.
4715    ///
4716    /// This option always takes precedence over default groups,
4717    /// `--all-groups`, and `--group`.
4718    ///
4719    /// May be provided multiple times.
4720    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
4721    pub no_group: Vec<GroupName>,
4722
4723    /// Ignore the default dependency groups.
4724    ///
4725    /// uv includes the groups defined in `tool.uv.default-groups` by default.
4726    /// This disables that option, however, specific groups can still be included with `--group`.
4727    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
4728    pub no_default_groups: bool,
4729
4730    /// Only include dependencies from the specified dependency group.
4731    ///
4732    /// The project and its dependencies will be omitted.
4733    ///
4734    /// May be provided multiple times. Implies `--no-default-groups`.
4735    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
4736    pub only_group: Vec<GroupName>,
4737
4738    /// Include dependencies from all dependency groups.
4739    ///
4740    /// `--no-group` can be used to exclude specific groups.
4741    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4742    pub all_groups: bool,
4743
4744    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
4745    ///
4746    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4747    /// uv will exit with an error.
4748    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
4749    pub locked: bool,
4750
4751    /// Display the requirements without locking the project [env: UV_FROZEN=]
4752    ///
4753    /// If the lockfile is missing, uv will exit with an error.
4754    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4755    pub frozen: bool,
4756
4757    #[command(flatten)]
4758    pub build: BuildOptionsArgs,
4759
4760    #[command(flatten)]
4761    pub resolver: ResolverArgs,
4762
4763    /// Show the dependency tree the specified PEP 723 Python script, rather than the current
4764    /// project.
4765    ///
4766    /// If provided, uv will resolve the dependencies based on its inline metadata table, in
4767    /// adherence with PEP 723.
4768    #[arg(long, value_hint = ValueHint::FilePath)]
4769    pub script: Option<PathBuf>,
4770
4771    /// The Python version to use when filtering the tree.
4772    ///
4773    /// For example, pass `--python-version 3.10` to display the dependencies that would be included
4774    /// when installing on Python 3.10.
4775    ///
4776    /// Defaults to the version of the discovered Python interpreter.
4777    #[arg(long, conflicts_with = "universal")]
4778    pub python_version: Option<PythonVersion>,
4779
4780    /// The platform to use when filtering the tree.
4781    ///
4782    /// For example, pass `--platform windows` to display the dependencies that would be included
4783    /// when installing on Windows.
4784    ///
4785    /// Represented as a "target triple", a string that describes the target platform in terms of
4786    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
4787    /// `aarch64-apple-darwin`.
4788    #[arg(long, conflicts_with = "universal")]
4789    pub python_platform: Option<TargetTriple>,
4790
4791    /// The Python interpreter to use for locking and filtering.
4792    ///
4793    /// By default, the tree is filtered to match the platform as reported by the Python
4794    /// interpreter. Use `--universal` to display the tree for all platforms, or use
4795    /// `--python-version` or `--python-platform` to override a subset of markers.
4796    ///
4797    /// See `uv help python` for details on Python discovery and supported request formats.
4798    #[arg(
4799        long,
4800        short,
4801        env = EnvVars::UV_PYTHON,
4802        verbatim_doc_comment,
4803        help_heading = "Python options",
4804        value_parser = parse_maybe_string,
4805        value_hint = ValueHint::Other,
4806    )]
4807    pub python: Option<Maybe<String>>,
4808}
4809
4810#[derive(Args)]
4811pub struct ExportArgs {
4812    /// The format to which `uv.lock` should be exported.
4813    ///
4814    /// Supports `requirements.txt`, `pylock.toml` (PEP 751) and CycloneDX v1.5 JSON output formats.
4815    ///
4816    /// uv will infer the output format from the file extension of the output file, if
4817    /// provided. Otherwise, defaults to `requirements.txt`.
4818    #[arg(long, value_enum)]
4819    pub format: Option<ExportFormat>,
4820
4821    /// Export the entire workspace.
4822    ///
4823    /// The dependencies for all workspace members will be included in the exported requirements
4824    /// file.
4825    ///
4826    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
4827    /// to all workspace members.
4828    #[arg(long, conflicts_with = "package")]
4829    pub all_packages: bool,
4830
4831    /// Export the dependencies for specific packages in the workspace.
4832    ///
4833    /// If any workspace member does not exist, uv will exit with an error.
4834    #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
4835    pub package: Vec<PackageName>,
4836
4837    /// Prune the given package from the dependency tree.
4838    ///
4839    /// Pruned packages will be excluded from the exported requirements file, as will any
4840    /// dependencies that are no longer required after the pruned package is removed.
4841    #[arg(long, conflicts_with = "all_packages", value_name = "PACKAGE")]
4842    pub prune: Vec<PackageName>,
4843
4844    /// Include optional dependencies from the specified extra name.
4845    ///
4846    /// May be provided more than once.
4847    #[arg(long, value_delimiter = ',', conflicts_with = "all_extras", conflicts_with = "only_group", value_parser = extra_name_with_clap_error)]
4848    pub extra: Option<Vec<ExtraName>>,
4849
4850    /// Include all optional dependencies.
4851    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
4852    pub all_extras: bool,
4853
4854    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
4855    ///
4856    /// May be provided multiple times.
4857    #[arg(long)]
4858    pub no_extra: Vec<ExtraName>,
4859
4860    #[arg(long, overrides_with("all_extras"), hide = true)]
4861    pub no_all_extras: bool,
4862
4863    /// Include the development dependency group [env: UV_DEV=]
4864    ///
4865    /// This option is an alias for `--group dev`.
4866    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
4867    pub dev: bool,
4868
4869    /// Disable the development dependency group [env: UV_NO_DEV=]
4870    ///
4871    /// This option is an alias of `--no-group dev`.
4872    /// See `--no-default-groups` to disable all default groups instead.
4873    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
4874    pub no_dev: bool,
4875
4876    /// Only include the development dependency group.
4877    ///
4878    /// The project and its dependencies will be omitted.
4879    ///
4880    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
4881    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
4882    pub only_dev: bool,
4883
4884    /// Include dependencies from the specified dependency group.
4885    ///
4886    /// May be provided multiple times.
4887    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4888    pub group: Vec<GroupName>,
4889
4890    /// Disable the specified dependency group.
4891    ///
4892    /// This option always takes precedence over default groups,
4893    /// `--all-groups`, and `--group`.
4894    ///
4895    /// May be provided multiple times.
4896    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
4897    pub no_group: Vec<GroupName>,
4898
4899    /// Ignore the default dependency groups.
4900    ///
4901    /// uv includes the groups defined in `tool.uv.default-groups` by default.
4902    /// This disables that option, however, specific groups can still be included with `--group`.
4903    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
4904    pub no_default_groups: bool,
4905
4906    /// Only include dependencies from the specified dependency group.
4907    ///
4908    /// The project and its dependencies will be omitted.
4909    ///
4910    /// May be provided multiple times. Implies `--no-default-groups`.
4911    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
4912    pub only_group: Vec<GroupName>,
4913
4914    /// Include dependencies from all dependency groups.
4915    ///
4916    /// `--no-group` can be used to exclude specific groups.
4917    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4918    pub all_groups: bool,
4919
4920    /// Exclude comment annotations indicating the source of each package.
4921    #[arg(long, overrides_with("annotate"))]
4922    pub no_annotate: bool,
4923
4924    #[arg(long, overrides_with("no_annotate"), hide = true)]
4925    pub annotate: bool,
4926
4927    /// Exclude the comment header at the top of the generated output file.
4928    #[arg(long, overrides_with("header"))]
4929    pub no_header: bool,
4930
4931    #[arg(long, overrides_with("no_header"), hide = true)]
4932    pub header: bool,
4933
4934    /// Export any non-editable dependencies, including the project and any workspace members, as
4935    /// editable.
4936    #[arg(long, overrides_with = "no_editable", hide = true)]
4937    pub editable: bool,
4938
4939    /// Export any editable dependencies, including the project and any workspace members, as
4940    /// non-editable [env: UV_NO_EDITABLE=]
4941    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new())]
4942    pub no_editable: bool,
4943
4944    /// Include hashes for all dependencies.
4945    #[arg(long, overrides_with("no_hashes"), hide = true)]
4946    pub hashes: bool,
4947
4948    /// Omit hashes in the generated output.
4949    #[arg(long, overrides_with("hashes"))]
4950    pub no_hashes: bool,
4951
4952    /// Write the exported requirements to the given file.
4953    #[arg(long, short, value_hint = ValueHint::FilePath)]
4954    pub output_file: Option<PathBuf>,
4955
4956    /// Do not emit the current project.
4957    ///
4958    /// By default, the current project is included in the exported requirements file with all of
4959    /// its dependencies. The `--no-emit-project` option allows the project to be excluded, but all
4960    /// of its dependencies to remain included.
4961    ///
4962    /// The inverse `--only-emit-project` can be used to emit _only_ the project itself, excluding
4963    /// all dependencies.
4964    #[arg(
4965        long,
4966        alias = "no-install-project",
4967        conflicts_with = "only_emit_project"
4968    )]
4969    pub no_emit_project: bool,
4970
4971    /// Only emit the current project.
4972    #[arg(
4973        long,
4974        alias = "only-install-project",
4975        conflicts_with = "no_emit_project",
4976        hide = true
4977    )]
4978    pub only_emit_project: bool,
4979
4980    /// Do not emit any workspace members, including the root project.
4981    ///
4982    /// By default, all workspace members and their dependencies are included in the exported
4983    /// requirements file, with all of their dependencies. The `--no-emit-workspace` option allows
4984    /// exclusion of all the workspace members while retaining their dependencies.
4985    ///
4986    /// The inverse `--only-emit-workspace` can be used to emit _only_ workspace members, excluding
4987    /// all other dependencies.
4988    #[arg(
4989        long,
4990        alias = "no-install-workspace",
4991        conflicts_with = "only_emit_workspace"
4992    )]
4993    pub no_emit_workspace: bool,
4994
4995    /// Only emit workspace members, including the root project.
4996    #[arg(
4997        long,
4998        alias = "only-install-workspace",
4999        conflicts_with = "no_emit_workspace",
5000        hide = true
5001    )]
5002    pub only_emit_workspace: bool,
5003
5004    /// Do not include local path dependencies in the exported requirements.
5005    ///
5006    /// Omits the current project, workspace members, and any other local (path or editable)
5007    /// packages from the export. Only remote/indexed dependencies are written. Useful for Docker
5008    /// and CI flows that want to export and cache third-party dependencies first.
5009    ///
5010    /// The inverse `--only-emit-local` can be used to emit _only_ local packages, excluding all
5011    /// remote dependencies.
5012    #[arg(long, alias = "no-install-local", conflicts_with = "only_emit_local")]
5013    pub no_emit_local: bool,
5014
5015    /// Only include local path dependencies in the exported requirements.
5016    #[arg(
5017        long,
5018        alias = "only-install-local",
5019        conflicts_with = "no_emit_local",
5020        hide = true
5021    )]
5022    pub only_emit_local: bool,
5023
5024    /// Do not emit the given package(s).
5025    ///
5026    /// By default, all project's dependencies are included in the exported requirements
5027    /// file. The `--no-emit-package` option allows exclusion of specific packages.
5028    ///
5029    /// The inverse `--only-emit-package` can be used to emit _only_ the specified packages,
5030    /// excluding all others.
5031    #[arg(
5032        long,
5033        alias = "no-install-package",
5034        conflicts_with = "only_emit_package",
5035        value_delimiter = ',',
5036        value_hint = ValueHint::Other,
5037    )]
5038    pub no_emit_package: Vec<PackageName>,
5039
5040    /// Only emit the given package(s).
5041    #[arg(
5042        long,
5043        alias = "only-install-package",
5044        conflicts_with = "no_emit_package",
5045        hide = true,
5046        value_delimiter = ',',
5047        value_hint = ValueHint::Other,
5048    )]
5049    pub only_emit_package: Vec<PackageName>,
5050
5051    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
5052    ///
5053    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
5054    /// uv will exit with an error.
5055    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
5056    pub locked: bool,
5057
5058    /// Do not update the `uv.lock` before exporting [env: UV_FROZEN=]
5059    ///
5060    /// If a `uv.lock` does not exist, uv will exit with an error.
5061    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
5062    pub frozen: bool,
5063
5064    #[command(flatten)]
5065    pub resolver: ResolverArgs,
5066
5067    #[command(flatten)]
5068    pub build: BuildOptionsArgs,
5069
5070    #[command(flatten)]
5071    pub refresh: RefreshArgs,
5072
5073    /// Export the dependencies for the specified PEP 723 Python script, rather than the current
5074    /// project.
5075    ///
5076    /// If provided, uv will resolve the dependencies based on its inline metadata table, in
5077    /// adherence with PEP 723.
5078    #[arg(
5079        long,
5080        conflicts_with_all = ["all_packages", "package", "no_emit_project", "no_emit_workspace"],
5081        value_hint = ValueHint::FilePath,
5082    )]
5083    pub script: Option<PathBuf>,
5084
5085    /// The Python interpreter to use during resolution.
5086    ///
5087    /// A Python interpreter is required for building source distributions to determine package
5088    /// metadata when there are not wheels.
5089    ///
5090    /// The interpreter is also used as the fallback value for the minimum Python version if
5091    /// `requires-python` is not set.
5092    ///
5093    /// See `uv help python` for details on Python discovery and supported request formats.
5094    #[arg(
5095        long,
5096        short,
5097        env = EnvVars::UV_PYTHON,
5098        verbatim_doc_comment,
5099        help_heading = "Python options",
5100        value_parser = parse_maybe_string,
5101        value_hint = ValueHint::Other,
5102    )]
5103    pub python: Option<Maybe<String>>,
5104}
5105
5106#[derive(Args)]
5107pub struct FormatArgs {
5108    /// Check if files are formatted without applying changes.
5109    #[arg(long)]
5110    pub check: bool,
5111
5112    /// Show a diff of formatting changes without applying them.
5113    ///
5114    /// Implies `--check`.
5115    #[arg(long)]
5116    pub diff: bool,
5117
5118    /// The version of Ruff to use for formatting.
5119    ///
5120    /// Accepts either a version (e.g., `0.8.2`) which will be treated as an exact pin,
5121    /// a version specifier (e.g., `>=0.8.0`), or `latest` to use the latest available version.
5122    ///
5123    /// By default, a constrained version range of Ruff will be used (e.g., `>=0.15,<0.16`).
5124    #[arg(long, value_hint = ValueHint::Other)]
5125    pub version: Option<String>,
5126
5127    /// Limit candidate Ruff versions to those released prior to the given date.
5128    ///
5129    /// Accepts a superset of [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html) (e.g.,
5130    /// `2006-12-02T02:07:43Z`) or local date in the same format (e.g. `2006-12-02`), as well as
5131    /// durations relative to "now" (e.g., `-1 week`).
5132    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER)]
5133    pub exclude_newer: Option<ExcludeNewerValue>,
5134
5135    /// Additional arguments to pass to Ruff.
5136    ///
5137    /// For example, use `uv format -- --line-length 100` to set the line length or
5138    /// `uv format -- src/module/foo.py` to format a specific file.
5139    #[arg(last = true, value_hint = ValueHint::Other)]
5140    pub extra_args: Vec<String>,
5141
5142    /// Avoid discovering a project or workspace.
5143    ///
5144    /// Instead of running the formatter in the context of the current project, run it in the
5145    /// context of the current directory. This is useful when the current directory is not a
5146    /// project.
5147    #[arg(
5148        long,
5149        env = EnvVars::UV_NO_PROJECT,
5150        value_parser = clap::builder::BoolishValueParser::new()
5151    )]
5152    pub no_project: bool,
5153
5154    /// Display the version of Ruff that will be used for formatting.
5155    ///
5156    /// This is useful for verifying which version was resolved when using version constraints
5157    /// (e.g., `--version ">=0.8.0"`) or `--version latest`.
5158    #[arg(long, hide = true)]
5159    pub show_version: bool,
5160}
5161
5162#[derive(Args)]
5163pub struct AuditArgs {
5164    /// Don't audit the specified optional dependencies.
5165    ///
5166    /// May be provided multiple times.
5167    #[arg(long, value_hint = ValueHint::Other)]
5168    pub no_extra: Vec<ExtraName>,
5169
5170    /// Don't audit the development dependency group [env: UV_NO_DEV=]
5171    ///
5172    /// This option is an alias of `--no-group dev`.
5173    /// See `--no-default-groups` to exclude all default groups instead.
5174    ///
5175    /// This option is only available when running in a project.
5176    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5177    pub no_dev: bool,
5178
5179    /// Don't audit the specified dependency group.
5180    ///
5181    /// May be provided multiple times.
5182    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ', value_hint = ValueHint::Other)]
5183    pub no_group: Vec<GroupName>,
5184
5185    /// Don't audit the default dependency groups.
5186    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
5187    pub no_default_groups: bool,
5188
5189    /// Only audit dependencies from the specified dependency group.
5190    ///
5191    /// The project and its dependencies will be omitted.
5192    ///
5193    /// May be provided multiple times. Implies `--no-default-groups`.
5194    #[arg(long, value_hint = ValueHint::Other)]
5195    pub only_group: Vec<GroupName>,
5196
5197    /// Only audit the development dependency group.
5198    ///
5199    /// The project and its dependencies will be omitted.
5200    ///
5201    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
5202    #[arg(long, conflicts_with_all = ["no_dev"])]
5203    pub only_dev: bool,
5204
5205    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
5206    ///
5207    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
5208    /// uv will exit with an error.
5209    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
5210    pub locked: bool,
5211
5212    /// Audit the requirements without locking the project [env: UV_FROZEN=]
5213    ///
5214    /// If the lockfile is missing, uv will exit with an error.
5215    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
5216    pub frozen: bool,
5217
5218    #[command(flatten)]
5219    pub build: BuildOptionsArgs,
5220
5221    #[command(flatten)]
5222    pub resolver: ResolverArgs,
5223
5224    /// Audit the specified PEP 723 Python script, rather than the current
5225    /// project.
5226    ///
5227    /// The specified script must be locked, i.e. with `uv lock --script <script>`
5228    /// before it can be audited.
5229    #[arg(long, value_hint = ValueHint::FilePath)]
5230    pub script: Option<PathBuf>,
5231
5232    /// The Python version to use when auditing.
5233    ///
5234    /// For example, pass `--python-version 3.10` to audit the dependencies that would be included
5235    /// when installing on Python 3.10.
5236    ///
5237    /// Defaults to the version of the discovered Python interpreter.
5238    #[arg(long)]
5239    pub python_version: Option<PythonVersion>,
5240
5241    /// The platform to use when auditing.
5242    ///
5243    /// For example, pass `--platform windows` to audit the dependencies that would be included
5244    /// when installing on Windows.
5245    ///
5246    /// Represented as a "target triple", a string that describes the target platform in terms of
5247    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5248    /// `aarch64-apple-darwin`.
5249    #[arg(long)]
5250    pub python_platform: Option<TargetTriple>,
5251
5252    /// Ignore a vulnerability by ID.
5253    ///
5254    /// Vulnerabilities matching any of the provided IDs (including aliases) will be excluded from
5255    /// the audit results.
5256    ///
5257    /// May be provided multiple times.
5258    #[arg(long)]
5259    pub ignore: Vec<String>,
5260
5261    /// Ignore a vulnerability by ID, but only while no fix is available.
5262    ///
5263    /// Vulnerabilities matching any of the provided IDs (including aliases) will be excluded from
5264    /// the audit results as long as they have no known fix versions. Once a fix version becomes
5265    /// available, the vulnerability will be reported again.
5266    ///
5267    /// May be provided multiple times.
5268    #[arg(long)]
5269    pub ignore_until_fixed: Vec<String>,
5270
5271    /// The service format to use for vulnerability lookups.
5272    ///
5273    /// Each service format has a default URL, which can be
5274    /// changed with `--service-url`. The defaults are:
5275    ///
5276    /// * OSV: <https://api.osv.dev/>
5277    #[arg(long, value_enum, default_value = "osv")]
5278    pub service_format: VulnerabilityServiceFormat,
5279
5280    /// The URL to vulnerability service API endpoint.
5281    ///
5282    /// If not provided, the default URL for the selected service will be used.
5283    ///
5284    /// The service needs to use the OSV protocol, unless a different
5285    /// format was requested by `--service-format`.
5286    #[arg(long, value_hint = ValueHint::Url)]
5287    pub service_url: Option<String>,
5288}
5289
5290#[derive(Args)]
5291pub struct AuthNamespace {
5292    #[command(subcommand)]
5293    pub command: AuthCommand,
5294}
5295
5296#[derive(Subcommand)]
5297pub enum AuthCommand {
5298    /// Login to a service
5299    Login(AuthLoginArgs),
5300    /// Logout of a service
5301    Logout(AuthLogoutArgs),
5302    /// Show the authentication token for a service
5303    Token(AuthTokenArgs),
5304    /// Show the path to the uv credentials directory.
5305    ///
5306    /// By default, credentials are stored in the uv data directory at
5307    /// `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and
5308    /// `%APPDATA%\uv\data\credentials` on Windows.
5309    ///
5310    /// The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`.
5311    ///
5312    /// Credentials are only stored in this directory when the plaintext backend is used, as
5313    /// opposed to the native backend, which uses the system keyring.
5314    Dir(AuthDirArgs),
5315    /// Act as a credential helper for external tools.
5316    ///
5317    /// Implements the Bazel credential helper protocol to provide credentials
5318    /// to external tools via JSON over stdin/stdout.
5319    ///
5320    /// This command is typically invoked by external tools.
5321    #[command(hide = true)]
5322    Helper(AuthHelperArgs),
5323}
5324
5325#[derive(Args)]
5326pub struct ToolNamespace {
5327    #[command(subcommand)]
5328    pub command: ToolCommand,
5329}
5330
5331#[derive(Subcommand)]
5332pub enum ToolCommand {
5333    /// Run a command provided by a Python package.
5334    ///
5335    /// By default, the package to install is assumed to match the command name.
5336    ///
5337    /// The name of the command can include an exact version in the format `<package>@<version>`,
5338    /// e.g., `uv tool run ruff@0.3.0`. If more complex version specification is desired or if the
5339    /// command is provided by a different package, use `--from`.
5340    ///
5341    /// `uvx` can be used to invoke Python, e.g., with `uvx python` or `uvx python@<version>`. A
5342    /// Python interpreter will be started in an isolated virtual environment.
5343    ///
5344    /// If the tool was previously installed, i.e., via `uv tool install`, the installed version
5345    /// will be used unless a version is requested or the `--isolated` flag is used.
5346    ///
5347    /// `uvx` is provided as a convenient alias for `uv tool run`, their behavior is identical.
5348    ///
5349    /// If no command is provided, the installed tools are displayed.
5350    ///
5351    /// Packages are installed into an ephemeral virtual environment in the uv cache directory.
5352    #[command(
5353        after_help = "Use `uvx` as a shortcut for `uv tool run`.\n\n\
5354        Use `uv help tool run` for more details.",
5355        after_long_help = ""
5356    )]
5357    Run(ToolRunArgs),
5358    /// Hidden alias for `uv tool run` for the `uvx` command
5359    #[command(
5360        hide = true,
5361        override_usage = "uvx [OPTIONS] [COMMAND]",
5362        about = "Run a command provided by a Python package.",
5363        after_help = "Use `uv help tool run` for more details.",
5364        after_long_help = "",
5365        display_name = "uvx",
5366        long_version = crate::version::uv_self_version()
5367    )]
5368    Uvx(UvxArgs),
5369    /// Install commands provided by a Python package.
5370    ///
5371    /// Packages are installed into an isolated virtual environment in the uv tools directory. The
5372    /// executables are linked the tool executable directory, which is determined according to the
5373    /// XDG standard and can be retrieved with `uv tool dir --bin`.
5374    ///
5375    /// If the tool was previously installed, the existing tool will generally be replaced.
5376    Install(ToolInstallArgs),
5377    /// Upgrade installed tools.
5378    ///
5379    /// If a tool was installed with version constraints, they will be respected on upgrade — to
5380    /// upgrade a tool beyond the originally provided constraints, use `uv tool install` again.
5381    ///
5382    /// If a tool was installed with specific settings, they will be respected on upgraded. For
5383    /// example, if `--prereleases allow` was provided during installation, it will continue to be
5384    /// respected in upgrades.
5385    #[command(alias = "update")]
5386    Upgrade(ToolUpgradeArgs),
5387    /// List installed tools.
5388    #[command(alias = "ls")]
5389    List(ToolListArgs),
5390    /// Uninstall a tool.
5391    Uninstall(ToolUninstallArgs),
5392    /// Ensure that the tool executable directory is on the `PATH`.
5393    ///
5394    /// If the tool executable directory is not present on the `PATH`, uv will attempt to add it to
5395    /// the relevant shell configuration files.
5396    ///
5397    /// If the shell configuration files already include a blurb to add the executable directory to
5398    /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5399    ///
5400    /// The tool executable directory is determined according to the XDG standard and can be
5401    /// retrieved with `uv tool dir --bin`.
5402    #[command(alias = "ensurepath")]
5403    UpdateShell,
5404    /// Show the path to the uv tools directory.
5405    ///
5406    /// The tools directory is used to store environments and metadata for installed tools.
5407    ///
5408    /// By default, tools are stored in the uv data directory at `$XDG_DATA_HOME/uv/tools` or
5409    /// `$HOME/.local/share/uv/tools` on Unix and `%APPDATA%\uv\data\tools` on Windows.
5410    ///
5411    /// The tool installation directory may be overridden with `$UV_TOOL_DIR`.
5412    ///
5413    /// To instead view the directory uv installs executables into, use the `--bin` flag.
5414    Dir(ToolDirArgs),
5415}
5416
5417#[derive(Args)]
5418pub struct ToolRunArgs {
5419    /// The command to run.
5420    ///
5421    /// WARNING: The documentation for [`Self::command`] is not included in help output
5422    #[command(subcommand)]
5423    pub command: Option<ExternalCommand>,
5424
5425    /// Use the given package to provide the command.
5426    ///
5427    /// By default, the package name is assumed to match the command name.
5428    #[arg(long, value_hint = ValueHint::Other)]
5429    pub from: Option<String>,
5430
5431    /// Run with the given packages installed.
5432    #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5433    pub with: Vec<comma::CommaSeparatedRequirements>,
5434
5435    /// Run with the given packages installed in editable mode
5436    ///
5437    /// When used in a project, these dependencies will be layered on top of the uv tool's
5438    /// environment in a separate, ephemeral environment. These dependencies are allowed to conflict
5439    /// with those specified.
5440    #[arg(long, value_hint = ValueHint::DirPath)]
5441    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5442
5443    /// Run with the packages listed in the given files.
5444    ///
5445    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5446    /// and `pylock.toml`.
5447    #[arg(
5448        long,
5449        value_delimiter = ',',
5450        value_parser = parse_maybe_file_path,
5451        value_hint = ValueHint::FilePath,
5452    )]
5453    pub with_requirements: Vec<Maybe<PathBuf>>,
5454
5455    /// Constrain versions using the given requirements files.
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    ///
5461    /// This is equivalent to pip's `--constraint` option.
5462    #[arg(
5463        long,
5464        short,
5465        alias = "constraint",
5466        env = EnvVars::UV_CONSTRAINT,
5467        value_delimiter = ' ',
5468        value_parser = parse_maybe_file_path,
5469        value_hint = ValueHint::FilePath,
5470    )]
5471    pub constraints: Vec<Maybe<PathBuf>>,
5472
5473    /// Constrain build dependencies using the given requirements files when building source
5474    /// distributions.
5475    ///
5476    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5477    /// requirement that's installed. However, including a package in a constraints file will _not_
5478    /// trigger the installation of that package.
5479    #[arg(
5480        long,
5481        short,
5482        alias = "build-constraint",
5483        env = EnvVars::UV_BUILD_CONSTRAINT,
5484        value_delimiter = ' ',
5485        value_parser = parse_maybe_file_path,
5486        value_hint = ValueHint::FilePath,
5487    )]
5488    pub build_constraints: Vec<Maybe<PathBuf>>,
5489
5490    /// Override versions using the given requirements files.
5491    ///
5492    /// Overrides files are `requirements.txt`-like files that force a specific version of a
5493    /// requirement to be installed, regardless of the requirements declared by any constituent
5494    /// package, and regardless of whether this would be considered an invalid resolution.
5495    ///
5496    /// While constraints are _additive_, in that they're combined with the requirements of the
5497    /// constituent packages, overrides are _absolute_, in that they completely replace the
5498    /// requirements of the constituent packages.
5499    #[arg(
5500        long,
5501        alias = "override",
5502        env = EnvVars::UV_OVERRIDE,
5503        value_delimiter = ' ',
5504        value_parser = parse_maybe_file_path,
5505        value_hint = ValueHint::FilePath,
5506    )]
5507    pub overrides: Vec<Maybe<PathBuf>>,
5508
5509    /// Run the tool in an isolated virtual environment, ignoring any already-installed tools [env:
5510    /// UV_ISOLATED=]
5511    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5512    pub isolated: bool,
5513
5514    /// Load environment variables from a `.env` file.
5515    ///
5516    /// Can be provided multiple times, with subsequent files overriding values defined in previous
5517    /// files.
5518    #[arg(long, value_delimiter = ' ', env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
5519    pub env_file: Vec<PathBuf>,
5520
5521    /// Avoid reading environment variables from a `.env` file [env: UV_NO_ENV_FILE=]
5522    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5523    pub no_env_file: bool,
5524
5525    #[command(flatten)]
5526    pub installer: ResolverInstallerArgs,
5527
5528    #[command(flatten)]
5529    pub build: BuildOptionsArgs,
5530
5531    #[command(flatten)]
5532    pub refresh: RefreshArgs,
5533
5534    /// Whether to use Git LFS when adding a dependency from Git.
5535    #[arg(long)]
5536    pub lfs: bool,
5537
5538    /// The Python interpreter to use to build the run environment.
5539    ///
5540    /// See `uv help python` for details on Python discovery and supported request formats.
5541    #[arg(
5542        long,
5543        short,
5544        env = EnvVars::UV_PYTHON,
5545        verbatim_doc_comment,
5546        help_heading = "Python options",
5547        value_parser = parse_maybe_string,
5548        value_hint = ValueHint::Other,
5549    )]
5550    pub python: Option<Maybe<String>>,
5551
5552    /// Whether to show resolver and installer output from any environment modifications [env:
5553    /// UV_SHOW_RESOLUTION=]
5554    ///
5555    /// By default, environment modifications are omitted, but enabled under `--verbose`.
5556    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
5557    pub show_resolution: bool,
5558
5559    /// The platform for which requirements should be installed.
5560    ///
5561    /// Represented as a "target triple", a string that describes the target platform in terms of
5562    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5563    /// `aarch64-apple-darwin`.
5564    ///
5565    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5566    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5567    ///
5568    /// When targeting iOS, the default minimum version is `13.0`. Use
5569    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5570    ///
5571    /// When targeting Android, the default minimum Android API level is `24`. Use
5572    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5573    ///
5574    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5575    /// platform; as a result, the installed distributions may not be compatible with the _current_
5576    /// platform. Conversely, any distributions that are built from source may be incompatible with
5577    /// the _target_ platform, as they will be built for the _current_ platform. The
5578    /// `--python-platform` option is intended for advanced use cases.
5579    #[arg(long)]
5580    pub python_platform: Option<TargetTriple>,
5581
5582    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5583    ///
5584    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5585    /// and will instead use the defined backend.
5586    ///
5587    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5588    /// uv will use the PyTorch index for CUDA 12.6.
5589    ///
5590    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5591    /// installed CUDA drivers.
5592    ///
5593    /// This option is in preview and may change in any future release.
5594    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5595    pub torch_backend: Option<TorchMode>,
5596
5597    #[arg(long, hide = true)]
5598    pub generate_shell_completion: Option<clap_complete_command::Shell>,
5599}
5600
5601#[derive(Args)]
5602pub struct UvxArgs {
5603    #[command(flatten)]
5604    pub tool_run: ToolRunArgs,
5605
5606    /// Display the uvx version.
5607    #[arg(short = 'V', long, action = clap::ArgAction::Version)]
5608    pub version: Option<bool>,
5609}
5610
5611#[derive(Args)]
5612pub struct ToolInstallArgs {
5613    /// The package to install commands from.
5614    #[arg(value_hint = ValueHint::Other)]
5615    pub package: String,
5616
5617    /// The package to install commands from.
5618    ///
5619    /// This option is provided for parity with `uv tool run`, but is redundant with `package`.
5620    #[arg(long, hide = true, value_hint = ValueHint::Other)]
5621    pub from: Option<String>,
5622
5623    /// Include the following additional requirements.
5624    #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5625    pub with: Vec<comma::CommaSeparatedRequirements>,
5626
5627    /// Run with the packages listed in the given files.
5628    ///
5629    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5630    /// and `pylock.toml`.
5631    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
5632    pub with_requirements: Vec<Maybe<PathBuf>>,
5633
5634    /// Install the target package in editable mode, such that changes in the package's source
5635    /// directory are reflected without reinstallation.
5636    #[arg(short, long)]
5637    pub editable: bool,
5638
5639    /// Include the given packages in editable mode.
5640    #[arg(long, value_hint = ValueHint::DirPath)]
5641    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5642
5643    /// Install executables from the following packages.
5644    #[arg(long, value_hint = ValueHint::Other)]
5645    pub with_executables_from: Vec<comma::CommaSeparatedRequirements>,
5646
5647    /// Constrain versions using the given requirements files.
5648    ///
5649    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5650    /// requirement that's installed. However, including a package in a constraints file will _not_
5651    /// trigger the installation of that package.
5652    ///
5653    /// This is equivalent to pip's `--constraint` option.
5654    #[arg(
5655        long,
5656        short,
5657        alias = "constraint",
5658        env = EnvVars::UV_CONSTRAINT,
5659        value_delimiter = ' ',
5660        value_parser = parse_maybe_file_path,
5661        value_hint = ValueHint::FilePath,
5662    )]
5663    pub constraints: Vec<Maybe<PathBuf>>,
5664
5665    /// Override versions using the given requirements files.
5666    ///
5667    /// Overrides files are `requirements.txt`-like files that force a specific version of a
5668    /// requirement to be installed, regardless of the requirements declared by any constituent
5669    /// package, and regardless of whether this would be considered an invalid resolution.
5670    ///
5671    /// While constraints are _additive_, in that they're combined with the requirements of the
5672    /// constituent packages, overrides are _absolute_, in that they completely replace the
5673    /// requirements of the constituent packages.
5674    #[arg(
5675        long,
5676        alias = "override",
5677        env = EnvVars::UV_OVERRIDE,
5678        value_delimiter = ' ',
5679        value_parser = parse_maybe_file_path,
5680        value_hint = ValueHint::FilePath,
5681    )]
5682    pub overrides: Vec<Maybe<PathBuf>>,
5683
5684    /// Exclude packages from resolution using the given requirements files.
5685    ///
5686    /// Excludes files are `requirements.txt`-like files that specify packages to exclude
5687    /// from the resolution. When a package is excluded, it will be omitted from the
5688    /// dependency list entirely and its own dependencies will be ignored during the resolution
5689    /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
5690    /// any package listed in the provided file will be omitted from all resolved environments.
5691    #[arg(
5692        long,
5693        alias = "exclude",
5694        env = EnvVars::UV_EXCLUDE,
5695        value_delimiter = ' ',
5696        value_parser = parse_maybe_file_path,
5697        value_hint = ValueHint::FilePath,
5698    )]
5699    pub excludes: Vec<Maybe<PathBuf>>,
5700
5701    /// Constrain build dependencies using the given requirements files when building source
5702    /// distributions.
5703    ///
5704    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5705    /// requirement that's installed. However, including a package in a constraints file will _not_
5706    /// trigger the installation of that package.
5707    #[arg(
5708        long,
5709        short,
5710        alias = "build-constraint",
5711        env = EnvVars::UV_BUILD_CONSTRAINT,
5712        value_delimiter = ' ',
5713        value_parser = parse_maybe_file_path,
5714        value_hint = ValueHint::FilePath,
5715    )]
5716    pub build_constraints: Vec<Maybe<PathBuf>>,
5717
5718    #[command(flatten)]
5719    pub installer: ResolverInstallerArgs,
5720
5721    #[command(flatten)]
5722    pub build: BuildOptionsArgs,
5723
5724    #[command(flatten)]
5725    pub refresh: RefreshArgs,
5726
5727    /// Force installation of the tool.
5728    ///
5729    /// Will recreate any existing environment for the tool and replace any existing entry points
5730    /// with the same name in the executable directory.
5731    #[arg(long)]
5732    pub force: bool,
5733
5734    /// Whether to use Git LFS when adding a dependency from Git.
5735    #[arg(long)]
5736    pub lfs: bool,
5737
5738    /// The Python interpreter to use to build the tool environment.
5739    ///
5740    /// See `uv help python` for details on Python discovery and supported request formats.
5741    #[arg(
5742        long,
5743        short,
5744        env = EnvVars::UV_PYTHON,
5745        verbatim_doc_comment,
5746        help_heading = "Python options",
5747        value_parser = parse_maybe_string,
5748        value_hint = ValueHint::Other,
5749    )]
5750    pub python: Option<Maybe<String>>,
5751
5752    /// The platform for which requirements should be installed.
5753    ///
5754    /// Represented as a "target triple", a string that describes the target platform in terms of
5755    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5756    /// `aarch64-apple-darwin`.
5757    ///
5758    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5759    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5760    ///
5761    /// When targeting iOS, the default minimum version is `13.0`. Use
5762    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5763    ///
5764    /// When targeting Android, the default minimum Android API level is `24`. Use
5765    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5766    ///
5767    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5768    /// platform; as a result, the installed distributions may not be compatible with the _current_
5769    /// platform. Conversely, any distributions that are built from source may be incompatible with
5770    /// the _target_ platform, as they will be built for the _current_ platform. The
5771    /// `--python-platform` option is intended for advanced use cases.
5772    #[arg(long)]
5773    pub python_platform: Option<TargetTriple>,
5774
5775    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5776    ///
5777    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5778    /// and will instead use the defined backend.
5779    ///
5780    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5781    /// uv will use the PyTorch index for CUDA 12.6.
5782    ///
5783    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5784    /// installed CUDA drivers.
5785    ///
5786    /// This option is in preview and may change in any future release.
5787    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5788    pub torch_backend: Option<TorchMode>,
5789}
5790
5791#[derive(Args)]
5792pub struct ToolListArgs {
5793    /// Whether to display the path to each tool environment and installed executable.
5794    #[arg(long)]
5795    pub show_paths: bool,
5796
5797    /// Whether to display the version specifier(s) used to install each tool.
5798    #[arg(long)]
5799    pub show_version_specifiers: bool,
5800
5801    /// Whether to display the additional requirements installed with each tool.
5802    #[arg(long)]
5803    pub show_with: bool,
5804
5805    /// Whether to display the extra requirements installed with each tool.
5806    #[arg(long)]
5807    pub show_extras: bool,
5808
5809    /// Whether to display the Python version associated with each tool.
5810    #[arg(long)]
5811    pub show_python: bool,
5812
5813    /// List outdated tools.
5814    ///
5815    /// The latest version of each tool will be shown alongside the installed version. Up-to-date
5816    /// tools will be omitted from the output.
5817    #[arg(long, overrides_with("no_outdated"))]
5818    pub outdated: bool,
5819
5820    #[arg(long, overrides_with("outdated"), hide = true)]
5821    pub no_outdated: bool,
5822
5823    /// Limit candidate packages to those that were uploaded prior to the given date.
5824    ///
5825    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
5826    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
5827    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
5828    /// `P7D`, `P30D`).
5829    ///
5830    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
5831    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
5832    /// Calendar units such as months and years are not allowed.
5833    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
5834    pub exclude_newer: Option<ExcludeNewerValue>,
5835
5836    // Hide unused global Python options.
5837    #[arg(long, hide = true)]
5838    pub python_preference: Option<PythonPreference>,
5839
5840    #[arg(long, hide = true)]
5841    pub no_python_downloads: bool,
5842}
5843
5844#[derive(Args)]
5845pub struct ToolDirArgs {
5846    /// Show the directory into which `uv tool` will install executables.
5847    ///
5848    /// By default, `uv tool dir` shows the directory into which the tool Python environments
5849    /// themselves are installed, rather than the directory containing the linked executables.
5850    ///
5851    /// The tool executable directory is determined according to the XDG standard and is derived
5852    /// from the following environment variables, in order of preference:
5853    ///
5854    /// - `$UV_TOOL_BIN_DIR`
5855    /// - `$XDG_BIN_HOME`
5856    /// - `$XDG_DATA_HOME/../bin`
5857    /// - `$HOME/.local/bin`
5858    #[arg(long, verbatim_doc_comment)]
5859    pub bin: bool,
5860}
5861
5862#[derive(Args)]
5863pub struct ToolUninstallArgs {
5864    /// The name of the tool to uninstall.
5865    #[arg(required = true, value_hint = ValueHint::Other)]
5866    pub name: Vec<PackageName>,
5867
5868    /// Uninstall all tools.
5869    #[arg(long, conflicts_with("name"))]
5870    pub all: bool,
5871}
5872
5873#[derive(Args)]
5874pub struct ToolUpgradeArgs {
5875    /// The name of the tool to upgrade, along with an optional version specifier.
5876    #[arg(required = true, value_hint = ValueHint::Other)]
5877    pub name: Vec<String>,
5878
5879    /// Upgrade all tools.
5880    #[arg(long, conflicts_with("name"))]
5881    pub all: bool,
5882
5883    /// Upgrade a tool, and specify it to use the given Python interpreter to build its environment.
5884    /// Use with `--all` to apply to all tools.
5885    ///
5886    /// See `uv help python` for details on Python discovery and supported request formats.
5887    #[arg(
5888        long,
5889        short,
5890        env = EnvVars::UV_PYTHON,
5891        verbatim_doc_comment,
5892        help_heading = "Python options",
5893        value_parser = parse_maybe_string,
5894        value_hint = ValueHint::Other,
5895    )]
5896    pub python: Option<Maybe<String>>,
5897
5898    /// The platform for which requirements should be installed.
5899    ///
5900    /// Represented as a "target triple", a string that describes the target platform in terms of
5901    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5902    /// `aarch64-apple-darwin`.
5903    ///
5904    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5905    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5906    ///
5907    /// When targeting iOS, the default minimum version is `13.0`. Use
5908    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5909    ///
5910    /// When targeting Android, the default minimum Android API level is `24`. Use
5911    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5912    ///
5913    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5914    /// platform; as a result, the installed distributions may not be compatible with the _current_
5915    /// platform. Conversely, any distributions that are built from source may be incompatible with
5916    /// the _target_ platform, as they will be built for the _current_ platform. The
5917    /// `--python-platform` option is intended for advanced use cases.
5918    #[arg(long)]
5919    pub python_platform: Option<TargetTriple>,
5920
5921    // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`,
5922    // `--upgrade-package`, and `--upgrade-group` options hidden, and the `--no-upgrade` option
5923    // removed.
5924    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
5925    /// `--refresh`.
5926    #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")]
5927    pub upgrade: bool,
5928
5929    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
5930    /// file. Implies `--refresh-package`.
5931    #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")]
5932    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
5933
5934    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
5935    /// existing output file.
5936    #[arg(hide = true, long, help_heading = "Resolver options")]
5937    pub upgrade_group: Vec<GroupName>,
5938
5939    #[command(flatten)]
5940    pub index_args: IndexArgs,
5941
5942    /// Reinstall all packages, regardless of whether they're already installed. Implies
5943    /// `--refresh`.
5944    #[arg(
5945        long,
5946        alias = "force-reinstall",
5947        overrides_with("no_reinstall"),
5948        help_heading = "Installer options"
5949    )]
5950    pub reinstall: bool,
5951
5952    #[arg(
5953        long,
5954        overrides_with("reinstall"),
5955        hide = true,
5956        help_heading = "Installer options"
5957    )]
5958    pub no_reinstall: bool,
5959
5960    /// Reinstall a specific package, regardless of whether it's already installed. Implies
5961    /// `--refresh-package`.
5962    #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
5963    pub reinstall_package: Vec<PackageName>,
5964
5965    /// The strategy to use when resolving against multiple index URLs.
5966    ///
5967    /// By default, uv will stop at the first index on which a given package is available, and limit
5968    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
5969    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
5970    /// to an alternate index.
5971    #[arg(
5972        long,
5973        value_enum,
5974        env = EnvVars::UV_INDEX_STRATEGY,
5975        help_heading = "Index options"
5976    )]
5977    pub index_strategy: Option<IndexStrategy>,
5978
5979    /// Attempt to use `keyring` for authentication for index URLs.
5980    ///
5981    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
5982    /// the `keyring` CLI to handle authentication.
5983    ///
5984    /// Defaults to `disabled`.
5985    #[arg(
5986        long,
5987        value_enum,
5988        env = EnvVars::UV_KEYRING_PROVIDER,
5989        help_heading = "Index options"
5990    )]
5991    pub keyring_provider: Option<KeyringProviderType>,
5992
5993    /// The strategy to use when selecting between the different compatible versions for a given
5994    /// package requirement.
5995    ///
5996    /// By default, uv will use the latest compatible version of each package (`highest`).
5997    #[arg(
5998        long,
5999        value_enum,
6000        env = EnvVars::UV_RESOLUTION,
6001        help_heading = "Resolver options"
6002    )]
6003    pub resolution: Option<ResolutionMode>,
6004
6005    /// The strategy to use when considering pre-release versions.
6006    ///
6007    /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
6008    /// with first-party requirements that contain an explicit pre-release marker in the declared
6009    /// specifiers (`if-necessary-or-explicit`).
6010    #[arg(
6011        long,
6012        value_enum,
6013        env = EnvVars::UV_PRERELEASE,
6014        help_heading = "Resolver options"
6015    )]
6016    pub prerelease: Option<PrereleaseMode>,
6017
6018    #[arg(long, hide = true)]
6019    pub pre: bool,
6020
6021    /// The strategy to use when selecting multiple versions of a given package across Python
6022    /// versions and platforms.
6023    ///
6024    /// By default, uv will optimize for selecting the latest version of each package for each
6025    /// supported Python version (`requires-python`), while minimizing the number of selected
6026    /// versions across platforms.
6027    ///
6028    /// Under `fewest`, uv will minimize the number of selected versions for each package,
6029    /// preferring older versions that are compatible with a wider range of supported Python
6030    /// versions or platforms.
6031    #[arg(
6032        long,
6033        value_enum,
6034        env = EnvVars::UV_FORK_STRATEGY,
6035        help_heading = "Resolver options"
6036    )]
6037    pub fork_strategy: Option<ForkStrategy>,
6038
6039    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
6040    #[arg(
6041        long,
6042        short = 'C',
6043        alias = "config-settings",
6044        help_heading = "Build options"
6045    )]
6046    pub config_setting: Option<Vec<ConfigSettingEntry>>,
6047
6048    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
6049    #[arg(
6050        long,
6051        alias = "config-settings-package",
6052        help_heading = "Build options"
6053    )]
6054    pub config_setting_package: Option<Vec<ConfigSettingPackageEntry>>,
6055
6056    /// Disable isolation when building source distributions.
6057    ///
6058    /// Assumes that build dependencies specified by PEP 518 are already installed.
6059    #[arg(
6060        long,
6061        overrides_with("build_isolation"),
6062        help_heading = "Build options",
6063        env = EnvVars::UV_NO_BUILD_ISOLATION,
6064        value_parser = clap::builder::BoolishValueParser::new(),
6065    )]
6066    pub no_build_isolation: bool,
6067
6068    /// Disable isolation when building source distributions for a specific package.
6069    ///
6070    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
6071    #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
6072    pub no_build_isolation_package: Vec<PackageName>,
6073
6074    #[arg(
6075        long,
6076        overrides_with("no_build_isolation"),
6077        hide = true,
6078        help_heading = "Build options"
6079    )]
6080    pub build_isolation: bool,
6081
6082    /// Limit candidate packages to those that were uploaded prior to the given date.
6083    ///
6084    /// The date is compared against the upload time of each individual distribution artifact
6085    /// (i.e., when each file was uploaded to the package index), not the release date of the
6086    /// package version.
6087    ///
6088    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
6089    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
6090    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
6091    /// `P7D`, `P30D`).
6092    ///
6093    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6094    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6095    /// Calendar units such as months and years are not allowed.
6096    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6097    pub exclude_newer: Option<ExcludeNewerValue>,
6098
6099    /// Limit candidate packages for specific packages to those that were uploaded prior to the
6100    /// given date.
6101    ///
6102    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
6103    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
6104    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
6105    /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
6106    /// `P30D`).
6107    ///
6108    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6109    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6110    /// Calendar units such as months and years are not allowed.
6111    ///
6112    /// Can be provided multiple times for different packages.
6113    #[arg(long, help_heading = "Resolver options")]
6114    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6115
6116    /// The method to use when installing packages from the global cache.
6117    ///
6118    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
6119    /// Windows.
6120    ///
6121    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
6122    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
6123    /// will break all installed packages by way of removing the underlying source files. Use
6124    /// symlinks with caution.
6125    #[arg(
6126        long,
6127        value_enum,
6128        env = EnvVars::UV_LINK_MODE,
6129        help_heading = "Installer options"
6130    )]
6131    pub link_mode: Option<uv_install_wheel::LinkMode>,
6132
6133    /// Compile Python files to bytecode after installation.
6134    ///
6135    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6136    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6137    /// in which start time is critical, such as CLI applications and Docker containers, this option
6138    /// can be enabled to trade longer installation times for faster start times.
6139    ///
6140    /// When enabled, uv will process the entire site-packages directory (including packages that
6141    /// are not being modified by the current operation) for consistency. Like pip, it will also
6142    /// ignore errors.
6143    #[arg(
6144        long,
6145        alias = "compile",
6146        overrides_with("no_compile_bytecode"),
6147        help_heading = "Installer options",
6148        env = EnvVars::UV_COMPILE_BYTECODE,
6149        value_parser = clap::builder::BoolishValueParser::new(),
6150    )]
6151    pub compile_bytecode: bool,
6152
6153    #[arg(
6154        long,
6155        alias = "no-compile",
6156        overrides_with("compile_bytecode"),
6157        hide = true,
6158        help_heading = "Installer options"
6159    )]
6160    pub no_compile_bytecode: bool,
6161
6162    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6163    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6164    /// URL, or local path sources.
6165    #[arg(
6166        long,
6167        env = EnvVars::UV_NO_SOURCES,
6168        value_parser = clap::builder::BoolishValueParser::new(),
6169        help_heading = "Resolver options",
6170    )]
6171    pub no_sources: bool,
6172
6173    /// Don't use sources from the `tool.uv.sources` table for the specified packages.
6174    #[arg(long, help_heading = "Resolver options", env = EnvVars::UV_NO_SOURCES_PACKAGE, value_delimiter = ' ')]
6175    pub no_sources_package: Vec<PackageName>,
6176
6177    #[command(flatten)]
6178    pub build: BuildOptionsArgs,
6179}
6180
6181#[derive(Args)]
6182pub struct PythonNamespace {
6183    #[command(subcommand)]
6184    pub command: PythonCommand,
6185}
6186
6187#[derive(Subcommand)]
6188pub enum PythonCommand {
6189    /// List the available Python installations.
6190    ///
6191    /// By default, installed Python versions and the downloads for latest available patch version
6192    /// of each supported Python major version are shown.
6193    ///
6194    /// Use `--managed-python` to view only managed Python versions.
6195    ///
6196    /// Use `--no-managed-python` to omit managed Python versions.
6197    ///
6198    /// Use `--all-versions` to view all available patch versions.
6199    ///
6200    /// Use `--only-installed` to omit available downloads.
6201    #[command(alias = "ls")]
6202    List(PythonListArgs),
6203
6204    /// Download and install Python versions.
6205    ///
6206    /// Supports CPython and PyPy. CPython distributions are downloaded from the Astral
6207    /// `python-build-standalone` project. PyPy distributions are downloaded from `python.org`. The
6208    /// available Python versions are bundled with each uv release. To install new Python versions,
6209    /// you may need upgrade uv.
6210    ///
6211    /// Python versions are installed into the uv Python directory, which can be retrieved with `uv
6212    /// python dir`.
6213    ///
6214    /// By default, Python executables are added to a directory on the path with a minor version
6215    /// suffix, e.g., `python3.13`. To install `python3` and `python`, use the `--default` flag. Use
6216    /// `uv python dir --bin` to see the target directory.
6217    ///
6218    /// Multiple Python versions may be requested.
6219    ///
6220    /// See `uv help python` to view supported request formats.
6221    Install(PythonInstallArgs),
6222
6223    /// Upgrade installed Python versions.
6224    ///
6225    /// Upgrades versions to the latest supported patch release. Requires the `python-upgrade`
6226    /// preview feature.
6227    ///
6228    /// A target Python minor version to upgrade may be provided, e.g., `3.13`. Multiple versions
6229    /// may be provided to perform more than one upgrade.
6230    ///
6231    /// If no target version is provided, then uv will upgrade all managed CPython versions.
6232    ///
6233    /// During an upgrade, uv will not uninstall outdated patch versions.
6234    ///
6235    /// When an upgrade is performed, virtual environments created by uv will automatically
6236    /// use the new version. However, if the virtual environment was created before the
6237    /// upgrade functionality was added, it will continue to use the old Python version; to enable
6238    /// upgrades, the environment must be recreated.
6239    ///
6240    /// Upgrades are not yet supported for alternative implementations, like PyPy.
6241    Upgrade(PythonUpgradeArgs),
6242
6243    /// Search for a Python installation.
6244    ///
6245    /// Displays the path to the Python executable.
6246    ///
6247    /// See `uv help python` to view supported request formats and details on discovery behavior.
6248    Find(PythonFindArgs),
6249
6250    /// Pin to a specific Python version.
6251    ///
6252    /// Writes the pinned Python version to a `.python-version` file, which is used by other uv
6253    /// commands to determine the required Python version.
6254    ///
6255    /// If no version is provided, uv will look for an existing `.python-version` file and display
6256    /// the currently pinned version. If no `.python-version` file is found, uv will exit with an
6257    /// error.
6258    ///
6259    /// See `uv help python` to view supported request formats.
6260    Pin(PythonPinArgs),
6261
6262    /// Show the uv Python installation directory.
6263    ///
6264    /// By default, Python installations are stored in the uv data directory at
6265    /// `$XDG_DATA_HOME/uv/python` or `$HOME/.local/share/uv/python` on Unix and
6266    /// `%APPDATA%\uv\data\python` on Windows.
6267    ///
6268    /// The Python installation directory may be overridden with `$UV_PYTHON_INSTALL_DIR`.
6269    ///
6270    /// To view the directory where uv installs Python executables instead, use the `--bin` flag.
6271    /// The Python executable directory may be overridden with `$UV_PYTHON_BIN_DIR`. Note that
6272    /// Python executables are only installed when preview mode is enabled.
6273    Dir(PythonDirArgs),
6274
6275    /// Uninstall Python versions.
6276    Uninstall(PythonUninstallArgs),
6277
6278    /// Ensure that the Python executable directory is on the `PATH`.
6279    ///
6280    /// If the Python executable directory is not present on the `PATH`, uv will attempt to add it to
6281    /// the relevant shell configuration files.
6282    ///
6283    /// If the shell configuration files already include a blurb to add the executable directory to
6284    /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
6285    ///
6286    /// The Python executable directory is determined according to the XDG standard and can be
6287    /// retrieved with `uv python dir --bin`.
6288    #[command(alias = "ensurepath")]
6289    UpdateShell,
6290}
6291
6292#[derive(Args)]
6293pub struct PythonListArgs {
6294    /// A Python request to filter by.
6295    ///
6296    /// See `uv help python` to view supported request formats.
6297    pub request: Option<String>,
6298
6299    /// List all Python versions, including old patch versions.
6300    ///
6301    /// By default, only the latest patch version is shown for each minor version.
6302    #[arg(long)]
6303    pub all_versions: bool,
6304
6305    /// List Python downloads for all platforms.
6306    ///
6307    /// By default, only downloads for the current platform are shown.
6308    #[arg(long)]
6309    pub all_platforms: bool,
6310
6311    /// List Python downloads for all architectures.
6312    ///
6313    /// By default, only downloads for the current architecture are shown.
6314    #[arg(long, alias = "all_architectures")]
6315    pub all_arches: bool,
6316
6317    /// Only show installed Python versions.
6318    ///
6319    /// By default, installed distributions and available downloads for the current platform are shown.
6320    #[arg(long, conflicts_with("only_downloads"))]
6321    pub only_installed: bool,
6322
6323    /// Only show available Python downloads.
6324    ///
6325    /// By default, installed distributions and available downloads for the current platform are shown.
6326    #[arg(long, conflicts_with("only_installed"))]
6327    pub only_downloads: bool,
6328
6329    /// Show the URLs of available Python downloads.
6330    ///
6331    /// By default, these display as `<download available>`.
6332    #[arg(long)]
6333    pub show_urls: bool,
6334
6335    /// Select the output format.
6336    #[arg(long, value_enum, default_value_t = PythonListFormat::default())]
6337    pub output_format: PythonListFormat,
6338
6339    /// URL pointing to JSON of custom Python installations.
6340    #[arg(long, value_hint = ValueHint::Other)]
6341    pub python_downloads_json_url: Option<String>,
6342}
6343
6344#[derive(Args)]
6345pub struct PythonDirArgs {
6346    /// Show the directory into which `uv python` will install Python executables.
6347    ///
6348    /// Note that this directory is only used when installing Python with preview mode enabled.
6349    ///
6350    /// The Python executable directory is determined according to the XDG standard and is derived
6351    /// from the following environment variables, in order of preference:
6352    ///
6353    /// - `$UV_PYTHON_BIN_DIR`
6354    /// - `$XDG_BIN_HOME`
6355    /// - `$XDG_DATA_HOME/../bin`
6356    /// - `$HOME/.local/bin`
6357    #[arg(long, verbatim_doc_comment)]
6358    pub bin: bool,
6359}
6360
6361#[derive(Args)]
6362pub struct PythonInstallCompileBytecodeArgs {
6363    /// Compile Python's standard library to bytecode after installation.
6364    ///
6365    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6366    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6367    /// in which start time is important, such as CLI applications and Docker containers, this
6368    /// option can be enabled to trade longer installation times and some additional disk space for
6369    /// faster start times.
6370    ///
6371    /// When enabled, uv will process the Python version's `stdlib` directory. It will ignore any
6372    /// compilation errors.
6373    #[arg(
6374        long,
6375        alias = "compile",
6376        overrides_with("no_compile_bytecode"),
6377        env = EnvVars::UV_COMPILE_BYTECODE,
6378        value_parser = clap::builder::BoolishValueParser::new(),
6379    )]
6380    pub compile_bytecode: bool,
6381
6382    #[arg(
6383        long,
6384        alias = "no-compile",
6385        overrides_with("compile_bytecode"),
6386        hide = true
6387    )]
6388    pub no_compile_bytecode: bool,
6389}
6390
6391#[derive(Args)]
6392pub struct PythonInstallArgs {
6393    /// The directory to store the Python installation in.
6394    ///
6395    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6396    /// discover the Python installation.
6397    ///
6398    /// See `uv python dir` to view the current Python installation directory. Defaults to
6399    /// `~/.local/share/uv/python`.
6400    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6401    pub install_dir: Option<PathBuf>,
6402
6403    /// Install a Python executable into the `bin` directory.
6404    ///
6405    /// This is the default behavior. If this flag is provided explicitly, uv will error if the
6406    /// executable cannot be installed.
6407    ///
6408    /// This can also be set with `UV_PYTHON_INSTALL_BIN=1`.
6409    ///
6410    /// See `UV_PYTHON_BIN_DIR` to customize the target directory.
6411    #[arg(long, overrides_with("no_bin"), hide = true)]
6412    pub bin: bool,
6413
6414    /// Do not install a Python executable into the `bin` directory.
6415    ///
6416    /// This can also be set with `UV_PYTHON_INSTALL_BIN=0`.
6417    #[arg(long, overrides_with("bin"), conflicts_with("default"))]
6418    pub no_bin: bool,
6419
6420    /// Register the Python installation in the Windows registry.
6421    ///
6422    /// This is the default behavior on Windows. If this flag is provided explicitly, uv will error if the
6423    /// registry entry cannot be created.
6424    ///
6425    /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=1`.
6426    #[arg(long, overrides_with("no_registry"), hide = true)]
6427    pub registry: bool,
6428
6429    /// Do not register the Python installation in the Windows registry.
6430    ///
6431    /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=0`.
6432    #[arg(long, overrides_with("registry"))]
6433    pub no_registry: bool,
6434
6435    /// The Python version(s) to install.
6436    ///
6437    /// If not provided, the requested Python version(s) will be read from the `UV_PYTHON`
6438    /// environment variable then `.python-versions` or `.python-version` files. If none of the
6439    /// above are present, uv will check if it has installed any Python versions. If not, it will
6440    /// install the latest stable version of Python.
6441    ///
6442    /// See `uv help python` to view supported request formats.
6443    #[arg(env = EnvVars::UV_PYTHON)]
6444    pub targets: Vec<String>,
6445
6446    /// Set the URL to use as the source for downloading Python installations.
6447    ///
6448    /// The provided URL will replace
6449    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6450    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6451    ///
6452    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6453    #[arg(long, value_hint = ValueHint::Url)]
6454    pub mirror: Option<String>,
6455
6456    /// Set the URL to use as the source for downloading PyPy installations.
6457    ///
6458    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6459    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6460    ///
6461    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6462    #[arg(long, value_hint = ValueHint::Url)]
6463    pub pypy_mirror: Option<String>,
6464
6465    /// URL pointing to JSON of custom Python installations.
6466    #[arg(long, value_hint = ValueHint::Other)]
6467    pub python_downloads_json_url: Option<String>,
6468
6469    /// Reinstall the requested Python version, if it's already installed.
6470    ///
6471    /// By default, uv will exit successfully if the version is already
6472    /// installed.
6473    #[arg(long, short)]
6474    pub reinstall: bool,
6475
6476    /// Replace existing Python executables during installation.
6477    ///
6478    /// By default, uv will refuse to replace executables that it does not manage.
6479    ///
6480    /// Implies `--reinstall`.
6481    #[arg(long, short)]
6482    pub force: bool,
6483
6484    /// Upgrade existing Python installations to the latest patch version.
6485    ///
6486    /// By default, uv will not upgrade already-installed Python versions to newer patch releases.
6487    /// With `--upgrade`, uv will upgrade to the latest available patch version for the specified
6488    /// minor version(s).
6489    ///
6490    /// If the requested versions are not yet installed, uv will install them.
6491    ///
6492    /// This option is only supported for minor version requests, e.g., `3.12`; uv will exit with an
6493    /// error if a patch version, e.g., `3.12.2`, is requested.
6494    #[arg(long, short = 'U')]
6495    pub upgrade: bool,
6496
6497    /// Use as the default Python version.
6498    ///
6499    /// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
6500    /// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
6501    /// also installed.
6502    ///
6503    /// Alternative Python variants will still include their tag. For example, installing
6504    /// 3.13+freethreaded with `--default` will include `python3t` and `pythont` instead of
6505    /// `python3` and `python`.
6506    ///
6507    /// If multiple Python versions are requested, uv will exit with an error.
6508    #[arg(long, conflicts_with("no_bin"))]
6509    pub default: bool,
6510
6511    #[command(flatten)]
6512    pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6513}
6514
6515impl PythonInstallArgs {
6516    #[must_use]
6517    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6518        PythonInstallMirrors {
6519            python_install_mirror: self.mirror.clone(),
6520            pypy_install_mirror: self.pypy_mirror.clone(),
6521            python_downloads_json_url: self.python_downloads_json_url.clone(),
6522        }
6523    }
6524}
6525
6526#[derive(Args)]
6527pub struct PythonUpgradeArgs {
6528    /// The directory Python installations are stored in.
6529    ///
6530    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6531    /// discover the Python installation.
6532    ///
6533    /// See `uv python dir` to view the current Python installation directory. Defaults to
6534    /// `~/.local/share/uv/python`.
6535    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6536    pub install_dir: Option<PathBuf>,
6537
6538    /// The Python minor version(s) to upgrade.
6539    ///
6540    /// If no target version is provided, then uv will upgrade all managed CPython versions.
6541    #[arg(env = EnvVars::UV_PYTHON)]
6542    pub targets: Vec<String>,
6543
6544    /// Set the URL to use as the source for downloading Python installations.
6545    ///
6546    /// The provided URL will replace
6547    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6548    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6549    ///
6550    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6551    #[arg(long, value_hint = ValueHint::Url)]
6552    pub mirror: Option<String>,
6553
6554    /// Set the URL to use as the source for downloading PyPy installations.
6555    ///
6556    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6557    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6558    ///
6559    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6560    #[arg(long, value_hint = ValueHint::Url)]
6561    pub pypy_mirror: Option<String>,
6562
6563    /// Reinstall the latest Python patch, if it's already installed.
6564    ///
6565    /// By default, uv will exit successfully if the latest patch is already
6566    /// installed.
6567    #[arg(long, short)]
6568    pub reinstall: bool,
6569
6570    /// URL pointing to JSON of custom Python installations.
6571    #[arg(long, value_hint = ValueHint::Other)]
6572    pub python_downloads_json_url: Option<String>,
6573
6574    #[command(flatten)]
6575    pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6576}
6577
6578impl PythonUpgradeArgs {
6579    #[must_use]
6580    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6581        PythonInstallMirrors {
6582            python_install_mirror: self.mirror.clone(),
6583            pypy_install_mirror: self.pypy_mirror.clone(),
6584            python_downloads_json_url: self.python_downloads_json_url.clone(),
6585        }
6586    }
6587}
6588
6589#[derive(Args)]
6590pub struct PythonUninstallArgs {
6591    /// The directory where the Python was installed.
6592    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6593    pub install_dir: Option<PathBuf>,
6594
6595    /// The Python version(s) to uninstall.
6596    ///
6597    /// See `uv help python` to view supported request formats.
6598    #[arg(required = true)]
6599    pub targets: Vec<String>,
6600
6601    /// Uninstall all managed Python versions.
6602    #[arg(long, conflicts_with("targets"))]
6603    pub all: bool,
6604}
6605
6606#[derive(Args)]
6607pub struct PythonFindArgs {
6608    /// The Python request.
6609    ///
6610    /// See `uv help python` to view supported request formats.
6611    pub request: Option<String>,
6612
6613    /// Avoid discovering a project or workspace.
6614    ///
6615    /// Otherwise, when no request is provided, the Python requirement of a project in the current
6616    /// directory or parent directories will be used.
6617    #[arg(
6618        long,
6619        alias = "no_workspace",
6620        env = EnvVars::UV_NO_PROJECT,
6621        value_parser = clap::builder::BoolishValueParser::new()
6622    )]
6623    pub no_project: bool,
6624
6625    /// Only find system Python interpreters.
6626    ///
6627    /// By default, uv will report the first Python interpreter it would use, including those in an
6628    /// active virtual environment or a virtual environment in the current working directory or any
6629    /// parent directory.
6630    ///
6631    /// The `--system` option instructs uv to skip virtual environment Python interpreters and
6632    /// restrict its search to the system path.
6633    #[arg(
6634        long,
6635        env = EnvVars::UV_SYSTEM_PYTHON,
6636        value_parser = clap::builder::BoolishValueParser::new(),
6637        overrides_with("no_system")
6638    )]
6639    pub system: bool,
6640
6641    #[arg(long, overrides_with("system"), hide = true)]
6642    pub no_system: bool,
6643
6644    /// Find the environment for a Python script, rather than the current project.
6645    #[arg(
6646        long,
6647        conflicts_with = "request",
6648        conflicts_with = "no_project",
6649        conflicts_with = "system",
6650        conflicts_with = "no_system",
6651        value_hint = ValueHint::FilePath,
6652    )]
6653    pub script: Option<PathBuf>,
6654
6655    /// Show the Python version that would be used instead of the path to the interpreter.
6656    #[arg(long)]
6657    pub show_version: bool,
6658
6659    /// Resolve symlinks in the output path.
6660    ///
6661    /// When enabled, the output path will be canonicalized, resolving any symlinks.
6662    #[arg(long)]
6663    pub resolve_links: bool,
6664
6665    /// URL pointing to JSON of custom Python installations.
6666    #[arg(long, value_hint = ValueHint::Other)]
6667    pub python_downloads_json_url: Option<String>,
6668}
6669
6670#[derive(Args)]
6671pub struct PythonPinArgs {
6672    /// The Python version request.
6673    ///
6674    /// uv supports more formats than other tools that read `.python-version` files, i.e., `pyenv`.
6675    /// If compatibility with those tools is needed, only use version numbers instead of complex
6676    /// requests such as `cpython@3.10`.
6677    ///
6678    /// If no request is provided, the currently pinned version will be shown.
6679    ///
6680    /// See `uv help python` to view supported request formats.
6681    pub request: Option<String>,
6682
6683    /// Write the resolved Python interpreter path instead of the request.
6684    ///
6685    /// Ensures that the exact same interpreter is used.
6686    ///
6687    /// This option is usually not safe to use when committing the `.python-version` file to version
6688    /// control.
6689    #[arg(long, overrides_with("resolved"))]
6690    pub resolved: bool,
6691
6692    #[arg(long, overrides_with("no_resolved"), hide = true)]
6693    pub no_resolved: bool,
6694
6695    /// Avoid validating the Python pin is compatible with the project or workspace.
6696    ///
6697    /// By default, a project or workspace is discovered in the current directory or any parent
6698    /// directory. If a workspace is found, the Python pin is validated against the workspace's
6699    /// `requires-python` constraint.
6700    #[arg(
6701        long,
6702        alias = "no-workspace",
6703        env = EnvVars::UV_NO_PROJECT,
6704        value_parser = clap::builder::BoolishValueParser::new()
6705    )]
6706    pub no_project: bool,
6707
6708    /// Update the global Python version pin.
6709    ///
6710    /// Writes the pinned Python version to a `.python-version` file in the uv user configuration
6711    /// directory: `XDG_CONFIG_HOME/uv` on Linux/macOS and `%APPDATA%/uv` on Windows.
6712    ///
6713    /// When a local Python version pin is not found in the working directory or an ancestor
6714    /// directory, this version will be used instead.
6715    #[arg(long)]
6716    pub global: bool,
6717
6718    /// Remove the Python version pin.
6719    #[arg(long, conflicts_with = "request", conflicts_with = "resolved")]
6720    pub rm: bool,
6721
6722    /// URL pointing to JSON of custom Python installations.
6723    #[arg(long, value_hint = ValueHint::Other)]
6724    pub python_downloads_json_url: Option<String>,
6725}
6726
6727#[derive(Args)]
6728pub struct AuthLogoutArgs {
6729    /// The domain or URL of the service to logout from.
6730    pub service: Service,
6731
6732    /// The username to logout.
6733    #[arg(long, short, value_hint = ValueHint::Other)]
6734    pub username: Option<String>,
6735
6736    /// The keyring provider to use for storage of credentials.
6737    ///
6738    /// Only `--keyring-provider native` is supported for `logout`, which uses the system keyring
6739    /// via an integration built into uv.
6740    #[arg(
6741        long,
6742        value_enum,
6743        env = EnvVars::UV_KEYRING_PROVIDER,
6744    )]
6745    pub keyring_provider: Option<KeyringProviderType>,
6746}
6747
6748#[derive(Args)]
6749pub struct AuthLoginArgs {
6750    /// The domain or URL of the service to log into.
6751    #[arg(value_hint = ValueHint::Url)]
6752    pub service: Service,
6753
6754    /// The username to use for the service.
6755    #[arg(long, short, conflicts_with = "token", value_hint = ValueHint::Other)]
6756    pub username: Option<String>,
6757
6758    /// The password to use for the service.
6759    ///
6760    /// Use `-` to read the password from stdin.
6761    #[arg(long, conflicts_with = "token", value_hint = ValueHint::Other)]
6762    pub password: Option<String>,
6763
6764    /// The token to use for the service.
6765    ///
6766    /// The username will be set to `__token__`.
6767    ///
6768    /// Use `-` to read the token from stdin.
6769    #[arg(long, short, conflicts_with = "username", conflicts_with = "password", value_hint = ValueHint::Other)]
6770    pub token: Option<String>,
6771
6772    /// The keyring provider to use for storage of credentials.
6773    ///
6774    /// Only `--keyring-provider native` is supported for `login`, which uses the system keyring via
6775    /// an integration built into uv.
6776    #[arg(
6777        long,
6778        value_enum,
6779        env = EnvVars::UV_KEYRING_PROVIDER,
6780    )]
6781    pub keyring_provider: Option<KeyringProviderType>,
6782}
6783
6784#[derive(Args)]
6785pub struct AuthTokenArgs {
6786    /// The domain or URL of the service to lookup.
6787    #[arg(value_hint = ValueHint::Url)]
6788    pub service: Service,
6789
6790    /// The username to lookup.
6791    #[arg(long, short, value_hint = ValueHint::Other)]
6792    pub username: Option<String>,
6793
6794    /// The keyring provider to use for reading credentials.
6795    #[arg(
6796        long,
6797        value_enum,
6798        env = EnvVars::UV_KEYRING_PROVIDER,
6799    )]
6800    pub keyring_provider: Option<KeyringProviderType>,
6801}
6802
6803#[derive(Args)]
6804pub struct AuthDirArgs {
6805    /// The domain or URL of the service to lookup.
6806    #[arg(value_hint = ValueHint::Url)]
6807    pub service: Option<Service>,
6808}
6809
6810#[derive(Args)]
6811pub struct AuthHelperArgs {
6812    #[command(subcommand)]
6813    pub command: AuthHelperCommand,
6814
6815    /// The credential helper protocol to use
6816    #[arg(long, value_enum, required = true)]
6817    pub protocol: AuthHelperProtocol,
6818}
6819
6820/// Credential helper protocols supported by uv
6821#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
6822pub enum AuthHelperProtocol {
6823    /// Bazel credential helper protocol as described in [the
6824    /// spec](https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md)
6825    Bazel,
6826}
6827
6828#[derive(Subcommand)]
6829pub enum AuthHelperCommand {
6830    /// Retrieve credentials for a URI
6831    Get,
6832}
6833
6834#[derive(Args)]
6835pub struct GenerateShellCompletionArgs {
6836    /// The shell to generate the completion script for
6837    pub shell: clap_complete_command::Shell,
6838
6839    // Hide unused global options.
6840    #[arg(long, short, hide = true)]
6841    pub no_cache: bool,
6842    #[arg(long, hide = true)]
6843    pub cache_dir: Option<PathBuf>,
6844
6845    #[arg(long, hide = true)]
6846    pub python_preference: Option<PythonPreference>,
6847    #[arg(long, hide = true)]
6848    pub no_python_downloads: bool,
6849
6850    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
6851    pub quiet: u8,
6852    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
6853    pub verbose: u8,
6854    #[arg(long, conflicts_with = "no_color", hide = true)]
6855    pub color: Option<ColorChoice>,
6856    #[arg(long, hide = true)]
6857    pub native_tls: bool,
6858    #[arg(long, hide = true)]
6859    pub offline: bool,
6860    #[arg(long, hide = true)]
6861    pub no_progress: bool,
6862    #[arg(long, hide = true)]
6863    pub config_file: Option<PathBuf>,
6864    #[arg(long, hide = true)]
6865    pub no_config: bool,
6866    #[arg(long, short, action = clap::ArgAction::HelpShort, hide = true)]
6867    pub help: Option<bool>,
6868    #[arg(short = 'V', long, hide = true)]
6869    pub version: bool,
6870}
6871
6872#[derive(Args)]
6873pub struct IndexArgs {
6874    /// The URLs to use when resolving dependencies, in addition to the default index.
6875    ///
6876    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6877    /// directory laid out in the same format.
6878    ///
6879    /// All indexes provided via this flag take priority over the index specified by
6880    /// `--default-index` (which defaults to PyPI). When multiple `--index` flags are provided,
6881    /// earlier values take priority.
6882    ///
6883    /// Index names are not supported as values. Relative paths must be disambiguated from index
6884    /// names with `./` or `../` on Unix or `.\\`, `..\\`, `./` or `../` on Windows.
6885    //
6886    // The nested Vec structure (`Vec<Vec<Maybe<Index>>>`) is required for clap's
6887    // value parsing mechanism, which processes one value at a time, in order to handle
6888    // `UV_INDEX` the same way pip handles `PIP_EXTRA_INDEX_URL`.
6889    #[arg(
6890        long,
6891        env = EnvVars::UV_INDEX,
6892        hide_env_values = true,
6893        value_parser = parse_indices,
6894        help_heading = "Index options"
6895    )]
6896    pub index: Option<Vec<Vec<Maybe<Index>>>>,
6897
6898    /// The URL of the default package index (by default: <https://pypi.org/simple>).
6899    ///
6900    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6901    /// directory laid out in the same format.
6902    ///
6903    /// The index given by this flag is given lower priority than all other indexes specified via
6904    /// the `--index` flag.
6905    #[arg(
6906        long,
6907        env = EnvVars::UV_DEFAULT_INDEX,
6908        hide_env_values = true,
6909        value_parser = parse_default_index,
6910        help_heading = "Index options"
6911    )]
6912    pub default_index: Option<Maybe<Index>>,
6913
6914    /// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default:
6915    /// <https://pypi.org/simple>).
6916    ///
6917    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6918    /// directory laid out in the same format.
6919    ///
6920    /// The index given by this flag is given lower priority than all other indexes specified via
6921    /// the `--extra-index-url` flag.
6922    #[arg(
6923        long,
6924        short,
6925        env = EnvVars::UV_INDEX_URL,
6926        hide_env_values = true,
6927        value_parser = parse_index_url,
6928        help_heading = "Index options"
6929    )]
6930    pub index_url: Option<Maybe<PipIndex>>,
6931
6932    /// (Deprecated: use `--index` instead) Extra URLs of package indexes to use, in addition to
6933    /// `--index-url`.
6934    ///
6935    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6936    /// directory laid out in the same format.
6937    ///
6938    /// All indexes provided via this flag take priority over the index specified by `--index-url`
6939    /// (which defaults to PyPI). When multiple `--extra-index-url` flags are provided, earlier
6940    /// values take priority.
6941    #[arg(
6942        long,
6943        env = EnvVars::UV_EXTRA_INDEX_URL,
6944        hide_env_values = true,
6945        value_delimiter = ' ',
6946        value_parser = parse_extra_index_url,
6947        help_heading = "Index options"
6948    )]
6949    pub extra_index_url: Option<Vec<Maybe<PipExtraIndex>>>,
6950
6951    /// Locations to search for candidate distributions, in addition to those found in the registry
6952    /// indexes.
6953    ///
6954    /// If a path, the target must be a directory that contains packages as wheel files (`.whl`) or
6955    /// source distributions (e.g., `.tar.gz` or `.zip`) at the top level.
6956    ///
6957    /// If a URL, the page must contain a flat list of links to package files adhering to the
6958    /// formats described above.
6959    #[arg(
6960        long,
6961        short,
6962        env = EnvVars::UV_FIND_LINKS,
6963        hide_env_values = true,
6964        value_delimiter = ',',
6965        value_parser = parse_find_links,
6966        help_heading = "Index options"
6967    )]
6968    pub find_links: Option<Vec<Maybe<PipFindLinks>>>,
6969
6970    /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
6971    /// provided via `--find-links`.
6972    #[arg(long, help_heading = "Index options")]
6973    pub no_index: bool,
6974}
6975
6976#[derive(Args)]
6977pub struct RefreshArgs {
6978    /// Refresh all cached data.
6979    #[arg(long, overrides_with("no_refresh"), help_heading = "Cache options")]
6980    pub refresh: bool,
6981
6982    #[arg(
6983        long,
6984        overrides_with("refresh"),
6985        hide = true,
6986        help_heading = "Cache options"
6987    )]
6988    pub no_refresh: bool,
6989
6990    /// Refresh cached data for a specific package.
6991    #[arg(long, help_heading = "Cache options", value_hint = ValueHint::Other)]
6992    pub refresh_package: Vec<PackageName>,
6993}
6994
6995#[derive(Args)]
6996pub struct BuildOptionsArgs {
6997    /// Don't build source distributions.
6998    ///
6999    /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
7000    /// already-built source distributions will be reused, but operations that require building
7001    /// distributions will exit with an error.
7002    #[arg(
7003        long,
7004        env = EnvVars::UV_NO_BUILD,
7005        overrides_with("build"),
7006        value_parser = clap::builder::BoolishValueParser::new(),
7007        help_heading = "Build options",
7008    )]
7009    pub no_build: bool,
7010
7011    #[arg(
7012        long,
7013        overrides_with("no_build"),
7014        hide = true,
7015        help_heading = "Build options"
7016    )]
7017    pub build: bool,
7018
7019    /// Don't build source distributions for a specific package.
7020    #[arg(
7021        long,
7022        help_heading = "Build options",
7023        env = EnvVars::UV_NO_BUILD_PACKAGE,
7024        value_delimiter = ' ',
7025        value_hint = ValueHint::Other,
7026    )]
7027    pub no_build_package: Vec<PackageName>,
7028
7029    /// Don't install pre-built wheels.
7030    ///
7031    /// The given packages will be built and installed from source. The resolver will still use
7032    /// pre-built wheels to extract package metadata, if available.
7033    #[arg(
7034        long,
7035        env = EnvVars::UV_NO_BINARY,
7036        overrides_with("binary"),
7037        value_parser = clap::builder::BoolishValueParser::new(),
7038        help_heading = "Build options"
7039    )]
7040    pub no_binary: bool,
7041
7042    #[arg(
7043        long,
7044        overrides_with("no_binary"),
7045        hide = true,
7046        help_heading = "Build options"
7047    )]
7048    pub binary: bool,
7049
7050    /// Don't install pre-built wheels for a specific package.
7051    #[arg(
7052        long,
7053        help_heading = "Build options",
7054        env = EnvVars::UV_NO_BINARY_PACKAGE,
7055        value_delimiter = ' ',
7056        value_hint = ValueHint::Other,
7057    )]
7058    pub no_binary_package: Vec<PackageName>,
7059}
7060
7061/// Arguments that are used by commands that need to install (but not resolve) packages.
7062#[derive(Args)]
7063pub struct InstallerArgs {
7064    #[command(flatten)]
7065    pub index_args: IndexArgs,
7066
7067    /// Reinstall all packages, regardless of whether they're already installed. Implies
7068    /// `--refresh`.
7069    #[arg(
7070        long,
7071        alias = "force-reinstall",
7072        overrides_with("no_reinstall"),
7073        help_heading = "Installer options"
7074    )]
7075    pub reinstall: bool,
7076
7077    #[arg(
7078        long,
7079        overrides_with("reinstall"),
7080        hide = true,
7081        help_heading = "Installer options"
7082    )]
7083    pub no_reinstall: bool,
7084
7085    /// Reinstall a specific package, regardless of whether it's already installed. Implies
7086    /// `--refresh-package`.
7087    #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7088    pub reinstall_package: Vec<PackageName>,
7089
7090    /// The strategy to use when resolving against multiple index URLs.
7091    ///
7092    /// By default, uv will stop at the first index on which a given package is available, and limit
7093    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7094    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7095    /// to an alternate index.
7096    #[arg(
7097        long,
7098        value_enum,
7099        env = EnvVars::UV_INDEX_STRATEGY,
7100        help_heading = "Index options"
7101    )]
7102    pub index_strategy: Option<IndexStrategy>,
7103
7104    /// Attempt to use `keyring` for authentication for index URLs.
7105    ///
7106    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7107    /// the `keyring` CLI to handle authentication.
7108    ///
7109    /// Defaults to `disabled`.
7110    #[arg(
7111        long,
7112        value_enum,
7113        env = EnvVars::UV_KEYRING_PROVIDER,
7114        help_heading = "Index options"
7115    )]
7116    pub keyring_provider: Option<KeyringProviderType>,
7117
7118    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7119    #[arg(
7120        long,
7121        short = 'C',
7122        alias = "config-settings",
7123        help_heading = "Build options"
7124    )]
7125    pub config_setting: Option<Vec<ConfigSettingEntry>>,
7126
7127    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7128    #[arg(
7129        long,
7130        alias = "config-settings-package",
7131        help_heading = "Build options"
7132    )]
7133    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7134
7135    /// Disable isolation when building source distributions.
7136    ///
7137    /// Assumes that build dependencies specified by PEP 518 are already installed.
7138    #[arg(
7139        long,
7140        overrides_with("build_isolation"),
7141        help_heading = "Build options",
7142        env = EnvVars::UV_NO_BUILD_ISOLATION,
7143        value_parser = clap::builder::BoolishValueParser::new(),
7144    )]
7145    pub no_build_isolation: bool,
7146
7147    #[arg(
7148        long,
7149        overrides_with("no_build_isolation"),
7150        hide = true,
7151        help_heading = "Build options"
7152    )]
7153    pub build_isolation: bool,
7154
7155    /// Limit candidate packages to those that were uploaded prior to the given date.
7156    ///
7157    /// The date is compared against the upload time of each individual distribution artifact
7158    /// (i.e., when each file was uploaded to the package index), not the release date of the
7159    /// package version.
7160    ///
7161    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7162    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7163    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7164    /// `P7D`, `P30D`).
7165    ///
7166    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7167    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7168    /// Calendar units such as months and years are not allowed.
7169    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7170    pub exclude_newer: Option<ExcludeNewerValue>,
7171
7172    /// Limit candidate packages for specific packages to those that were uploaded prior to the
7173    /// given date.
7174    ///
7175    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7176    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7177    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7178    /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7179    /// `P30D`).
7180    ///
7181    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7182    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7183    /// Calendar units such as months and years are not allowed.
7184    ///
7185    /// Can be provided multiple times for different packages.
7186    #[arg(long, help_heading = "Resolver options")]
7187    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7188
7189    /// The method to use when installing packages from the global cache.
7190    ///
7191    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7192    /// Windows.
7193    ///
7194    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7195    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7196    /// will break all installed packages by way of removing the underlying source files. Use
7197    /// symlinks with caution.
7198    #[arg(
7199        long,
7200        value_enum,
7201        env = EnvVars::UV_LINK_MODE,
7202        help_heading = "Installer options"
7203    )]
7204    pub link_mode: Option<uv_install_wheel::LinkMode>,
7205
7206    /// Compile Python files to bytecode after installation.
7207    ///
7208    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7209    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7210    /// in which start time is critical, such as CLI applications and Docker containers, this option
7211    /// can be enabled to trade longer installation times for faster start times.
7212    ///
7213    /// When enabled, uv will process the entire site-packages directory (including packages that
7214    /// are not being modified by the current operation) for consistency. Like pip, it will also
7215    /// ignore errors.
7216    #[arg(
7217        long,
7218        alias = "compile",
7219        overrides_with("no_compile_bytecode"),
7220        help_heading = "Installer options",
7221        env = EnvVars::UV_COMPILE_BYTECODE,
7222        value_parser = clap::builder::BoolishValueParser::new(),
7223    )]
7224    pub compile_bytecode: bool,
7225
7226    #[arg(
7227        long,
7228        alias = "no-compile",
7229        overrides_with("compile_bytecode"),
7230        hide = true,
7231        help_heading = "Installer options"
7232    )]
7233    pub no_compile_bytecode: bool,
7234
7235    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7236    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7237    /// URL, or local path sources.
7238    #[arg(
7239        long,
7240        env = EnvVars::UV_NO_SOURCES,
7241        value_parser = clap::builder::BoolishValueParser::new(),
7242        help_heading = "Resolver options"
7243    )]
7244    pub no_sources: bool,
7245
7246    /// Don't use sources from the `tool.uv.sources` table for the specified packages.
7247    #[arg(long, help_heading = "Resolver options", env = EnvVars::UV_NO_SOURCES_PACKAGE, value_delimiter = ' ')]
7248    pub no_sources_package: Vec<PackageName>,
7249}
7250
7251/// Arguments that are used by commands that need to resolve (but not install) packages.
7252#[derive(Args)]
7253pub struct ResolverArgs {
7254    #[command(flatten)]
7255    pub index_args: IndexArgs,
7256
7257    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7258    /// `--refresh`.
7259    #[arg(
7260        long,
7261        short = 'U',
7262        overrides_with("no_upgrade"),
7263        help_heading = "Resolver options"
7264    )]
7265    pub upgrade: bool,
7266
7267    #[arg(
7268        long,
7269        overrides_with("upgrade"),
7270        hide = true,
7271        help_heading = "Resolver options"
7272    )]
7273    pub no_upgrade: bool,
7274
7275    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
7276    /// file. Implies `--refresh-package`.
7277    #[arg(long, short = 'P', help_heading = "Resolver options")]
7278    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7279
7280    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7281    /// existing output file.
7282    #[arg(long, help_heading = "Resolver options")]
7283    pub upgrade_group: Vec<GroupName>,
7284
7285    /// The strategy to use when resolving against multiple index URLs.
7286    ///
7287    /// By default, uv will stop at the first index on which a given package is available, and limit
7288    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7289    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7290    /// to an alternate index.
7291    #[arg(
7292        long,
7293        value_enum,
7294        env = EnvVars::UV_INDEX_STRATEGY,
7295        help_heading = "Index options"
7296    )]
7297    pub index_strategy: Option<IndexStrategy>,
7298
7299    /// Attempt to use `keyring` for authentication for index URLs.
7300    ///
7301    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7302    /// the `keyring` CLI to handle authentication.
7303    ///
7304    /// Defaults to `disabled`.
7305    #[arg(
7306        long,
7307        value_enum,
7308        env = EnvVars::UV_KEYRING_PROVIDER,
7309        help_heading = "Index options"
7310    )]
7311    pub keyring_provider: Option<KeyringProviderType>,
7312
7313    /// The strategy to use when selecting between the different compatible versions for a given
7314    /// package requirement.
7315    ///
7316    /// By default, uv will use the latest compatible version of each package (`highest`).
7317    #[arg(
7318        long,
7319        value_enum,
7320        env = EnvVars::UV_RESOLUTION,
7321        help_heading = "Resolver options"
7322    )]
7323    pub resolution: Option<ResolutionMode>,
7324
7325    /// The strategy to use when considering pre-release versions.
7326    ///
7327    /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
7328    /// with first-party requirements that contain an explicit pre-release marker in the declared
7329    /// specifiers (`if-necessary-or-explicit`).
7330    #[arg(
7331        long,
7332        value_enum,
7333        env = EnvVars::UV_PRERELEASE,
7334        help_heading = "Resolver options"
7335    )]
7336    pub prerelease: Option<PrereleaseMode>,
7337
7338    #[arg(long, hide = true, help_heading = "Resolver options")]
7339    pub pre: bool,
7340
7341    /// The strategy to use when selecting multiple versions of a given package across Python
7342    /// versions and platforms.
7343    ///
7344    /// By default, uv will optimize for selecting the latest version of each package for each
7345    /// supported Python version (`requires-python`), while minimizing the number of selected
7346    /// versions across platforms.
7347    ///
7348    /// Under `fewest`, uv will minimize the number of selected versions for each package,
7349    /// preferring older versions that are compatible with a wider range of supported Python
7350    /// versions or platforms.
7351    #[arg(
7352        long,
7353        value_enum,
7354        env = EnvVars::UV_FORK_STRATEGY,
7355        help_heading = "Resolver options"
7356    )]
7357    pub fork_strategy: Option<ForkStrategy>,
7358
7359    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7360    #[arg(
7361        long,
7362        short = 'C',
7363        alias = "config-settings",
7364        help_heading = "Build options"
7365    )]
7366    pub config_setting: Option<Vec<ConfigSettingEntry>>,
7367
7368    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7369    #[arg(
7370        long,
7371        alias = "config-settings-package",
7372        help_heading = "Build options"
7373    )]
7374    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7375
7376    /// Disable isolation when building source distributions.
7377    ///
7378    /// Assumes that build dependencies specified by PEP 518 are already installed.
7379    #[arg(
7380        long,
7381        overrides_with("build_isolation"),
7382        help_heading = "Build options",
7383        env = EnvVars::UV_NO_BUILD_ISOLATION,
7384        value_parser = clap::builder::BoolishValueParser::new(),
7385    )]
7386    pub no_build_isolation: bool,
7387
7388    /// Disable isolation when building source distributions for a specific package.
7389    ///
7390    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7391    #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7392    pub no_build_isolation_package: Vec<PackageName>,
7393
7394    #[arg(
7395        long,
7396        overrides_with("no_build_isolation"),
7397        hide = true,
7398        help_heading = "Build options"
7399    )]
7400    pub build_isolation: bool,
7401
7402    /// Limit candidate packages to those that were uploaded prior to the given date.
7403    ///
7404    /// The date is compared against the upload time of each individual distribution artifact
7405    /// (i.e., when each file was uploaded to the package index), not the release date of the
7406    /// package version.
7407    ///
7408    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7409    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7410    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7411    /// `P7D`, `P30D`).
7412    ///
7413    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7414    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7415    /// Calendar units such as months and years are not allowed.
7416    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7417    pub exclude_newer: Option<ExcludeNewerValue>,
7418
7419    /// Limit candidate packages for specific packages to those that were uploaded prior to the
7420    /// given date.
7421    ///
7422    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7423    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7424    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7425    /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7426    /// `P30D`).
7427    ///
7428    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7429    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7430    /// Calendar units such as months and years are not allowed.
7431    ///
7432    /// Can be provided multiple times for different packages.
7433    #[arg(long, help_heading = "Resolver options")]
7434    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7435
7436    /// The method to use when installing packages from the global cache.
7437    ///
7438    /// This option is only used when building source distributions.
7439    ///
7440    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7441    /// Windows.
7442    ///
7443    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7444    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7445    /// will break all installed packages by way of removing the underlying source files. Use
7446    /// symlinks with caution.
7447    #[arg(
7448        long,
7449        value_enum,
7450        env = EnvVars::UV_LINK_MODE,
7451        help_heading = "Installer options"
7452    )]
7453    pub link_mode: Option<uv_install_wheel::LinkMode>,
7454
7455    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7456    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7457    /// URL, or local path sources.
7458    #[arg(
7459        long,
7460        env = EnvVars::UV_NO_SOURCES,
7461        value_parser = clap::builder::BoolishValueParser::new(),
7462        help_heading = "Resolver options",
7463    )]
7464    pub no_sources: bool,
7465
7466    /// Don't use sources from the `tool.uv.sources` table for the specified packages.
7467    #[arg(long, help_heading = "Resolver options", env = EnvVars::UV_NO_SOURCES_PACKAGE, value_delimiter = ' ')]
7468    pub no_sources_package: Vec<PackageName>,
7469}
7470
7471/// Arguments that are used by commands that need to resolve and install packages.
7472#[derive(Args)]
7473pub struct ResolverInstallerArgs {
7474    #[command(flatten)]
7475    pub index_args: IndexArgs,
7476
7477    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7478    /// `--refresh`.
7479    #[arg(
7480        long,
7481        short = 'U',
7482        overrides_with("no_upgrade"),
7483        help_heading = "Resolver options"
7484    )]
7485    pub upgrade: bool,
7486
7487    #[arg(
7488        long,
7489        overrides_with("upgrade"),
7490        hide = true,
7491        help_heading = "Resolver options"
7492    )]
7493    pub no_upgrade: bool,
7494
7495    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output file.
7496    /// Implies `--refresh-package`.
7497    #[arg(long, short = 'P', help_heading = "Resolver options", value_hint = ValueHint::Other)]
7498    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7499
7500    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7501    /// existing output file.
7502    #[arg(long, help_heading = "Resolver options")]
7503    pub upgrade_group: Vec<GroupName>,
7504
7505    /// Reinstall all packages, regardless of whether they're already installed. Implies
7506    /// `--refresh`.
7507    #[arg(
7508        long,
7509        alias = "force-reinstall",
7510        overrides_with("no_reinstall"),
7511        help_heading = "Installer options"
7512    )]
7513    pub reinstall: bool,
7514
7515    #[arg(
7516        long,
7517        overrides_with("reinstall"),
7518        hide = true,
7519        help_heading = "Installer options"
7520    )]
7521    pub no_reinstall: bool,
7522
7523    /// Reinstall a specific package, regardless of whether it's already installed. Implies
7524    /// `--refresh-package`.
7525    #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7526    pub reinstall_package: Vec<PackageName>,
7527
7528    /// The strategy to use when resolving against multiple index URLs.
7529    ///
7530    /// By default, uv will stop at the first index on which a given package is available, and limit
7531    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7532    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7533    /// to an alternate index.
7534    #[arg(
7535        long,
7536        value_enum,
7537        env = EnvVars::UV_INDEX_STRATEGY,
7538        help_heading = "Index options"
7539    )]
7540    pub index_strategy: Option<IndexStrategy>,
7541
7542    /// Attempt to use `keyring` for authentication for index URLs.
7543    ///
7544    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7545    /// the `keyring` CLI to handle authentication.
7546    ///
7547    /// Defaults to `disabled`.
7548    #[arg(
7549        long,
7550        value_enum,
7551        env = EnvVars::UV_KEYRING_PROVIDER,
7552        help_heading = "Index options"
7553    )]
7554    pub keyring_provider: Option<KeyringProviderType>,
7555
7556    /// The strategy to use when selecting between the different compatible versions for a given
7557    /// package requirement.
7558    ///
7559    /// By default, uv will use the latest compatible version of each package (`highest`).
7560    #[arg(
7561        long,
7562        value_enum,
7563        env = EnvVars::UV_RESOLUTION,
7564        help_heading = "Resolver options"
7565    )]
7566    pub resolution: Option<ResolutionMode>,
7567
7568    /// The strategy to use when considering pre-release versions.
7569    ///
7570    /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
7571    /// with first-party requirements that contain an explicit pre-release marker in the declared
7572    /// specifiers (`if-necessary-or-explicit`).
7573    #[arg(
7574        long,
7575        value_enum,
7576        env = EnvVars::UV_PRERELEASE,
7577        help_heading = "Resolver options"
7578    )]
7579    pub prerelease: Option<PrereleaseMode>,
7580
7581    #[arg(long, hide = true)]
7582    pub pre: bool,
7583
7584    /// The strategy to use when selecting multiple versions of a given package across Python
7585    /// versions and platforms.
7586    ///
7587    /// By default, uv will optimize for selecting the latest version of each package for each
7588    /// supported Python version (`requires-python`), while minimizing the number of selected
7589    /// versions across platforms.
7590    ///
7591    /// Under `fewest`, uv will minimize the number of selected versions for each package,
7592    /// preferring older versions that are compatible with a wider range of supported Python
7593    /// versions or platforms.
7594    #[arg(
7595        long,
7596        value_enum,
7597        env = EnvVars::UV_FORK_STRATEGY,
7598        help_heading = "Resolver options"
7599    )]
7600    pub fork_strategy: Option<ForkStrategy>,
7601
7602    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7603    #[arg(
7604        long,
7605        short = 'C',
7606        alias = "config-settings",
7607        help_heading = "Build options",
7608        value_hint = ValueHint::Other,
7609    )]
7610    pub config_setting: Option<Vec<ConfigSettingEntry>>,
7611
7612    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7613    #[arg(
7614        long,
7615        alias = "config-settings-package",
7616        help_heading = "Build options",
7617        value_hint = ValueHint::Other,
7618    )]
7619    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7620
7621    /// Disable isolation when building source distributions.
7622    ///
7623    /// Assumes that build dependencies specified by PEP 518 are already installed.
7624    #[arg(
7625        long,
7626        overrides_with("build_isolation"),
7627        help_heading = "Build options",
7628        env = EnvVars::UV_NO_BUILD_ISOLATION,
7629        value_parser = clap::builder::BoolishValueParser::new(),
7630    )]
7631    pub no_build_isolation: bool,
7632
7633    /// Disable isolation when building source distributions for a specific package.
7634    ///
7635    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7636    #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7637    pub no_build_isolation_package: Vec<PackageName>,
7638
7639    #[arg(
7640        long,
7641        overrides_with("no_build_isolation"),
7642        hide = true,
7643        help_heading = "Build options"
7644    )]
7645    pub build_isolation: bool,
7646
7647    /// Limit candidate packages to those that were uploaded prior to the given date.
7648    ///
7649    /// The date is compared against the upload time of each individual distribution artifact
7650    /// (i.e., when each file was uploaded to the package index), not the release date of the
7651    /// package version.
7652    ///
7653    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7654    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7655    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7656    /// `P7D`, `P30D`).
7657    ///
7658    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7659    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7660    /// Calendar units such as months and years are not allowed.
7661    #[arg(
7662        long,
7663        env = EnvVars::UV_EXCLUDE_NEWER,
7664        help_heading = "Resolver options",
7665        value_hint = ValueHint::Other,
7666    )]
7667    pub exclude_newer: Option<ExcludeNewerValue>,
7668
7669    /// Limit candidate packages for specific packages to those that were uploaded prior to the
7670    /// given date.
7671    ///
7672    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7673    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7674    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7675    /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7676    /// `P30D`).
7677    ///
7678    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7679    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7680    /// Calendar units such as months and years are not allowed.
7681    ///
7682    /// Can be provided multiple times for different packages.
7683    #[arg(long, help_heading = "Resolver options", value_hint = ValueHint::Other)]
7684    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7685
7686    /// The method to use when installing packages from the global cache.
7687    ///
7688    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7689    /// Windows.
7690    ///
7691    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7692    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7693    /// will break all installed packages by way of removing the underlying source files. Use
7694    /// symlinks with caution.
7695    #[arg(
7696        long,
7697        value_enum,
7698        env = EnvVars::UV_LINK_MODE,
7699        help_heading = "Installer options"
7700    )]
7701    pub link_mode: Option<uv_install_wheel::LinkMode>,
7702
7703    /// Compile Python files to bytecode after installation.
7704    ///
7705    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7706    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7707    /// in which start time is critical, such as CLI applications and Docker containers, this option
7708    /// can be enabled to trade longer installation times for faster start times.
7709    ///
7710    /// When enabled, uv will process the entire site-packages directory (including packages that
7711    /// are not being modified by the current operation) for consistency. Like pip, it will also
7712    /// ignore errors.
7713    #[arg(
7714        long,
7715        alias = "compile",
7716        overrides_with("no_compile_bytecode"),
7717        help_heading = "Installer options",
7718        env = EnvVars::UV_COMPILE_BYTECODE,
7719        value_parser = clap::builder::BoolishValueParser::new(),
7720    )]
7721    pub compile_bytecode: bool,
7722
7723    #[arg(
7724        long,
7725        alias = "no-compile",
7726        overrides_with("compile_bytecode"),
7727        hide = true,
7728        help_heading = "Installer options"
7729    )]
7730    pub no_compile_bytecode: bool,
7731
7732    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7733    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7734    /// URL, or local path sources.
7735    #[arg(
7736        long,
7737        env = EnvVars::UV_NO_SOURCES,
7738        value_parser = clap::builder::BoolishValueParser::new(),
7739        help_heading = "Resolver options",
7740    )]
7741    pub no_sources: bool,
7742
7743    /// Don't use sources from the `tool.uv.sources` table for the specified packages.
7744    #[arg(long, help_heading = "Resolver options", env = EnvVars::UV_NO_SOURCES_PACKAGE, value_delimiter = ' ')]
7745    pub no_sources_package: Vec<PackageName>,
7746}
7747
7748/// Arguments that are used by commands that need to fetch from the Simple API.
7749#[derive(Args)]
7750pub struct FetchArgs {
7751    #[command(flatten)]
7752    pub index_args: IndexArgs,
7753
7754    /// The strategy to use when resolving against multiple index URLs.
7755    ///
7756    /// By default, uv will stop at the first index on which a given package is available, and limit
7757    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7758    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7759    /// to an alternate index.
7760    #[arg(
7761        long,
7762        value_enum,
7763        env = EnvVars::UV_INDEX_STRATEGY,
7764        help_heading = "Index options"
7765    )]
7766    pub index_strategy: Option<IndexStrategy>,
7767
7768    /// Attempt to use `keyring` for authentication for index URLs.
7769    ///
7770    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7771    /// the `keyring` CLI to handle authentication.
7772    ///
7773    /// Defaults to `disabled`.
7774    #[arg(
7775        long,
7776        value_enum,
7777        env = EnvVars::UV_KEYRING_PROVIDER,
7778        help_heading = "Index options"
7779    )]
7780    pub keyring_provider: Option<KeyringProviderType>,
7781
7782    /// Limit candidate packages to those that were uploaded prior to the given date.
7783    ///
7784    /// The date is compared against the upload time of each individual distribution artifact
7785    /// (i.e., when each file was uploaded to the package index), not the release date of the
7786    /// package version.
7787    ///
7788    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7789    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7790    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7791    /// `P7D`, `P30D`).
7792    ///
7793    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7794    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7795    /// Calendar units such as months and years are not allowed.
7796    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7797    pub exclude_newer: Option<ExcludeNewerValue>,
7798}
7799
7800#[derive(Args)]
7801pub struct DisplayTreeArgs {
7802    /// Maximum display depth of the dependency tree
7803    #[arg(long, short, default_value_t = 255)]
7804    pub depth: u8,
7805
7806    /// Prune the given package from the display of the dependency tree.
7807    #[arg(long, value_hint = ValueHint::Other)]
7808    pub prune: Vec<PackageName>,
7809
7810    /// Display only the specified packages.
7811    #[arg(long, value_hint = ValueHint::Other)]
7812    pub package: Vec<PackageName>,
7813
7814    /// Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its
7815    /// dependencies, further occurrences will not re-display its dependencies, and will include a
7816    /// (*) to indicate it has already been shown. This flag will cause those duplicates to be
7817    /// repeated.
7818    #[arg(long)]
7819    pub no_dedupe: bool,
7820
7821    /// Show the reverse dependencies for the given package. This flag will invert the tree and
7822    /// display the packages that depend on the given package.
7823    #[arg(long, alias = "reverse")]
7824    pub invert: bool,
7825
7826    /// Show the latest available version of each package in the tree.
7827    #[arg(long)]
7828    pub outdated: bool,
7829
7830    /// Show compressed wheel sizes for packages in the tree.
7831    #[arg(long)]
7832    pub show_sizes: bool,
7833}
7834
7835#[derive(Args, Debug)]
7836pub struct PublishArgs {
7837    /// Paths to the files to upload. Accepts glob expressions.
7838    ///
7839    /// Defaults to the `dist` directory. Selects only wheels and source distributions
7840    /// and their attestations, while ignoring other files.
7841    #[arg(default_value = "dist/*", value_hint = ValueHint::FilePath)]
7842    pub files: Vec<String>,
7843
7844    /// The name of an index in the configuration to use for publishing.
7845    ///
7846    /// The index must have a `publish-url` setting, for example:
7847    ///
7848    /// ```toml
7849    /// [[tool.uv.index]]
7850    /// name = "pypi"
7851    /// url = "https://pypi.org/simple"
7852    /// publish-url = "https://upload.pypi.org/legacy/"
7853    /// ```
7854    ///
7855    /// The index `url` will be used to check for existing files to skip duplicate uploads.
7856    ///
7857    /// With these settings, the following two calls are equivalent:
7858    ///
7859    /// ```shell
7860    /// uv publish --index pypi
7861    /// uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pypi.org/simple
7862    /// ```
7863    #[arg(
7864        long,
7865        verbatim_doc_comment,
7866        env = EnvVars::UV_PUBLISH_INDEX,
7867        conflicts_with = "publish_url",
7868        conflicts_with = "check_url",
7869        value_hint = ValueHint::Other,
7870    )]
7871    pub index: Option<String>,
7872
7873    /// The username for the upload.
7874    #[arg(
7875        short,
7876        long,
7877        env = EnvVars::UV_PUBLISH_USERNAME,
7878        hide_env_values = true,
7879        value_hint = ValueHint::Other
7880    )]
7881    pub username: Option<String>,
7882
7883    /// The password for the upload.
7884    #[arg(
7885        short,
7886        long,
7887        env = EnvVars::UV_PUBLISH_PASSWORD,
7888        hide_env_values = true,
7889        value_hint = ValueHint::Other
7890    )]
7891    pub password: Option<String>,
7892
7893    /// The token for the upload.
7894    ///
7895    /// Using a token is equivalent to passing `__token__` as `--username` and the token as
7896    /// `--password` password.
7897    #[arg(
7898        short,
7899        long,
7900        env = EnvVars::UV_PUBLISH_TOKEN,
7901        hide_env_values = true,
7902        conflicts_with = "username",
7903        conflicts_with = "password",
7904        value_hint = ValueHint::Other,
7905    )]
7906    pub token: Option<String>,
7907
7908    /// Configure trusted publishing.
7909    ///
7910    /// By default, uv checks for trusted publishing when running in a supported environment, but
7911    /// ignores it if it isn't configured.
7912    ///
7913    /// uv's supported environments for trusted publishing include GitHub Actions and GitLab CI/CD.
7914    #[arg(long)]
7915    pub trusted_publishing: Option<TrustedPublishing>,
7916
7917    /// Attempt to use `keyring` for authentication for remote requirements files.
7918    ///
7919    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7920    /// the `keyring` CLI to handle authentication.
7921    ///
7922    /// Defaults to `disabled`.
7923    #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
7924    pub keyring_provider: Option<KeyringProviderType>,
7925
7926    /// The URL of the upload endpoint (not the index URL).
7927    ///
7928    /// Note that there are typically different URLs for index access (e.g., `https:://.../simple`)
7929    /// and index upload.
7930    ///
7931    /// Defaults to PyPI's publish URL (<https://upload.pypi.org/legacy/>).
7932    #[arg(long, env = EnvVars::UV_PUBLISH_URL, hide_env_values = true)]
7933    pub publish_url: Option<DisplaySafeUrl>,
7934
7935    /// Check an index URL for existing files to skip duplicate uploads.
7936    ///
7937    /// This option allows retrying publishing that failed after only some, but not all files have
7938    /// been uploaded, and handles errors due to parallel uploads of the same file.
7939    ///
7940    /// Before uploading, the index is checked. If the exact same file already exists in the index,
7941    /// the file will not be uploaded. If an error occurred during the upload, the index is checked
7942    /// again, to handle cases where the identical file was uploaded twice in parallel.
7943    ///
7944    /// The exact behavior will vary based on the index. When uploading to PyPI, uploading the same
7945    /// file succeeds even without `--check-url`, while most other indexes error. When uploading to
7946    /// pyx, the index URL can be inferred automatically from the publish URL.
7947    ///
7948    /// The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).
7949    #[arg(long, env = EnvVars::UV_PUBLISH_CHECK_URL, hide_env_values = true)]
7950    pub check_url: Option<IndexUrl>,
7951
7952    #[arg(long, hide = true)]
7953    pub skip_existing: bool,
7954
7955    /// Perform a dry run without uploading files.
7956    ///
7957    /// When enabled, the command will check for existing files if `--check-url` is provided,
7958    /// and will perform validation against the index if supported, but will not upload any files.
7959    #[arg(long)]
7960    pub dry_run: bool,
7961
7962    /// Do not upload attestations for the published files.
7963    ///
7964    /// By default, uv attempts to upload matching PEP 740 attestations with each distribution
7965    /// that is published.
7966    #[arg(long, env = EnvVars::UV_PUBLISH_NO_ATTESTATIONS)]
7967    pub no_attestations: bool,
7968
7969    /// Use direct upload to the registry.
7970    ///
7971    /// When enabled, the publish command will use a direct two-phase upload protocol
7972    /// that uploads files directly to storage, bypassing the registry's upload endpoint.
7973    #[arg(long, hide = true)]
7974    pub direct: bool,
7975}
7976
7977#[derive(Args)]
7978pub struct WorkspaceNamespace {
7979    #[command(subcommand)]
7980    pub command: WorkspaceCommand,
7981}
7982
7983#[derive(Subcommand)]
7984pub enum WorkspaceCommand {
7985    /// View metadata about the current workspace.
7986    ///
7987    /// The output of this command is not yet stable.
7988    Metadata(Box<MetadataArgs>),
7989    /// Display the path of a workspace member.
7990    ///
7991    /// By default, the path to the workspace root directory is displayed.
7992    /// The `--package` option can be used to display the path to a workspace member instead.
7993    ///
7994    /// If used outside of a workspace, i.e., if a `pyproject.toml` cannot be found, uv will exit with an error.
7995    Dir(WorkspaceDirArgs),
7996    /// List the members of a workspace.
7997    ///
7998    /// Displays newline separated names of workspace members.
7999    #[command(hide = true)]
8000    List(WorkspaceListArgs),
8001}
8002#[derive(Args)]
8003pub struct MetadataArgs {
8004    /// Check if the lockfile is up-to-date [env: UV_LOCKED=]
8005    ///
8006    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
8007    /// missing or needs to be updated, uv will exit with an error.
8008    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
8009    pub locked: bool,
8010
8011    /// Assert that a `uv.lock` exists without checking if it is up-to-date [env: UV_FROZEN=]
8012    #[arg(long, conflicts_with_all = ["locked"])]
8013    pub frozen: bool,
8014
8015    /// Perform a dry run, without writing the lockfile.
8016    ///
8017    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
8018    /// changes, but will not write the lockfile to disk.
8019    #[arg(long, conflicts_with = "frozen", conflicts_with = "locked")]
8020    pub dry_run: bool,
8021
8022    #[command(flatten)]
8023    pub resolver: ResolverArgs,
8024
8025    #[command(flatten)]
8026    pub build: BuildOptionsArgs,
8027
8028    #[command(flatten)]
8029    pub refresh: RefreshArgs,
8030
8031    /// The Python interpreter to use during resolution.
8032    ///
8033    /// A Python interpreter is required for building source distributions to determine package
8034    /// metadata when there are not wheels.
8035    ///
8036    /// The interpreter is also used as the fallback value for the minimum Python version if
8037    /// `requires-python` is not set.
8038    ///
8039    /// See `uv help python` for details on Python discovery and supported request formats.
8040    #[arg(
8041        long,
8042        short,
8043        env = EnvVars::UV_PYTHON,
8044        verbatim_doc_comment,
8045        help_heading = "Python options",
8046        value_parser = parse_maybe_string,
8047        value_hint = ValueHint::Other,
8048    )]
8049    pub python: Option<Maybe<String>>,
8050}
8051
8052#[derive(Args, Debug)]
8053pub struct WorkspaceDirArgs {
8054    /// Display the path to a specific package in the workspace.
8055    #[arg(long, value_hint = ValueHint::Other)]
8056    pub package: Option<PackageName>,
8057}
8058
8059#[derive(Args, Debug)]
8060pub struct WorkspaceListArgs {
8061    /// Show paths instead of names.
8062    #[arg(long)]
8063    pub paths: bool,
8064}
8065
8066/// See [PEP 517](https://peps.python.org/pep-0517/) and
8067/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.
8068#[derive(Subcommand)]
8069pub enum BuildBackendCommand {
8070    /// PEP 517 hook `build_sdist`.
8071    BuildSdist { sdist_directory: PathBuf },
8072    /// PEP 517 hook `build_wheel`.
8073    BuildWheel {
8074        wheel_directory: PathBuf,
8075        #[arg(long)]
8076        metadata_directory: Option<PathBuf>,
8077    },
8078    /// PEP 660 hook `build_editable`.
8079    BuildEditable {
8080        wheel_directory: PathBuf,
8081        #[arg(long)]
8082        metadata_directory: Option<PathBuf>,
8083    },
8084    /// PEP 517 hook `get_requires_for_build_sdist`.
8085    GetRequiresForBuildSdist,
8086    /// PEP 517 hook `get_requires_for_build_wheel`.
8087    GetRequiresForBuildWheel,
8088    /// PEP 517 hook `prepare_metadata_for_build_wheel`.
8089    PrepareMetadataForBuildWheel { wheel_directory: PathBuf },
8090    /// PEP 660 hook `get_requires_for_build_editable`.
8091    GetRequiresForBuildEditable,
8092    /// PEP 660 hook `prepare_metadata_for_build_editable`.
8093    PrepareMetadataForBuildEditable { wheel_directory: PathBuf },
8094}