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