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