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