Skip to main content

uv_cli/
lib.rs

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