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