Skip to main content

uv_cli/
lib.rs

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