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