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