uv_cli/
lib.rs

1use std::ffi::OsString;
2use std::fmt::{self, Display, Formatter};
3use std::ops::{Deref, DerefMut};
4use std::path::PathBuf;
5use std::str::FromStr;
6
7use anyhow::{Result, anyhow};
8use clap::ValueEnum;
9use clap::builder::styling::{AnsiColor, Effects, Style};
10use clap::builder::{PossibleValue, Styles, TypedValueParser, ValueParserFactory};
11use clap::error::ErrorKind;
12use clap::{Args, Parser, Subcommand};
13
14use uv_auth::Service;
15use uv_cache::CacheArgs;
16use uv_configuration::{
17    ExportFormat, IndexStrategy, KeyringProviderType, PackageNameSpecifier, PipCompileFormat,
18    ProjectBuildBackend, TargetTriple, TrustedHost, TrustedPublishing, VersionControlSystem,
19};
20use uv_distribution_types::{
21    ConfigSettingEntry, ConfigSettingPackageEntry, Index, IndexUrl, Origin, PipExtraIndex,
22    PipFindLinks, PipIndex,
23};
24use uv_normalize::{ExtraName, GroupName, PackageName, PipGroupName};
25use uv_pep508::{MarkerTree, Requirement};
26use uv_preview::PreviewFeatures;
27use uv_pypi_types::VerbatimParsedUrl;
28use uv_python::{PythonDownloads, PythonPreference, PythonVersion};
29use uv_redacted::DisplaySafeUrl;
30use uv_resolver::{
31    AnnotationStyle, ExcludeNewerPackageEntry, ExcludeNewerTimestamp, ForkStrategy, PrereleaseMode,
32    ResolutionMode,
33};
34use uv_settings::PythonInstallMirrors;
35use uv_static::EnvVars;
36use uv_torch::TorchMode;
37use uv_workspace::pyproject_mut::AddBoundsKind;
38
39pub mod comma;
40pub mod compat;
41pub mod options;
42pub mod version;
43
44#[derive(Debug, Clone, Copy, clap::ValueEnum)]
45pub enum VersionFormat {
46    /// Display the version as plain text.
47    Text,
48    /// Display the version as JSON.
49    Json,
50}
51
52#[derive(Debug, Default, Clone, Copy, clap::ValueEnum)]
53pub enum PythonListFormat {
54    /// Plain text (for humans).
55    #[default]
56    Text,
57    /// JSON (for computers).
58    Json,
59}
60
61#[derive(Debug, Default, Clone, Copy, clap::ValueEnum)]
62pub enum SyncFormat {
63    /// Display the result in a human-readable format.
64    #[default]
65    Text,
66    /// Display the result in JSON format.
67    Json,
68}
69
70#[derive(Debug, Default, Clone, clap::ValueEnum)]
71pub enum ListFormat {
72    /// Display the list of packages in a human-readable table.
73    #[default]
74    Columns,
75    /// Display the list of packages in a `pip freeze`-like format, with one package per line
76    /// alongside its version.
77    Freeze,
78    /// Display the list of packages in a machine-readable JSON format.
79    Json,
80}
81
82fn extra_name_with_clap_error(arg: &str) -> Result<ExtraName> {
83    ExtraName::from_str(arg).map_err(|_err| {
84        anyhow!(
85            "Extra names must start and end with a letter or digit and may only \
86            contain -, _, ., and alphanumeric characters"
87        )
88    })
89}
90
91// Configures Clap v3-style help menu colors
92const STYLES: Styles = Styles::styled()
93    .header(AnsiColor::Green.on_default().effects(Effects::BOLD))
94    .usage(AnsiColor::Green.on_default().effects(Effects::BOLD))
95    .literal(AnsiColor::Cyan.on_default().effects(Effects::BOLD))
96    .placeholder(AnsiColor::Cyan.on_default());
97
98#[derive(Parser)]
99#[command(name = "uv", author, long_version = crate::version::uv_self_version())]
100#[command(about = "An extremely fast Python package manager.")]
101#[command(
102    after_help = "Use `uv help` for more details.",
103    after_long_help = "",
104    disable_help_flag = true,
105    disable_help_subcommand = true,
106    disable_version_flag = true
107)]
108#[command(styles=STYLES)]
109pub struct Cli {
110    #[command(subcommand)]
111    pub command: Box<Commands>,
112
113    #[command(flatten)]
114    pub top_level: TopLevelArgs,
115}
116
117#[derive(Parser)]
118#[command(disable_help_flag = true, disable_version_flag = true)]
119pub struct TopLevelArgs {
120    #[command(flatten)]
121    pub cache_args: Box<CacheArgs>,
122
123    #[command(flatten)]
124    pub global_args: Box<GlobalArgs>,
125
126    /// The path to a `uv.toml` file to use for configuration.
127    ///
128    /// While uv configuration can be included in a `pyproject.toml` file, it is
129    /// not allowed in this context.
130    #[arg(
131        global = true,
132        long,
133        env = EnvVars::UV_CONFIG_FILE,
134        help_heading = "Global options"
135    )]
136    pub config_file: Option<PathBuf>,
137
138    /// Avoid discovering configuration files (`pyproject.toml`, `uv.toml`).
139    ///
140    /// Normally, configuration files are discovered in the current directory,
141    /// parent directories, or user configuration directories.
142    #[arg(global = true, long, env = EnvVars::UV_NO_CONFIG, value_parser = clap::builder::BoolishValueParser::new(), help_heading = "Global options")]
143    pub no_config: bool,
144
145    /// Display the concise help for this command.
146    #[arg(global = true, short, long, action = clap::ArgAction::HelpShort, help_heading = "Global options")]
147    help: Option<bool>,
148
149    /// Display the uv version.
150    #[arg(short = 'V', long, action = clap::ArgAction::Version)]
151    version: Option<bool>,
152}
153
154#[derive(Parser, Debug, Clone)]
155#[command(next_help_heading = "Global options", next_display_order = 1000)]
156pub struct GlobalArgs {
157    #[arg(
158        global = true,
159        long,
160        help_heading = "Python options",
161        display_order = 700,
162        env = EnvVars::UV_PYTHON_PREFERENCE,
163        hide = true
164    )]
165    pub python_preference: Option<PythonPreference>,
166
167    /// Require use of uv-managed Python versions.
168    ///
169    /// By default, uv prefers using Python versions it manages. However, it
170    /// will use system Python versions if a uv-managed Python is not
171    /// installed. This option disables use of system Python versions.
172    #[arg(
173        global = true,
174        long,
175        help_heading = "Python options",
176        env = EnvVars::UV_MANAGED_PYTHON,
177        value_parser = clap::builder::BoolishValueParser::new(),
178        overrides_with = "no_managed_python",
179        conflicts_with = "python_preference"
180    )]
181    pub managed_python: bool,
182
183    /// Disable use of uv-managed Python versions.
184    ///
185    /// Instead, uv will search for a suitable Python version on the system.
186    #[arg(
187        global = true,
188        long,
189        help_heading = "Python options",
190        env = EnvVars::UV_NO_MANAGED_PYTHON,
191        value_parser = clap::builder::BoolishValueParser::new(),
192        overrides_with = "managed_python",
193        conflicts_with = "python_preference"
194    )]
195    pub no_managed_python: bool,
196
197    #[allow(clippy::doc_markdown)]
198    /// Allow automatically downloading Python when required. [env: "UV_PYTHON_DOWNLOADS=auto"]
199    #[arg(global = true, long, help_heading = "Python options", hide = true)]
200    pub allow_python_downloads: bool,
201
202    #[allow(clippy::doc_markdown)]
203    /// Disable automatic downloads of Python. [env: "UV_PYTHON_DOWNLOADS=never"]
204    #[arg(global = true, long, help_heading = "Python options")]
205    pub no_python_downloads: bool,
206
207    /// Deprecated version of [`Self::python_downloads`].
208    #[arg(global = true, long, hide = true)]
209    pub python_fetch: Option<PythonDownloads>,
210
211    /// Use quiet output.
212    ///
213    /// Repeating this option, e.g., `-qq`, will enable a silent mode in which
214    /// uv will write no output to stdout.
215    #[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "verbose")]
216    pub quiet: u8,
217
218    /// Use verbose output.
219    ///
220    /// You can configure fine-grained logging using the `RUST_LOG` environment variable.
221    /// (<https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives>)
222    #[arg(global = true, action = clap::ArgAction::Count, long, short, conflicts_with = "quiet")]
223    pub verbose: u8,
224
225    /// Disable colors.
226    ///
227    /// Provided for compatibility with `pip`, use `--color` instead.
228    #[arg(global = true, long, hide = true, conflicts_with = "color")]
229    pub no_color: bool,
230
231    /// Control the use of color in output.
232    ///
233    /// By default, uv will automatically detect support for colors when writing to a terminal.
234    #[arg(
235        global = true,
236        long,
237        value_enum,
238        conflicts_with = "no_color",
239        value_name = "COLOR_CHOICE"
240    )]
241    pub color: Option<ColorChoice>,
242
243    /// Whether to load TLS certificates from the platform's native certificate store.
244    ///
245    /// By default, uv loads certificates from the bundled `webpki-roots` crate. The
246    /// `webpki-roots` are a reliable set of trust roots from Mozilla, and including them in uv
247    /// improves portability and performance (especially on macOS).
248    ///
249    /// However, in some cases, you may want to use the platform's native certificate store,
250    /// especially if you're relying on a corporate trust root (e.g., for a mandatory proxy) that's
251    /// included in your system's certificate store.
252    #[arg(global = true, long, env = EnvVars::UV_NATIVE_TLS, value_parser = clap::builder::BoolishValueParser::new(), overrides_with("no_native_tls"))]
253    pub native_tls: bool,
254
255    #[arg(global = true, long, overrides_with("native_tls"), hide = true)]
256    pub no_native_tls: bool,
257
258    /// Disable network access.
259    ///
260    /// When disabled, uv will only use locally cached data and locally available files.
261    #[arg(global = true, long, overrides_with("no_offline"), env = EnvVars::UV_OFFLINE, value_parser = clap::builder::BoolishValueParser::new())]
262    pub offline: bool,
263
264    #[arg(global = true, long, overrides_with("offline"), hide = true)]
265    pub no_offline: bool,
266
267    /// Allow insecure connections to a host.
268    ///
269    /// Can be provided multiple times.
270    ///
271    /// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
272    /// `localhost:8080`), or a URL (e.g., `https://localhost`).
273    ///
274    /// WARNING: Hosts included in this list will not be verified against the system's certificate
275    /// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
276    /// bypasses SSL verification and could expose you to MITM attacks.
277    #[arg(
278        global = true,
279        long,
280        alias = "trusted-host",
281        env = EnvVars::UV_INSECURE_HOST,
282        value_delimiter = ' ',
283        value_parser = parse_insecure_host,
284    )]
285    pub allow_insecure_host: Option<Vec<Maybe<TrustedHost>>>,
286
287    /// Whether to enable all experimental preview features.
288    ///
289    /// Preview features may change without warning.
290    #[arg(global = true, long, hide = true, env = EnvVars::UV_PREVIEW, value_parser = clap::builder::BoolishValueParser::new(), overrides_with("no_preview"))]
291    pub preview: bool,
292
293    #[arg(global = true, long, overrides_with("preview"), hide = true)]
294    pub no_preview: bool,
295
296    /// Enable experimental preview features.
297    ///
298    /// Preview features may change without warning.
299    ///
300    /// Use comma-separated values or pass multiple times to enable multiple features.
301    ///
302    /// The following features are available: `python-install-default`, `python-upgrade`,
303    /// `json-output`, `pylock`, `add-bounds`.
304    #[arg(
305        global = true,
306        long = "preview-features",
307        env = EnvVars::UV_PREVIEW_FEATURES,
308        value_delimiter = ',',
309        hide = true,
310        alias = "preview-feature",
311        value_enum,
312    )]
313    pub preview_features: Vec<PreviewFeatures>,
314
315    /// Avoid discovering a `pyproject.toml` or `uv.toml` file.
316    ///
317    /// Normally, configuration files are discovered in the current directory,
318    /// parent directories, or user configuration directories.
319    ///
320    /// This option is deprecated in favor of `--no-config`.
321    #[arg(global = true, long, hide = true, env = EnvVars::UV_ISOLATED, value_parser = clap::builder::BoolishValueParser::new())]
322    pub isolated: bool,
323
324    /// Show the resolved settings for the current command.
325    ///
326    /// This option is used for debugging and development purposes.
327    #[arg(global = true, long, hide = true)]
328    pub show_settings: bool,
329
330    /// Hide all progress outputs.
331    ///
332    /// For example, spinners or progress bars.
333    #[arg(global = true, long, env = EnvVars::UV_NO_PROGRESS, value_parser = clap::builder::BoolishValueParser::new())]
334    pub no_progress: bool,
335
336    /// Skip writing `uv` installer metadata files (e.g., `INSTALLER`, `REQUESTED`, and `direct_url.json`) to site-packages `.dist-info` directories.
337    #[arg(global = true, long, hide = true, env = EnvVars::UV_NO_INSTALLER_METADATA, value_parser = clap::builder::BoolishValueParser::new())]
338    pub no_installer_metadata: bool,
339
340    /// Change to the given directory prior to running the command.
341    ///
342    /// Relative paths are resolved with the given directory as the base.
343    ///
344    /// See `--project` to only change the project root directory.
345    #[arg(global = true, long, env = EnvVars::UV_WORKING_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 both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
3087    /// format (e.g., `2006-12-02`) in your system's configured time zone.
3088    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER)]
3089    pub exclude_newer: Option<ExcludeNewerTimestamp>,
3090
3091    /// Limit candidate packages for a specific package to those that were uploaded prior to the given date.
3092    ///
3093    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339 timestamp
3094    /// (e.g., `2006-12-02T02:07:43Z`) or local date (e.g., `2006-12-02`) in your system's configured time zone.
3095    ///
3096    /// Can be provided multiple times for different packages.
3097    #[arg(long)]
3098    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
3099
3100    /// The method to use when installing packages from the global cache.
3101    ///
3102    /// This option is only used for installing seed packages.
3103    ///
3104    /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
3105    /// Windows.
3106    ///
3107    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
3108    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
3109    /// will break all installed packages by way of removing the underlying source files. Use
3110    /// symlinks with caution.
3111    #[arg(long, value_enum, env = EnvVars::UV_LINK_MODE)]
3112    pub link_mode: Option<uv_install_wheel::LinkMode>,
3113
3114    #[command(flatten)]
3115    pub refresh: RefreshArgs,
3116
3117    #[command(flatten)]
3118    pub compat_args: compat::VenvCompatArgs,
3119}
3120
3121#[derive(Parser, Debug, Clone)]
3122pub enum ExternalCommand {
3123    #[command(external_subcommand)]
3124    Cmd(Vec<OsString>),
3125}
3126
3127impl Deref for ExternalCommand {
3128    type Target = Vec<OsString>;
3129
3130    fn deref(&self) -> &Self::Target {
3131        match self {
3132            Self::Cmd(cmd) => cmd,
3133        }
3134    }
3135}
3136
3137impl DerefMut for ExternalCommand {
3138    fn deref_mut(&mut self) -> &mut Self::Target {
3139        match self {
3140            Self::Cmd(cmd) => cmd,
3141        }
3142    }
3143}
3144
3145impl ExternalCommand {
3146    pub fn split(&self) -> (Option<&OsString>, &[OsString]) {
3147        match self.as_slice() {
3148            [] => (None, &[]),
3149            [cmd, args @ ..] => (Some(cmd), args),
3150        }
3151    }
3152}
3153
3154#[derive(Debug, Default, Copy, Clone, clap::ValueEnum)]
3155pub enum AuthorFrom {
3156    /// Fetch the author information from some sources (e.g., Git) automatically.
3157    #[default]
3158    Auto,
3159    /// Fetch the author information from Git configuration only.
3160    Git,
3161    /// Do not infer the author information.
3162    None,
3163}
3164
3165#[derive(Args)]
3166pub struct InitArgs {
3167    /// The path to use for the project/script.
3168    ///
3169    /// Defaults to the current working directory when initializing an app or library; required when
3170    /// initializing a script. Accepts relative and absolute paths.
3171    ///
3172    /// If a `pyproject.toml` is found in any of the parent directories of the target path, the
3173    /// project will be added as a workspace member of the parent, unless `--no-workspace` is
3174    /// provided.
3175    #[arg(required_if_eq("script", "true"))]
3176    pub path: Option<PathBuf>,
3177
3178    /// The name of the project.
3179    ///
3180    /// Defaults to the name of the directory.
3181    #[arg(long, conflicts_with = "script")]
3182    pub name: Option<PackageName>,
3183
3184    /// Only create a `pyproject.toml`.
3185    ///
3186    /// Disables creating extra files like `README.md`, the `src/` tree, `.python-version` files,
3187    /// etc.
3188    #[arg(long, conflicts_with = "script")]
3189    pub bare: bool,
3190
3191    /// Create a virtual project, rather than a package.
3192    ///
3193    /// This option is deprecated and will be removed in a future release.
3194    #[arg(long, hide = true, conflicts_with = "package")]
3195    pub r#virtual: bool,
3196
3197    /// Set up the project to be built as a Python package.
3198    ///
3199    /// Defines a `[build-system]` for the project.
3200    ///
3201    /// This is the default behavior when using `--lib` or `--build-backend`.
3202    ///
3203    /// When using `--app`, this will include a `[project.scripts]` entrypoint and use a `src/`
3204    /// project structure.
3205    #[arg(long, overrides_with = "no_package")]
3206    pub r#package: bool,
3207
3208    /// Do not set up the project to be built as a Python package.
3209    ///
3210    /// Does not include a `[build-system]` for the project.
3211    ///
3212    /// This is the default behavior when using `--app`.
3213    #[arg(long, overrides_with = "package", conflicts_with_all = ["lib", "build_backend"])]
3214    pub r#no_package: bool,
3215
3216    /// Create a project for an application.
3217    ///
3218    /// This is the default behavior if `--lib` is not requested.
3219    ///
3220    /// This project kind is for web servers, scripts, and command-line interfaces.
3221    ///
3222    /// By default, an application is not intended to be built and distributed as a Python package.
3223    /// The `--package` option can be used to create an application that is distributable, e.g., if
3224    /// you want to distribute a command-line interface via PyPI.
3225    #[arg(long, alias = "application", conflicts_with_all = ["lib", "script"])]
3226    pub r#app: bool,
3227
3228    /// Create a project for a library.
3229    ///
3230    /// A library is a project that is intended to be built and distributed as a Python package.
3231    #[arg(long, alias = "library", conflicts_with_all=["app", "script"])]
3232    pub r#lib: bool,
3233
3234    /// Create a script.
3235    ///
3236    /// A script is a standalone file with embedded metadata enumerating its dependencies, along
3237    /// with any Python version requirements, as defined in the PEP 723 specification.
3238    ///
3239    /// PEP 723 scripts can be executed directly with `uv run`.
3240    ///
3241    /// By default, adds a requirement on the system Python version; use `--python` to specify an
3242    /// alternative Python version requirement.
3243    #[arg(long, conflicts_with_all=["app", "lib", "package", "build_backend", "description"])]
3244    pub r#script: bool,
3245
3246    /// Set the project description.
3247    #[arg(long, conflicts_with = "script", overrides_with = "no_description")]
3248    pub description: Option<String>,
3249
3250    /// Disable the description for the project.
3251    #[arg(long, conflicts_with = "script", overrides_with = "description")]
3252    pub no_description: bool,
3253
3254    /// Initialize a version control system for the project.
3255    ///
3256    /// By default, uv will initialize a Git repository (`git`). Use `--vcs none` to explicitly
3257    /// avoid initializing a version control system.
3258    #[arg(long, value_enum, conflicts_with = "script")]
3259    pub vcs: Option<VersionControlSystem>,
3260
3261    /// Initialize a build-backend of choice for the project.
3262    ///
3263    /// Implicitly sets `--package`.
3264    #[arg(long, value_enum, conflicts_with_all=["script", "no_package"], env = EnvVars::UV_INIT_BUILD_BACKEND)]
3265    pub build_backend: Option<ProjectBuildBackend>,
3266
3267    /// Invalid option name for build backend.
3268    #[arg(
3269        long,
3270        required(false),
3271        action(clap::ArgAction::SetTrue),
3272        value_parser=clap::builder::UnknownArgumentValueParser::suggest_arg("--build-backend"),
3273        hide(true)
3274    )]
3275    backend: Option<String>,
3276
3277    /// Do not create a `README.md` file.
3278    #[arg(long)]
3279    pub no_readme: bool,
3280
3281    /// Fill in the `authors` field in the `pyproject.toml`.
3282    ///
3283    /// By default, uv will attempt to infer the author information from some sources (e.g., Git)
3284    /// (`auto`). Use `--author-from git` to only infer from Git configuration. Use `--author-from
3285    /// none` to avoid inferring the author information.
3286    #[arg(long, value_enum)]
3287    pub author_from: Option<AuthorFrom>,
3288
3289    /// Do not create a `.python-version` file for the project.
3290    ///
3291    /// By default, uv will create a `.python-version` file containing the minor version of the
3292    /// discovered Python interpreter, which will cause subsequent uv commands to use that version.
3293    #[arg(long)]
3294    pub no_pin_python: bool,
3295
3296    /// Create a `.python-version` file for the project.
3297    ///
3298    /// This is the default.
3299    #[arg(long, hide = true)]
3300    pub pin_python: bool,
3301
3302    /// Avoid discovering a workspace and create a standalone project.
3303    ///
3304    /// By default, uv searches for workspaces in the current directory or any parent directory.
3305    #[arg(long, alias = "no-project")]
3306    pub no_workspace: bool,
3307
3308    /// The Python interpreter to use to determine the minimum supported Python version.
3309    ///
3310    /// See `uv help python` to view supported request formats.
3311    #[arg(
3312        long,
3313        short,
3314        env = EnvVars::UV_PYTHON,
3315        verbatim_doc_comment,
3316        help_heading = "Python options",
3317        value_parser = parse_maybe_string,
3318    )]
3319    pub python: Option<Maybe<String>>,
3320}
3321
3322#[derive(Args)]
3323pub struct RunArgs {
3324    /// Include optional dependencies from the specified extra name.
3325    ///
3326    /// May be provided more than once.
3327    ///
3328    /// Optional dependencies are defined via `project.optional-dependencies` in a `pyproject.toml`.
3329    ///
3330    /// This option is only available when running in a project.
3331    #[arg(long, conflicts_with = "all_extras", conflicts_with = "only_group", value_parser = extra_name_with_clap_error)]
3332    pub extra: Option<Vec<ExtraName>>,
3333
3334    /// Include all optional dependencies.
3335    ///
3336    /// Optional dependencies are defined via `project.optional-dependencies` in a `pyproject.toml`.
3337    ///
3338    /// This option is only available when running in a project.
3339    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3340    pub all_extras: bool,
3341
3342    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3343    ///
3344    /// May be provided multiple times.
3345    #[arg(long)]
3346    pub no_extra: Vec<ExtraName>,
3347
3348    #[arg(long, overrides_with("all_extras"), hide = true)]
3349    pub no_all_extras: bool,
3350
3351    /// Include the development dependency group.
3352    ///
3353    /// Development dependencies are defined via `dependency-groups.dev` or
3354    /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
3355    ///
3356    /// This option is an alias for `--group dev`.
3357    ///
3358    /// This option is only available when running in a project.
3359    #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3360    pub dev: bool,
3361
3362    /// Disable the development dependency group.
3363    ///
3364    /// This option is an alias of `--no-group dev`.
3365    /// See `--no-default-groups` to disable all default groups instead.
3366    ///
3367    /// This option is only available when running in a project.
3368    #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3369    pub no_dev: bool,
3370
3371    /// Include dependencies from the specified dependency group.
3372    ///
3373    /// May be provided multiple times.
3374    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3375    pub group: Vec<GroupName>,
3376
3377    /// Disable the specified dependency group.
3378    ///
3379    /// This option always takes precedence over default groups,
3380    /// `--all-groups`, and `--group`.
3381    ///
3382    /// May be provided multiple times.
3383    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
3384    pub no_group: Vec<GroupName>,
3385
3386    /// Ignore the default dependency groups.
3387    ///
3388    /// uv includes the groups defined in `tool.uv.default-groups` by default.
3389    /// This disables that option, however, specific groups can still be included with `--group`.
3390    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
3391    pub no_default_groups: bool,
3392
3393    /// Only include dependencies from the specified dependency group.
3394    ///
3395    /// The project and its dependencies will be omitted.
3396    ///
3397    /// May be provided multiple times. Implies `--no-default-groups`.
3398    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
3399    pub only_group: Vec<GroupName>,
3400
3401    /// Include dependencies from all dependency groups.
3402    ///
3403    /// `--no-group` can be used to exclude specific groups.
3404    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3405    pub all_groups: bool,
3406
3407    /// Run a Python module.
3408    ///
3409    /// Equivalent to `python -m <module>`.
3410    #[arg(short, long, conflicts_with_all = ["script", "gui_script"])]
3411    pub module: bool,
3412
3413    /// Only include the development dependency group.
3414    ///
3415    /// The project and its dependencies will be omitted.
3416    ///
3417    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3418    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3419    pub only_dev: bool,
3420
3421    /// Install any non-editable dependencies, including the project and any workspace members, as
3422    /// editable.
3423    #[arg(long, overrides_with = "no_editable", hide = true)]
3424    pub editable: bool,
3425
3426    /// Install any editable dependencies, including the project and any workspace members, as
3427    /// non-editable.
3428    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
3429    pub no_editable: bool,
3430
3431    /// Do not remove extraneous packages present in the environment.
3432    #[arg(long, overrides_with("exact"), alias = "no-exact", hide = true)]
3433    pub inexact: bool,
3434
3435    /// Perform an exact sync, removing extraneous packages.
3436    ///
3437    /// When enabled, uv will remove any extraneous packages from the environment. By default, `uv
3438    /// run` will make the minimum necessary changes to satisfy the requirements.
3439    #[arg(long, overrides_with("inexact"))]
3440    pub exact: bool,
3441
3442    /// Load environment variables from a `.env` file.
3443    ///
3444    /// Can be provided multiple times, with subsequent files overriding values defined in previous
3445    /// files.
3446    #[arg(long, env = EnvVars::UV_ENV_FILE)]
3447    pub env_file: Vec<String>,
3448
3449    /// Avoid reading environment variables from a `.env` file.
3450    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_ENV_FILE)]
3451    pub no_env_file: bool,
3452
3453    /// The command to run.
3454    ///
3455    /// If the path to a Python script (i.e., ending in `.py`), it will be
3456    /// executed with the Python interpreter.
3457    #[command(subcommand)]
3458    pub command: Option<ExternalCommand>,
3459
3460    /// Run with the given packages installed.
3461    ///
3462    /// When used in a project, these dependencies will be layered on top of the project environment
3463    /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3464    /// specified by the project.
3465    #[arg(short = 'w', long)]
3466    pub with: Vec<comma::CommaSeparatedRequirements>,
3467
3468    /// Run with the given packages installed in editable mode.
3469    ///
3470    /// When used in a project, these dependencies will be layered on top of the project environment
3471    /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3472    /// specified by the project.
3473    #[arg(long)]
3474    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
3475
3476    /// Run with the packages listed in the given files.
3477    ///
3478    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
3479    /// and `pylock.toml`.
3480    ///
3481    /// The same environment semantics as `--with` apply.
3482    ///
3483    /// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed.
3484    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path)]
3485    pub with_requirements: Vec<Maybe<PathBuf>>,
3486
3487    /// Run the command in an isolated virtual environment.
3488    ///
3489    /// Usually, the project environment is reused for performance. This option forces a fresh
3490    /// environment to be used for the project, enforcing strict isolation between dependencies and
3491    /// declaration of requirements.
3492    ///
3493    /// An editable installation is still used for the project.
3494    ///
3495    /// When used with `--with` or `--with-requirements`, the additional dependencies will still be
3496    /// layered in a second environment.
3497    #[arg(long, env = EnvVars::UV_ISOLATED, value_parser = clap::builder::BoolishValueParser::new())]
3498    pub isolated: bool,
3499
3500    /// Prefer the active virtual environment over the project's virtual environment.
3501    ///
3502    /// If the project virtual environment is active or no virtual environment is active, this has
3503    /// no effect.
3504    #[arg(long, overrides_with = "no_active")]
3505    pub active: bool,
3506
3507    /// Prefer project's virtual environment over an active environment.
3508    ///
3509    /// This is the default behavior.
3510    #[arg(long, overrides_with = "active", hide = true)]
3511    pub no_active: bool,
3512
3513    /// Avoid syncing the virtual environment.
3514    ///
3515    /// Implies `--frozen`, as the project dependencies will be ignored (i.e., the lockfile will not
3516    /// be updated, since the environment will not be synced regardless).
3517    #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new())]
3518    pub no_sync: bool,
3519
3520    /// Assert that the `uv.lock` will remain unchanged.
3521    ///
3522    /// Requires that the lockfile is up-to-date. If the lockfile is missing or
3523    /// needs to be updated, uv will exit with an error.
3524    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
3525    pub locked: bool,
3526
3527    /// Run without updating the `uv.lock` file.
3528    ///
3529    /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3530    /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3531    /// `pyproject.toml` includes changes to dependencies that have not been included in the
3532    /// lockfile yet, they will not be present in the environment.
3533    #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3534    pub frozen: bool,
3535
3536    /// Run the given path as a Python script.
3537    ///
3538    /// Using `--script` will attempt to parse the path as a PEP 723 script,
3539    /// irrespective of its extension.
3540    #[arg(long, short, conflicts_with_all = ["module", "gui_script"])]
3541    pub script: bool,
3542
3543    /// Run the given path as a Python GUI script.
3544    ///
3545    /// Using `--gui-script` will attempt to parse the path as a PEP 723 script and run it with
3546    /// `pythonw.exe`, irrespective of its extension. Only available on Windows.
3547    #[arg(long, conflicts_with_all = ["script", "module"])]
3548    pub gui_script: bool,
3549
3550    #[command(flatten)]
3551    pub installer: ResolverInstallerArgs,
3552
3553    #[command(flatten)]
3554    pub build: BuildOptionsArgs,
3555
3556    #[command(flatten)]
3557    pub refresh: RefreshArgs,
3558
3559    /// Run the command with all workspace members installed.
3560    ///
3561    /// The workspace's environment (`.venv`) is updated to include all workspace members.
3562    ///
3563    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
3564    /// to all workspace members.
3565    #[arg(long, conflicts_with = "package")]
3566    pub all_packages: bool,
3567
3568    /// Run the command in a specific package in the workspace.
3569    ///
3570    /// If the workspace member does not exist, uv will exit with an error.
3571    #[arg(long, conflicts_with = "all_packages")]
3572    pub package: Option<PackageName>,
3573
3574    /// Avoid discovering the project or workspace.
3575    ///
3576    /// Instead of searching for projects in the current directory and parent directories, run in an
3577    /// isolated, ephemeral environment populated by the `--with` requirements.
3578    ///
3579    /// If a virtual environment is active or found in a current or parent directory, it will be
3580    /// used as if there was no project or workspace.
3581    #[arg(long, alias = "no_workspace", conflicts_with = "package")]
3582    pub no_project: bool,
3583
3584    /// The Python interpreter to use for the run environment.
3585    ///
3586    /// If the interpreter request is satisfied by a discovered environment, the environment will be
3587    /// used.
3588    ///
3589    /// See `uv help python` to view supported request formats.
3590    #[arg(
3591        long,
3592        short,
3593        env = EnvVars::UV_PYTHON,
3594        verbatim_doc_comment,
3595        help_heading = "Python options",
3596        value_parser = parse_maybe_string,
3597    )]
3598    pub python: Option<Maybe<String>>,
3599
3600    /// Whether to show resolver and installer output from any environment modifications.
3601    ///
3602    /// By default, environment modifications are omitted, but enabled under `--verbose`.
3603    #[arg(long, env = EnvVars::UV_SHOW_RESOLUTION, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
3604    pub show_resolution: bool,
3605
3606    /// Number of times that `uv run` will allow recursive invocations.
3607    ///
3608    /// The current recursion depth is tracked by environment variable. If environment variables are
3609    /// cleared, uv will fail to detect the recursion depth.
3610    ///
3611    /// If uv reaches the maximum recursion depth, it will exit with an error.
3612    #[arg(long, hide = true, env = EnvVars::UV_RUN_MAX_RECURSION_DEPTH)]
3613    pub max_recursion_depth: Option<u32>,
3614
3615    /// The platform for which requirements should be installed.
3616    ///
3617    /// Represented as a "target triple", a string that describes the target platform in terms of
3618    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
3619    /// `aarch64-apple-darwin`.
3620    ///
3621    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
3622    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3623    ///
3624    /// When targeting iOS, the default minimum version is `13.0`. Use
3625    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3626    ///
3627    /// When targeting Android, the default minimum Android API level is `24`. Use
3628    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
3629    ///
3630    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
3631    /// platform; as a result, the installed distributions may not be compatible with the _current_
3632    /// platform. Conversely, any distributions that are built from source may be incompatible with
3633    /// the _target_ platform, as they will be built for the _current_ platform. The
3634    /// `--python-platform` option is intended for advanced use cases.
3635    #[arg(long)]
3636    pub python_platform: Option<TargetTriple>,
3637}
3638
3639#[derive(Args)]
3640pub struct SyncArgs {
3641    /// Include optional dependencies from the specified extra name.
3642    ///
3643    /// May be provided more than once.
3644    ///
3645    /// When multiple extras or groups are specified that appear in `tool.uv.conflicts`, uv will
3646    /// report an error.
3647    ///
3648    /// Note that all optional dependencies are always included in the resolution; this option only
3649    /// affects the selection of packages to install.
3650    #[arg(long, conflicts_with = "all_extras", conflicts_with = "only_group", value_parser = extra_name_with_clap_error)]
3651    pub extra: Option<Vec<ExtraName>>,
3652
3653    /// Select the output format.
3654    #[arg(long, value_enum, default_value_t = SyncFormat::default())]
3655    pub output_format: SyncFormat,
3656
3657    /// Include all optional dependencies.
3658    ///
3659    /// When two or more extras are declared as conflicting in `tool.uv.conflicts`, using this flag
3660    /// will always result in 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 = "extra", conflicts_with = "only_group")]
3665    pub all_extras: bool,
3666
3667    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3668    ///
3669    /// May be provided multiple times.
3670    #[arg(long)]
3671    pub no_extra: Vec<ExtraName>,
3672
3673    #[arg(long, overrides_with("all_extras"), hide = true)]
3674    pub no_all_extras: bool,
3675
3676    /// Include the development dependency group.
3677    ///
3678    /// This option is an alias for `--group dev`.
3679    #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3680    pub dev: bool,
3681
3682    /// Disable the development dependency group.
3683    ///
3684    /// This option is an alias of `--no-group dev`.
3685    /// See `--no-default-groups` to disable all default groups instead.
3686    #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
3687    pub no_dev: bool,
3688
3689    /// Only include the development dependency group.
3690    ///
3691    /// The project and its dependencies will be omitted.
3692    ///
3693    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3694    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3695    pub only_dev: bool,
3696
3697    /// Include dependencies from the specified dependency group.
3698    ///
3699    /// When multiple extras or groups are specified that appear in
3700    /// `tool.uv.conflicts`, uv will report an error.
3701    ///
3702    /// May be provided multiple times.
3703    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3704    pub group: Vec<GroupName>,
3705
3706    /// Disable the specified dependency group.
3707    ///
3708    /// This option always takes precedence over default groups,
3709    /// `--all-groups`, and `--group`.
3710    ///
3711    /// May be provided multiple times.
3712    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
3713    pub no_group: Vec<GroupName>,
3714
3715    /// Ignore the default dependency groups.
3716    ///
3717    /// uv includes the groups defined in `tool.uv.default-groups` by default.
3718    /// This disables that option, however, specific groups can still be included with `--group`.
3719    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
3720    pub no_default_groups: bool,
3721
3722    /// Only include dependencies from the specified dependency group.
3723    ///
3724    /// The project and its dependencies will be omitted.
3725    ///
3726    /// May be provided multiple times. Implies `--no-default-groups`.
3727    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
3728    pub only_group: Vec<GroupName>,
3729
3730    /// Include dependencies from all dependency groups.
3731    ///
3732    /// `--no-group` can be used to exclude specific groups.
3733    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3734    pub all_groups: bool,
3735
3736    /// Install any non-editable dependencies, including the project and any workspace members, as
3737    /// editable.
3738    #[arg(long, overrides_with = "no_editable", hide = true)]
3739    pub editable: bool,
3740
3741    /// Install any editable dependencies, including the project and any workspace members, as
3742    /// non-editable.
3743    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
3744    pub no_editable: bool,
3745
3746    /// Do not remove extraneous packages present in the environment.
3747    ///
3748    /// When enabled, uv will make the minimum necessary changes to satisfy the requirements.
3749    /// By default, syncing will remove any extraneous packages from the environment
3750    #[arg(long, overrides_with("exact"), alias = "no-exact")]
3751    pub inexact: bool,
3752
3753    /// Perform an exact sync, removing extraneous packages.
3754    #[arg(long, overrides_with("inexact"), hide = true)]
3755    pub exact: bool,
3756
3757    /// Sync dependencies to the active virtual environment.
3758    ///
3759    /// Instead of creating or updating the virtual environment for the project or script, the
3760    /// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
3761    /// set.
3762    #[arg(long, overrides_with = "no_active")]
3763    pub active: bool,
3764
3765    /// Prefer project's virtual environment over an active environment.
3766    ///
3767    /// This is the default behavior.
3768    #[arg(long, overrides_with = "active", hide = true)]
3769    pub no_active: bool,
3770
3771    /// Do not install the current project.
3772    ///
3773    /// By default, the current project is installed into the environment with all of its
3774    /// dependencies. The `--no-install-project` option allows the project to be excluded, but all
3775    /// of its dependencies are still installed. This is particularly useful in situations like
3776    /// building Docker images where installing the project separately from its dependencies allows
3777    /// optimal layer caching.
3778    ///
3779    /// The inverse `--only-install-project` can be used to install _only_ the project itself,
3780    /// excluding all dependencies.
3781    #[arg(long, conflicts_with = "only_install_project")]
3782    pub no_install_project: bool,
3783
3784    /// Only install the current project.
3785    #[arg(long, conflicts_with = "no_install_project", hide = true)]
3786    pub only_install_project: bool,
3787
3788    /// Do not install any workspace members, including the root project.
3789    ///
3790    /// By default, all workspace members and their dependencies are installed into the
3791    /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
3792    /// members while retaining their dependencies. This is particularly useful in situations like
3793    /// building Docker images where installing the workspace separately from its dependencies
3794    /// allows optimal layer caching.
3795    ///
3796    /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
3797    /// excluding all other dependencies.
3798    #[arg(long, conflicts_with = "only_install_workspace")]
3799    pub no_install_workspace: bool,
3800
3801    /// Only install workspace members, including the root project.
3802    #[arg(long, conflicts_with = "no_install_workspace", hide = true)]
3803    pub only_install_workspace: bool,
3804
3805    /// Do not install local path dependencies
3806    ///
3807    /// Skips the current project, workspace members, and any other local (path or editable)
3808    /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
3809    /// heavy third-party dependencies first and layer local packages separately.
3810    ///
3811    /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
3812    /// all remote dependencies.
3813    #[arg(long, conflicts_with = "only_install_local")]
3814    pub no_install_local: bool,
3815
3816    /// Only install local path dependencies
3817    #[arg(long, conflicts_with = "no_install_local", hide = true)]
3818    pub only_install_local: bool,
3819
3820    /// Do not install the given package(s).
3821    ///
3822    /// By default, all of the project's dependencies are installed into the environment. The
3823    /// `--no-install-package` option allows exclusion of specific packages. Note this can result
3824    /// in a broken environment, and should be used with caution.
3825    ///
3826    /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
3827    /// excluding all others.
3828    #[arg(long, conflicts_with = "only_install_package")]
3829    pub no_install_package: Vec<PackageName>,
3830
3831    /// Only install the given package(s).
3832    #[arg(long, conflicts_with = "no_install_package", hide = true)]
3833    pub only_install_package: Vec<PackageName>,
3834
3835    /// Assert that the `uv.lock` will remain unchanged.
3836    ///
3837    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
3838    /// uv will exit with an error.
3839    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
3840    pub locked: bool,
3841
3842    /// Sync without updating the `uv.lock` file.
3843    ///
3844    /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3845    /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3846    /// `pyproject.toml` includes changes to dependencies that have not been included in the
3847    /// lockfile yet, they will not be present in the environment.
3848    #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3849    pub frozen: bool,
3850
3851    /// Perform a dry run, without writing the lockfile or modifying the project environment.
3852    ///
3853    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
3854    /// changes to both the lockfile and the project environment, but will not modify either.
3855    #[arg(long)]
3856    pub dry_run: bool,
3857
3858    #[command(flatten)]
3859    pub installer: ResolverInstallerArgs,
3860
3861    #[command(flatten)]
3862    pub build: BuildOptionsArgs,
3863
3864    #[command(flatten)]
3865    pub refresh: RefreshArgs,
3866
3867    /// Sync all packages in the workspace.
3868    ///
3869    /// The workspace's environment (`.venv`) is updated to include all workspace members.
3870    ///
3871    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
3872    /// to all workspace members.
3873    #[arg(long, conflicts_with = "package")]
3874    pub all_packages: bool,
3875
3876    /// Sync for specific packages in the workspace.
3877    ///
3878    /// The workspace's environment (`.venv`) is updated to reflect the subset of dependencies
3879    /// declared by the specified workspace member packages.
3880    ///
3881    /// If any workspace member does not exist, uv will exit with an error.
3882    #[arg(long, conflicts_with = "all_packages")]
3883    pub package: Vec<PackageName>,
3884
3885    /// Sync the environment for a Python script, rather than the current project.
3886    ///
3887    /// If provided, uv will sync the dependencies based on the script's inline metadata table, in
3888    /// adherence with PEP 723.
3889    #[arg(
3890        long,
3891        conflicts_with = "all_packages",
3892        conflicts_with = "package",
3893        conflicts_with = "no_install_project",
3894        conflicts_with = "no_install_workspace",
3895        conflicts_with = "no_install_local",
3896        conflicts_with = "extra",
3897        conflicts_with = "all_extras",
3898        conflicts_with = "no_extra",
3899        conflicts_with = "no_all_extras",
3900        conflicts_with = "dev",
3901        conflicts_with = "no_dev",
3902        conflicts_with = "only_dev",
3903        conflicts_with = "group",
3904        conflicts_with = "no_group",
3905        conflicts_with = "no_default_groups",
3906        conflicts_with = "only_group",
3907        conflicts_with = "all_groups"
3908    )]
3909    pub script: Option<PathBuf>,
3910
3911    /// The Python interpreter to use for the project environment.
3912    ///
3913    /// By default, the first interpreter that meets the project's `requires-python` constraint is
3914    /// used.
3915    ///
3916    /// If a Python interpreter in a virtual environment is provided, the packages will not be
3917    /// synced to the given environment. The interpreter will be used to create a virtual
3918    /// environment in the project.
3919    ///
3920    /// See `uv help python` for details on Python discovery and supported request formats.
3921    #[arg(
3922        long,
3923        short,
3924        env = EnvVars::UV_PYTHON,
3925        verbatim_doc_comment,
3926        help_heading = "Python options",
3927        value_parser = parse_maybe_string,
3928    )]
3929    pub python: Option<Maybe<String>>,
3930
3931    /// The platform for which requirements should be installed.
3932    ///
3933    /// Represented as a "target triple", a string that describes the target platform in terms of
3934    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
3935    /// `aarch64-apple-darwin`.
3936    ///
3937    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
3938    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3939    ///
3940    /// When targeting iOS, the default minimum version is `13.0`. Use
3941    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3942    ///
3943    /// When targeting Android, the default minimum Android API level is `24`. Use
3944    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
3945    ///
3946    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
3947    /// platform; as a result, the installed distributions may not be compatible with the _current_
3948    /// platform. Conversely, any distributions that are built from source may be incompatible with
3949    /// the _target_ platform, as they will be built for the _current_ platform. The
3950    /// `--python-platform` option is intended for advanced use cases.
3951    #[arg(long)]
3952    pub python_platform: Option<TargetTriple>,
3953
3954    /// Check if the Python environment is synchronized with the project.
3955    ///
3956    /// If the environment is not up to date, uv will exit with an error.
3957    #[arg(long, overrides_with("no_check"))]
3958    pub check: bool,
3959
3960    #[arg(long, overrides_with("check"), hide = true)]
3961    pub no_check: bool,
3962}
3963
3964#[derive(Args)]
3965pub struct LockArgs {
3966    /// Check if the lockfile is up-to-date.
3967    ///
3968    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
3969    /// missing or needs to be updated, uv will exit with an error.
3970    ///
3971    /// Equivalent to `--locked`.
3972    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check_exists", "upgrade"], overrides_with = "check")]
3973    pub check: bool,
3974
3975    /// Check if the lockfile is up-to-date.
3976    ///
3977    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
3978    /// missing or needs to be updated, uv will exit with an error.
3979    ///
3980    /// Equivalent to `--check`.
3981    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check_exists", "upgrade"], hide = true)]
3982    pub locked: bool,
3983
3984    /// Assert that a `uv.lock` exists without checking if it is up-to-date.
3985    ///
3986    /// Equivalent to `--frozen`.
3987    #[arg(long, alias = "frozen", env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check", "locked"])]
3988    pub check_exists: bool,
3989
3990    /// Perform a dry run, without writing the lockfile.
3991    ///
3992    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
3993    /// changes, but will not write the lockfile to disk.
3994    #[arg(
3995        long,
3996        conflicts_with = "check_exists",
3997        conflicts_with = "check",
3998        conflicts_with = "locked"
3999    )]
4000    pub dry_run: bool,
4001
4002    /// Lock the specified Python script, rather than the current project.
4003    ///
4004    /// If provided, uv will lock the script (based on its inline metadata table, in adherence with
4005    /// PEP 723) to a `.lock` file adjacent to the script itself.
4006    #[arg(long)]
4007    pub script: Option<PathBuf>,
4008
4009    #[command(flatten)]
4010    pub resolver: ResolverArgs,
4011
4012    #[command(flatten)]
4013    pub build: BuildOptionsArgs,
4014
4015    #[command(flatten)]
4016    pub refresh: RefreshArgs,
4017
4018    /// The Python interpreter to use during resolution.
4019    ///
4020    /// A Python interpreter is required for building source distributions to determine package
4021    /// metadata when there are not wheels.
4022    ///
4023    /// The interpreter is also used as the fallback value for the minimum Python version if
4024    /// `requires-python` is not set.
4025    ///
4026    /// See `uv help python` for details on Python discovery and supported request formats.
4027    #[arg(
4028        long,
4029        short,
4030        env = EnvVars::UV_PYTHON,
4031        verbatim_doc_comment,
4032        help_heading = "Python options",
4033        value_parser = parse_maybe_string,
4034    )]
4035    pub python: Option<Maybe<String>>,
4036}
4037
4038#[derive(Args)]
4039#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
4040pub struct AddArgs {
4041    /// The packages to add, as PEP 508 requirements (e.g., `ruff==0.5.0`).
4042    #[arg(group = "sources")]
4043    pub packages: Vec<String>,
4044
4045    /// Add the packages listed in the given files.
4046    ///
4047    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
4048    /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
4049    #[arg(long, short, alias = "requirement", group = "sources", value_parser = parse_file_path)]
4050    pub requirements: Vec<PathBuf>,
4051
4052    /// Constrain versions using the given requirements files.
4053    ///
4054    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
4055    /// requirement that's installed. The constraints will _not_ be added to the project's
4056    /// `pyproject.toml` file, but _will_ be respected during dependency resolution.
4057    ///
4058    /// This is equivalent to pip's `--constraint` option.
4059    #[arg(long, short, alias = "constraint", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
4060    pub constraints: Vec<Maybe<PathBuf>>,
4061
4062    /// Apply this marker to all added packages.
4063    #[arg(long, short, value_parser = MarkerTree::from_str)]
4064    pub marker: Option<MarkerTree>,
4065
4066    /// Add the requirements to the development dependency group.
4067    ///
4068    /// This option is an alias for `--group dev`.
4069    #[arg(
4070        long,
4071        conflicts_with("optional"),
4072        conflicts_with("group"),
4073        conflicts_with("script"),
4074        env = EnvVars::UV_DEV,
4075        value_parser = clap::builder::BoolishValueParser::new()
4076    )]
4077    pub dev: bool,
4078
4079    /// Add the requirements to the package's optional dependencies for the specified extra.
4080    ///
4081    /// The group may then be activated when installing the project with the `--extra` flag.
4082    ///
4083    /// To enable an optional extra for this requirement instead, see `--extra`.
4084    #[arg(long, conflicts_with("dev"), conflicts_with("group"))]
4085    pub optional: Option<ExtraName>,
4086
4087    /// Add the requirements to the specified dependency group.
4088    ///
4089    /// These requirements will not be included in the published metadata for the project.
4090    #[arg(
4091        long,
4092        conflicts_with("dev"),
4093        conflicts_with("optional"),
4094        conflicts_with("script")
4095    )]
4096    pub group: Option<GroupName>,
4097
4098    /// Add the requirements as editable.
4099    #[arg(long, overrides_with = "no_editable")]
4100    pub editable: bool,
4101
4102    #[arg(long, overrides_with = "editable", hide = true, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
4103    pub no_editable: bool,
4104
4105    /// Add a dependency as provided.
4106    ///
4107    /// By default, uv will use the `tool.uv.sources` section to record source information for Git,
4108    /// local, editable, and direct URL requirements. When `--raw` is provided, uv will add source
4109    /// requirements to `project.dependencies`, rather than `tool.uv.sources`.
4110    ///
4111    /// Additionally, by default, uv will add bounds to your dependency, e.g., `foo>=1.0.0`. When
4112    /// `--raw` is provided, uv will add the dependency without bounds.
4113    #[arg(
4114        long,
4115        conflicts_with = "editable",
4116        conflicts_with = "no_editable",
4117        conflicts_with = "rev",
4118        conflicts_with = "tag",
4119        conflicts_with = "branch",
4120        alias = "raw-sources"
4121    )]
4122    pub raw: bool,
4123
4124    /// The kind of version specifier to use when adding dependencies.
4125    ///
4126    /// When adding a dependency to the project, if no constraint or URL is provided, a constraint
4127    /// is added based on the latest compatible version of the package. By default, a lower bound
4128    /// constraint is used, e.g., `>=1.2.3`.
4129    ///
4130    /// When `--frozen` is provided, no resolution is performed, and dependencies are always added
4131    /// without constraints.
4132    ///
4133    /// This option is in preview and may change in any future release.
4134    #[arg(long, value_enum)]
4135    pub bounds: Option<AddBoundsKind>,
4136
4137    /// Commit to use when adding a dependency from Git.
4138    #[arg(long, group = "git-ref", action = clap::ArgAction::Set)]
4139    pub rev: Option<String>,
4140
4141    /// Tag to use when adding a dependency from Git.
4142    #[arg(long, group = "git-ref", action = clap::ArgAction::Set)]
4143    pub tag: Option<String>,
4144
4145    /// Branch to use when adding a dependency from Git.
4146    #[arg(long, group = "git-ref", action = clap::ArgAction::Set)]
4147    pub branch: Option<String>,
4148
4149    /// Whether to use Git LFS when adding a dependency from Git.
4150    #[arg(long, env = EnvVars::UV_GIT_LFS, value_parser = clap::builder::BoolishValueParser::new())]
4151    pub lfs: bool,
4152
4153    /// Extras to enable for the dependency.
4154    ///
4155    /// May be provided more than once.
4156    ///
4157    /// To add this dependency to an optional extra instead, see `--optional`.
4158    #[arg(long)]
4159    pub extra: Option<Vec<ExtraName>>,
4160
4161    /// Avoid syncing the virtual environment.
4162    #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
4163    pub no_sync: bool,
4164
4165    /// Assert that the `uv.lock` will remain unchanged.
4166    ///
4167    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4168    /// uv will exit with an error.
4169    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4170    pub locked: bool,
4171
4172    /// Add dependencies without re-locking the project.
4173    ///
4174    /// The project environment will not be synced.
4175    #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4176    pub frozen: bool,
4177
4178    /// Prefer the active virtual environment over the project's virtual environment.
4179    ///
4180    /// If the project virtual environment is active or no virtual environment is active, this has
4181    /// no effect.
4182    #[arg(long, overrides_with = "no_active")]
4183    pub active: bool,
4184
4185    /// Prefer project's virtual environment over an active environment.
4186    ///
4187    /// This is the default behavior.
4188    #[arg(long, overrides_with = "active", hide = true)]
4189    pub no_active: bool,
4190
4191    #[command(flatten)]
4192    pub installer: ResolverInstallerArgs,
4193
4194    #[command(flatten)]
4195    pub build: BuildOptionsArgs,
4196
4197    #[command(flatten)]
4198    pub refresh: RefreshArgs,
4199
4200    /// Add the dependency to a specific package in the workspace.
4201    #[arg(long, conflicts_with = "isolated")]
4202    pub package: Option<PackageName>,
4203
4204    /// Add the dependency to the specified Python script, rather than to a project.
4205    ///
4206    /// If provided, uv will add the dependency to the script's inline metadata table, in adherence
4207    /// with PEP 723. If no such inline metadata table is present, a new one will be created and
4208    /// added to the script. When executed via `uv run`, uv will create a temporary environment for
4209    /// the script with all inline dependencies installed.
4210    #[arg(
4211        long,
4212        conflicts_with = "dev",
4213        conflicts_with = "optional",
4214        conflicts_with = "package",
4215        conflicts_with = "workspace"
4216    )]
4217    pub script: Option<PathBuf>,
4218
4219    /// The Python interpreter to use for resolving and syncing.
4220    ///
4221    /// See `uv help python` for details on Python discovery and supported request formats.
4222    #[arg(
4223        long,
4224        short,
4225        env = EnvVars::UV_PYTHON,
4226        verbatim_doc_comment,
4227        help_heading = "Python options",
4228        value_parser = parse_maybe_string,
4229    )]
4230    pub python: Option<Maybe<String>>,
4231
4232    /// Add the dependency as a workspace member.
4233    ///
4234    /// By default, uv will add path dependencies that are within the workspace directory
4235    /// as workspace members. When used with a path dependency, the package will be added
4236    /// to the workspace's `members` list in the root `pyproject.toml` file.
4237    #[arg(long, overrides_with = "no_workspace")]
4238    pub workspace: bool,
4239
4240    /// Don't add the dependency as a workspace member.
4241    ///
4242    /// By default, when adding a dependency that's a local path and is within the workspace
4243    /// directory, uv will add it as a workspace member; pass `--no-workspace` to add the package
4244    /// as direct path dependency instead.
4245    #[arg(long, overrides_with = "workspace")]
4246    pub no_workspace: bool,
4247
4248    /// Do not install the current project.
4249    ///
4250    /// By default, the current project is installed into the environment with all of its
4251    /// dependencies. The `--no-install-project` option allows the project to be excluded, but all of
4252    /// its dependencies are still installed. This is particularly useful in situations like building
4253    /// Docker images where installing the project separately from its dependencies allows optimal
4254    /// layer caching.
4255    ///
4256    /// The inverse `--only-install-project` can be used to install _only_ the project itself,
4257    /// excluding all dependencies.
4258    #[arg(
4259        long,
4260        conflicts_with = "frozen",
4261        conflicts_with = "no_sync",
4262        conflicts_with = "only_install_project"
4263    )]
4264    pub no_install_project: bool,
4265
4266    /// Only install the current project.
4267    #[arg(
4268        long,
4269        conflicts_with = "frozen",
4270        conflicts_with = "no_sync",
4271        conflicts_with = "no_install_project",
4272        hide = true
4273    )]
4274    pub only_install_project: bool,
4275
4276    /// Do not install any workspace members, including the current project.
4277    ///
4278    /// By default, all workspace members and their dependencies are installed into the
4279    /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
4280    /// members while retaining their dependencies. This is particularly useful in situations like
4281    /// building Docker images where installing the workspace separately from its dependencies
4282    /// allows optimal layer caching.
4283    ///
4284    /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
4285    /// excluding all other dependencies.
4286    #[arg(
4287        long,
4288        conflicts_with = "frozen",
4289        conflicts_with = "no_sync",
4290        conflicts_with = "only_install_workspace"
4291    )]
4292    pub no_install_workspace: bool,
4293
4294    /// Only install workspace members, including the current project.
4295    #[arg(
4296        long,
4297        conflicts_with = "frozen",
4298        conflicts_with = "no_sync",
4299        conflicts_with = "no_install_workspace",
4300        hide = true
4301    )]
4302    pub only_install_workspace: bool,
4303
4304    /// Do not install local path dependencies
4305    ///
4306    /// Skips the current project, workspace members, and any other local (path or editable)
4307    /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
4308    /// heavy third-party dependencies first and layer local packages separately.
4309    ///
4310    /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
4311    /// all remote dependencies.
4312    #[arg(
4313        long,
4314        conflicts_with = "frozen",
4315        conflicts_with = "no_sync",
4316        conflicts_with = "only_install_local"
4317    )]
4318    pub no_install_local: bool,
4319
4320    /// Only install local path dependencies
4321    #[arg(
4322        long,
4323        conflicts_with = "frozen",
4324        conflicts_with = "no_sync",
4325        conflicts_with = "no_install_local",
4326        hide = true
4327    )]
4328    pub only_install_local: bool,
4329
4330    /// Do not install the given package(s).
4331    ///
4332    /// By default, all project's dependencies are installed into the environment. The
4333    /// `--no-install-package` option allows exclusion of specific packages. Note this can result
4334    /// in a broken environment, and should be used with caution.
4335    ///
4336    /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
4337    /// excluding all others.
4338    #[arg(
4339        long,
4340        conflicts_with = "frozen",
4341        conflicts_with = "no_sync",
4342        conflicts_with = "only_install_package"
4343    )]
4344    pub no_install_package: Vec<PackageName>,
4345
4346    /// Only install the given package(s).
4347    #[arg(
4348        long,
4349        conflicts_with = "frozen",
4350        conflicts_with = "no_sync",
4351        conflicts_with = "no_install_package",
4352        hide = true
4353    )]
4354    pub only_install_package: Vec<PackageName>,
4355}
4356
4357#[derive(Args)]
4358pub struct RemoveArgs {
4359    /// The names of the dependencies to remove (e.g., `ruff`).
4360    #[arg(required = true)]
4361    pub packages: Vec<Requirement<VerbatimParsedUrl>>,
4362
4363    /// Remove the packages from the development dependency group.
4364    ///
4365    /// This option is an alias for `--group dev`.
4366    #[arg(long, conflicts_with("optional"), conflicts_with("group"), env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4367    pub dev: bool,
4368
4369    /// Remove the packages from the project's optional dependencies for the specified extra.
4370    #[arg(
4371        long,
4372        conflicts_with("dev"),
4373        conflicts_with("group"),
4374        conflicts_with("script")
4375    )]
4376    pub optional: Option<ExtraName>,
4377
4378    /// Remove the packages from the specified dependency group.
4379    #[arg(
4380        long,
4381        conflicts_with("dev"),
4382        conflicts_with("optional"),
4383        conflicts_with("script")
4384    )]
4385    pub group: Option<GroupName>,
4386
4387    /// Avoid syncing the virtual environment after re-locking the project.
4388    #[arg(long, env = EnvVars::UV_NO_SYNC, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with = "frozen")]
4389    pub no_sync: bool,
4390
4391    /// Prefer the active virtual environment over the project's virtual environment.
4392    ///
4393    /// If the project virtual environment is active or no virtual environment is active, this has
4394    /// no effect.
4395    #[arg(long, overrides_with = "no_active")]
4396    pub active: bool,
4397
4398    /// Prefer project's virtual environment over an active environment.
4399    ///
4400    /// This is the default behavior.
4401    #[arg(long, overrides_with = "active", hide = true)]
4402    pub no_active: bool,
4403
4404    /// Assert that the `uv.lock` will remain unchanged.
4405    ///
4406    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4407    /// uv will exit with an error.
4408    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4409    pub locked: bool,
4410
4411    /// Remove dependencies without re-locking the project.
4412    ///
4413    /// The project environment will not be synced.
4414    #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4415    pub frozen: bool,
4416
4417    #[command(flatten)]
4418    pub installer: ResolverInstallerArgs,
4419
4420    #[command(flatten)]
4421    pub build: BuildOptionsArgs,
4422
4423    #[command(flatten)]
4424    pub refresh: RefreshArgs,
4425
4426    /// Remove the dependencies from a specific package in the workspace.
4427    #[arg(long, conflicts_with = "isolated")]
4428    pub package: Option<PackageName>,
4429
4430    /// Remove the dependency from the specified Python script, rather than from a project.
4431    ///
4432    /// If provided, uv will remove the dependency from the script's inline metadata table, in
4433    /// adherence with PEP 723.
4434    #[arg(long)]
4435    pub script: Option<PathBuf>,
4436
4437    /// The Python interpreter to use for resolving and syncing.
4438    ///
4439    /// See `uv help python` for details on Python discovery and supported request formats.
4440    #[arg(
4441        long,
4442        short,
4443        env = EnvVars::UV_PYTHON,
4444        verbatim_doc_comment,
4445        help_heading = "Python options",
4446        value_parser = parse_maybe_string,
4447    )]
4448    pub python: Option<Maybe<String>>,
4449}
4450
4451#[derive(Args)]
4452pub struct TreeArgs {
4453    /// Show a platform-independent dependency tree.
4454    ///
4455    /// Shows resolved package versions for all Python versions and platforms, rather than filtering
4456    /// to those that are relevant for the current environment.
4457    ///
4458    /// Multiple versions may be shown for a each package.
4459    #[arg(long)]
4460    pub universal: bool,
4461
4462    #[command(flatten)]
4463    pub tree: DisplayTreeArgs,
4464
4465    /// Include the development dependency group.
4466    ///
4467    /// Development dependencies are defined via `dependency-groups.dev` or
4468    /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
4469    ///
4470    /// This option is an alias for `--group dev`.
4471    #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4472    pub dev: bool,
4473
4474    /// Only include the development dependency group.
4475    ///
4476    /// The project and its dependencies will be omitted.
4477    ///
4478    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
4479    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
4480    pub only_dev: bool,
4481
4482    /// Disable the development dependency group.
4483    ///
4484    /// This option is an alias of `--no-group dev`.
4485    /// See `--no-default-groups` to disable all default groups instead.
4486    #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4487    pub no_dev: bool,
4488
4489    /// Include dependencies from the specified dependency group.
4490    ///
4491    /// May be provided multiple times.
4492    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4493    pub group: Vec<GroupName>,
4494
4495    /// Disable the specified dependency group.
4496    ///
4497    /// This option always takes precedence over default groups,
4498    /// `--all-groups`, and `--group`.
4499    ///
4500    /// May be provided multiple times.
4501    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
4502    pub no_group: Vec<GroupName>,
4503
4504    /// Ignore the default dependency groups.
4505    ///
4506    /// uv includes the groups defined in `tool.uv.default-groups` by default.
4507    /// This disables that option, however, specific groups can still be included with `--group`.
4508    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
4509    pub no_default_groups: bool,
4510
4511    /// Only include dependencies from the specified dependency group.
4512    ///
4513    /// The project and its dependencies will be omitted.
4514    ///
4515    /// May be provided multiple times. Implies `--no-default-groups`.
4516    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
4517    pub only_group: Vec<GroupName>,
4518
4519    /// Include dependencies from all dependency groups.
4520    ///
4521    /// `--no-group` can be used to exclude specific groups.
4522    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4523    pub all_groups: bool,
4524
4525    /// Assert that the `uv.lock` will remain unchanged.
4526    ///
4527    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4528    /// uv will exit with an error.
4529    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4530    pub locked: bool,
4531
4532    /// Display the requirements without locking the project.
4533    ///
4534    /// If the lockfile is missing, uv will exit with an error.
4535    #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4536    pub frozen: bool,
4537
4538    #[command(flatten)]
4539    pub build: BuildOptionsArgs,
4540
4541    #[command(flatten)]
4542    pub resolver: ResolverArgs,
4543
4544    /// Show the dependency tree the specified PEP 723 Python script, rather than the current
4545    /// project.
4546    ///
4547    /// If provided, uv will resolve the dependencies based on its inline metadata table, in
4548    /// adherence with PEP 723.
4549    #[arg(long)]
4550    pub script: Option<PathBuf>,
4551
4552    /// The Python version to use when filtering the tree.
4553    ///
4554    /// For example, pass `--python-version 3.10` to display the dependencies that would be included
4555    /// when installing on Python 3.10.
4556    ///
4557    /// Defaults to the version of the discovered Python interpreter.
4558    #[arg(long, conflicts_with = "universal")]
4559    pub python_version: Option<PythonVersion>,
4560
4561    /// The platform to use when filtering the tree.
4562    ///
4563    /// For example, pass `--platform windows` to display the dependencies that would be included
4564    /// when installing on Windows.
4565    ///
4566    /// Represented as a "target triple", a string that describes the target platform in terms of
4567    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
4568    /// `aarch64-apple-darwin`.
4569    #[arg(long, conflicts_with = "universal")]
4570    pub python_platform: Option<TargetTriple>,
4571
4572    /// The Python interpreter to use for locking and filtering.
4573    ///
4574    /// By default, the tree is filtered to match the platform as reported by the Python
4575    /// interpreter. Use `--universal` to display the tree for all platforms, or use
4576    /// `--python-version` or `--python-platform` to override a subset of markers.
4577    ///
4578    /// See `uv help python` for details on Python discovery and supported request formats.
4579    #[arg(
4580        long,
4581        short,
4582        env = EnvVars::UV_PYTHON,
4583        verbatim_doc_comment,
4584        help_heading = "Python options",
4585        value_parser = parse_maybe_string,
4586    )]
4587    pub python: Option<Maybe<String>>,
4588}
4589
4590#[derive(Args)]
4591pub struct ExportArgs {
4592    #[allow(clippy::doc_markdown)]
4593    /// The format to which `uv.lock` should be exported.
4594    ///
4595    /// Supports `requirements.txt`, `pylock.toml` (PEP 751) and CycloneDX v1.5 JSON output formats.
4596    ///
4597    /// uv will infer the output format from the file extension of the output file, if
4598    /// provided. Otherwise, defaults to `requirements.txt`.
4599    #[arg(long, value_enum)]
4600    pub format: Option<ExportFormat>,
4601
4602    /// Export the entire workspace.
4603    ///
4604    /// The dependencies for all workspace members will be included in the exported requirements
4605    /// file.
4606    ///
4607    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
4608    /// to all workspace members.
4609    #[arg(long, conflicts_with = "package")]
4610    pub all_packages: bool,
4611
4612    /// Export the dependencies for specific packages in the workspace.
4613    ///
4614    /// If any workspace member does not exist, uv will exit with an error.
4615    #[arg(long, conflicts_with = "all_packages")]
4616    pub package: Vec<PackageName>,
4617
4618    /// Prune the given package from the dependency tree.
4619    ///
4620    /// Pruned packages will be excluded from the exported requirements file, as will any
4621    /// dependencies that are no longer required after the pruned package is removed.
4622    #[arg(long, conflicts_with = "all_packages", value_name = "PACKAGE")]
4623    pub prune: Vec<PackageName>,
4624
4625    /// Include optional dependencies from the specified extra name.
4626    ///
4627    /// May be provided more than once.
4628    #[arg(long, conflicts_with = "all_extras", conflicts_with = "only_group", value_parser = extra_name_with_clap_error)]
4629    pub extra: Option<Vec<ExtraName>>,
4630
4631    /// Include all optional dependencies.
4632    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
4633    pub all_extras: bool,
4634
4635    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
4636    ///
4637    /// May be provided multiple times.
4638    #[arg(long)]
4639    pub no_extra: Vec<ExtraName>,
4640
4641    #[arg(long, overrides_with("all_extras"), hide = true)]
4642    pub no_all_extras: bool,
4643
4644    /// Include the development dependency group.
4645    ///
4646    /// This option is an alias for `--group dev`.
4647    #[arg(long, overrides_with("no_dev"), hide = true, env = EnvVars::UV_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4648    pub dev: bool,
4649
4650    /// Disable the development dependency group.
4651    ///
4652    /// This option is an alias of `--no-group dev`.
4653    /// See `--no-default-groups` to disable all default groups instead.
4654    #[arg(long, overrides_with("dev"), env = EnvVars::UV_NO_DEV, value_parser = clap::builder::BoolishValueParser::new())]
4655    pub no_dev: bool,
4656
4657    /// Only include the development dependency group.
4658    ///
4659    /// The project and its dependencies will be omitted.
4660    ///
4661    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
4662    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
4663    pub only_dev: bool,
4664
4665    /// Include dependencies from the specified dependency group.
4666    ///
4667    /// May be provided multiple times.
4668    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4669    pub group: Vec<GroupName>,
4670
4671    /// Disable the specified dependency group.
4672    ///
4673    /// This option always takes precedence over default groups,
4674    /// `--all-groups`, and `--group`.
4675    ///
4676    /// May be provided multiple times.
4677    #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')]
4678    pub no_group: Vec<GroupName>,
4679
4680    /// Ignore the default dependency groups.
4681    ///
4682    /// uv includes the groups defined in `tool.uv.default-groups` by default.
4683    /// This disables that option, however, specific groups can still be included with `--group`.
4684    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS)]
4685    pub no_default_groups: bool,
4686
4687    /// Only include dependencies from the specified dependency group.
4688    ///
4689    /// The project and its dependencies will be omitted.
4690    ///
4691    /// May be provided multiple times. Implies `--no-default-groups`.
4692    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"])]
4693    pub only_group: Vec<GroupName>,
4694
4695    /// Include dependencies from all dependency groups.
4696    ///
4697    /// `--no-group` can be used to exclude specific groups.
4698    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
4699    pub all_groups: bool,
4700
4701    /// Exclude comment annotations indicating the source of each package.
4702    #[arg(long, overrides_with("annotate"))]
4703    pub no_annotate: bool,
4704
4705    #[arg(long, overrides_with("no_annotate"), hide = true)]
4706    pub annotate: bool,
4707
4708    /// Exclude the comment header at the top of the generated output file.
4709    #[arg(long, overrides_with("header"))]
4710    pub no_header: bool,
4711
4712    #[arg(long, overrides_with("no_header"), hide = true)]
4713    pub header: bool,
4714
4715    /// Export any non-editable dependencies, including the project and any workspace members, as
4716    /// editable.
4717    #[arg(long, overrides_with = "no_editable", hide = true)]
4718    pub editable: bool,
4719
4720    /// Export any editable dependencies, including the project and any workspace members, as
4721    /// non-editable.
4722    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_EDITABLE)]
4723    pub no_editable: bool,
4724
4725    /// Include hashes for all dependencies.
4726    #[arg(long, overrides_with("no_hashes"), hide = true)]
4727    pub hashes: bool,
4728
4729    /// Omit hashes in the generated output.
4730    #[arg(long, overrides_with("hashes"))]
4731    pub no_hashes: bool,
4732
4733    /// Write the exported requirements to the given file.
4734    #[arg(long, short)]
4735    pub output_file: Option<PathBuf>,
4736
4737    /// Do not emit the current project.
4738    ///
4739    /// By default, the current project is included in the exported requirements file with all of
4740    /// its dependencies. The `--no-emit-project` option allows the project to be excluded, but all
4741    /// of its dependencies to remain included.
4742    ///
4743    /// The inverse `--only-emit-project` can be used to emit _only_ the project itself, excluding
4744    /// all dependencies.
4745    #[arg(
4746        long,
4747        alias = "no-install-project",
4748        conflicts_with = "only_emit_project"
4749    )]
4750    pub no_emit_project: bool,
4751
4752    /// Only emit the current project.
4753    #[arg(
4754        long,
4755        alias = "only-install-project",
4756        conflicts_with = "no_emit_project",
4757        hide = true
4758    )]
4759    pub only_emit_project: bool,
4760
4761    /// Do not emit any workspace members, including the root project.
4762    ///
4763    /// By default, all workspace members and their dependencies are included in the exported
4764    /// requirements file, with all of their dependencies. The `--no-emit-workspace` option allows
4765    /// exclusion of all the workspace members while retaining their dependencies.
4766    ///
4767    /// The inverse `--only-emit-workspace` can be used to emit _only_ workspace members, excluding
4768    /// all other dependencies.
4769    #[arg(
4770        long,
4771        alias = "no-install-workspace",
4772        conflicts_with = "only_emit_workspace"
4773    )]
4774    pub no_emit_workspace: bool,
4775
4776    /// Only emit workspace members, including the root project.
4777    #[arg(
4778        long,
4779        alias = "only-install-workspace",
4780        conflicts_with = "no_emit_workspace",
4781        hide = true
4782    )]
4783    pub only_emit_workspace: bool,
4784
4785    /// Do not include local path dependencies in the exported requirements.
4786    ///
4787    /// Omits the current project, workspace members, and any other local (path or editable)
4788    /// packages from the export. Only remote/indexed dependencies are written. Useful for Docker
4789    /// and CI flows that want to export and cache third-party dependencies first.
4790    ///
4791    /// The inverse `--only-emit-local` can be used to emit _only_ local packages, excluding all
4792    /// remote dependencies.
4793    #[arg(long, alias = "no-install-local", conflicts_with = "only_emit_local")]
4794    pub no_emit_local: bool,
4795
4796    /// Only include local path dependencies in the exported requirements.
4797    #[arg(
4798        long,
4799        alias = "only-install-local",
4800        conflicts_with = "no_emit_local",
4801        hide = true
4802    )]
4803    pub only_emit_local: bool,
4804
4805    /// Do not emit the given package(s).
4806    ///
4807    /// By default, all project's dependencies are included in the exported requirements
4808    /// file. The `--no-emit-package` option allows exclusion of specific packages.
4809    ///
4810    /// The inverse `--only-emit-package` can be used to emit _only_ the specified packages,
4811    /// excluding all others.
4812    #[arg(
4813        long,
4814        alias = "no-install-package",
4815        conflicts_with = "only_emit_package"
4816    )]
4817    pub no_emit_package: Vec<PackageName>,
4818
4819    /// Only emit the given package(s).
4820    #[arg(
4821        long,
4822        alias = "only-install-package",
4823        conflicts_with = "no_emit_package",
4824        hide = true
4825    )]
4826    pub only_emit_package: Vec<PackageName>,
4827
4828    /// Assert that the `uv.lock` will remain unchanged.
4829    ///
4830    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
4831    /// uv will exit with an error.
4832    #[arg(long, env = EnvVars::UV_LOCKED, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["frozen", "upgrade"])]
4833    pub locked: bool,
4834
4835    /// Do not update the `uv.lock` before exporting.
4836    ///
4837    /// If a `uv.lock` does not exist, uv will exit with an error.
4838    #[arg(long, env = EnvVars::UV_FROZEN, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["locked", "upgrade", "no_sources"])]
4839    pub frozen: bool,
4840
4841    #[command(flatten)]
4842    pub resolver: ResolverArgs,
4843
4844    #[command(flatten)]
4845    pub build: BuildOptionsArgs,
4846
4847    #[command(flatten)]
4848    pub refresh: RefreshArgs,
4849
4850    /// Export the dependencies for the specified PEP 723 Python script, rather than the current
4851    /// project.
4852    ///
4853    /// If provided, uv will resolve the dependencies based on its inline metadata table, in
4854    /// adherence with PEP 723.
4855    #[arg(long, conflicts_with_all = ["all_packages", "package", "no_emit_project", "no_emit_workspace"])]
4856    pub script: Option<PathBuf>,
4857
4858    /// The Python interpreter to use during resolution.
4859    ///
4860    /// A Python interpreter is required for building source distributions to determine package
4861    /// metadata when there are not wheels.
4862    ///
4863    /// The interpreter is also used as the fallback value for the minimum Python version if
4864    /// `requires-python` is not set.
4865    ///
4866    /// See `uv help python` for details on Python discovery and supported request formats.
4867    #[arg(
4868        long,
4869        short,
4870        env = EnvVars::UV_PYTHON,
4871        verbatim_doc_comment,
4872        help_heading = "Python options",
4873        value_parser = parse_maybe_string,
4874    )]
4875    pub python: Option<Maybe<String>>,
4876}
4877
4878#[derive(Args)]
4879pub struct FormatArgs {
4880    /// Check if files are formatted without applying changes.
4881    #[arg(long)]
4882    pub check: bool,
4883
4884    /// Show a diff of formatting changes without applying them.
4885    ///
4886    /// Implies `--check`.
4887    #[arg(long)]
4888    pub diff: bool,
4889
4890    /// The version of Ruff to use for formatting.
4891    ///
4892    /// By default, a version of Ruff pinned by uv will be used.
4893    #[arg(long)]
4894    pub version: Option<String>,
4895
4896    /// Additional arguments to pass to Ruff.
4897    ///
4898    /// For example, use `uv format -- --line-length 100` to set the line length or
4899    /// `uv format -- src/module/foo.py` to format a specific file.
4900    #[arg(last = true)]
4901    pub extra_args: Vec<String>,
4902
4903    /// Avoid discovering a project or workspace.
4904    ///
4905    /// Instead of running the formatter in the context of the current project, run it in the
4906    /// context of the current directory. This is useful when the current directory is not a
4907    /// project.
4908    #[arg(long)]
4909    pub no_project: bool,
4910}
4911
4912#[derive(Args)]
4913pub struct AuthNamespace {
4914    #[command(subcommand)]
4915    pub command: AuthCommand,
4916}
4917
4918#[derive(Subcommand)]
4919pub enum AuthCommand {
4920    /// Login to a service
4921    Login(AuthLoginArgs),
4922    /// Logout of a service
4923    Logout(AuthLogoutArgs),
4924    /// Show the authentication token for a service
4925    Token(AuthTokenArgs),
4926    /// Show the path to the uv credentials directory.
4927    ///
4928    /// By default, credentials are stored in the uv data directory at
4929    /// `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and
4930    /// `%APPDATA%\uv\data\credentials` on Windows.
4931    ///
4932    /// The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`.
4933    ///
4934    /// Credentials are only stored in this directory when the plaintext backend is used, as
4935    /// opposed to the native backend, which uses the system keyring.
4936    Dir(AuthDirArgs),
4937    /// Act as a credential helper for external tools.
4938    ///
4939    /// Implements the Bazel credential helper protocol to provide credentials
4940    /// to external tools via JSON over stdin/stdout.
4941    ///
4942    /// This command is typically invoked by external tools.
4943    #[command(hide = true)]
4944    Helper(AuthHelperArgs),
4945}
4946
4947#[derive(Args)]
4948pub struct ToolNamespace {
4949    #[command(subcommand)]
4950    pub command: ToolCommand,
4951}
4952
4953#[derive(Subcommand)]
4954pub enum ToolCommand {
4955    /// Run a command provided by a Python package.
4956    ///
4957    /// By default, the package to install is assumed to match the command name.
4958    ///
4959    /// The name of the command can include an exact version in the format `<package>@<version>`,
4960    /// e.g., `uv tool run ruff@0.3.0`. If more complex version specification is desired or if the
4961    /// command is provided by a different package, use `--from`.
4962    ///
4963    /// `uvx` can be used to invoke Python, e.g., with `uvx python` or `uvx python@<version>`. A
4964    /// Python interpreter will be started in an isolated virtual environment.
4965    ///
4966    /// If the tool was previously installed, i.e., via `uv tool install`, the installed version
4967    /// will be used unless a version is requested or the `--isolated` flag is used.
4968    ///
4969    /// `uvx` is provided as a convenient alias for `uv tool run`, their behavior is identical.
4970    ///
4971    /// If no command is provided, the installed tools are displayed.
4972    ///
4973    /// Packages are installed into an ephemeral virtual environment in the uv cache directory.
4974    #[command(
4975        after_help = "Use `uvx` as a shortcut for `uv tool run`.\n\n\
4976        Use `uv help tool run` for more details.",
4977        after_long_help = ""
4978    )]
4979    Run(ToolRunArgs),
4980    /// Hidden alias for `uv tool run` for the `uvx` command
4981    #[command(
4982        hide = true,
4983        override_usage = "uvx [OPTIONS] [COMMAND]",
4984        about = "Run a command provided by a Python package.",
4985        after_help = "Use `uv help tool run` for more details.",
4986        after_long_help = "",
4987        display_name = "uvx",
4988        long_version = crate::version::uv_self_version()
4989    )]
4990    Uvx(UvxArgs),
4991    /// Install commands provided by a Python package.
4992    ///
4993    /// Packages are installed into an isolated virtual environment in the uv tools directory. The
4994    /// executables are linked the tool executable directory, which is determined according to the
4995    /// XDG standard and can be retrieved with `uv tool dir --bin`.
4996    ///
4997    /// If the tool was previously installed, the existing tool will generally be replaced.
4998    Install(ToolInstallArgs),
4999    /// Upgrade installed tools.
5000    ///
5001    /// If a tool was installed with version constraints, they will be respected on upgrade — to
5002    /// upgrade a tool beyond the originally provided constraints, use `uv tool install` again.
5003    ///
5004    /// If a tool was installed with specific settings, they will be respected on upgraded. For
5005    /// example, if `--prereleases allow` was provided during installation, it will continue to be
5006    /// respected in upgrades.
5007    #[command(alias = "update")]
5008    Upgrade(ToolUpgradeArgs),
5009    /// List installed tools.
5010    #[command(alias = "ls")]
5011    List(ToolListArgs),
5012    /// Uninstall a tool.
5013    Uninstall(ToolUninstallArgs),
5014    /// Ensure that the tool executable directory is on the `PATH`.
5015    ///
5016    /// If the tool executable directory is not present on the `PATH`, uv will attempt to add it to
5017    /// the relevant shell configuration files.
5018    ///
5019    /// If the shell configuration files already include a blurb to add the executable directory to
5020    /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5021    ///
5022    /// The tool executable directory is determined according to the XDG standard and can be
5023    /// retrieved with `uv tool dir --bin`.
5024    #[command(alias = "ensurepath")]
5025    UpdateShell,
5026    /// Show the path to the uv tools directory.
5027    ///
5028    /// The tools directory is used to store environments and metadata for installed tools.
5029    ///
5030    /// By default, tools are stored in the uv data directory at `$XDG_DATA_HOME/uv/tools` or
5031    /// `$HOME/.local/share/uv/tools` on Unix and `%APPDATA%\uv\data\tools` on Windows.
5032    ///
5033    /// The tool installation directory may be overridden with `$UV_TOOL_DIR`.
5034    ///
5035    /// To instead view the directory uv installs executables into, use the `--bin` flag.
5036    Dir(ToolDirArgs),
5037}
5038
5039#[derive(Args)]
5040pub struct ToolRunArgs {
5041    /// The command to run.
5042    ///
5043    /// WARNING: The documentation for [`Self::command`] is not included in help output
5044    #[command(subcommand)]
5045    pub command: Option<ExternalCommand>,
5046
5047    /// Use the given package to provide the command.
5048    ///
5049    /// By default, the package name is assumed to match the command name.
5050    #[arg(long)]
5051    pub from: Option<String>,
5052
5053    /// Run with the given packages installed.
5054    #[arg(short = 'w', long)]
5055    pub with: Vec<comma::CommaSeparatedRequirements>,
5056
5057    /// Run with the given packages installed in editable mode
5058    ///
5059    /// When used in a project, these dependencies will be layered on top of the uv tool's
5060    /// environment in a separate, ephemeral environment. These dependencies are allowed to conflict
5061    /// with those specified.
5062    #[arg(long)]
5063    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5064
5065    /// Run with the packages listed in the given files.
5066    ///
5067    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5068    /// and `pylock.toml`.
5069    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path)]
5070    pub with_requirements: Vec<Maybe<PathBuf>>,
5071
5072    /// Constrain versions using the given requirements files.
5073    ///
5074    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5075    /// requirement that's installed. However, including a package in a constraints file will _not_
5076    /// trigger the installation of that package.
5077    ///
5078    /// This is equivalent to pip's `--constraint` option.
5079    #[arg(long, short, alias = "constraint", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5080    pub constraints: Vec<Maybe<PathBuf>>,
5081
5082    /// Constrain build dependencies using the given requirements files when building source
5083    /// distributions.
5084    ///
5085    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5086    /// requirement that's installed. However, including a package in a constraints file will _not_
5087    /// trigger the installation of that package.
5088    #[arg(long, short, alias = "build-constraint", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5089    pub build_constraints: Vec<Maybe<PathBuf>>,
5090
5091    /// Override versions using the given requirements files.
5092    ///
5093    /// Overrides files are `requirements.txt`-like files that force a specific version of a
5094    /// requirement to be installed, regardless of the requirements declared by any constituent
5095    /// package, and regardless of whether this would be considered an invalid resolution.
5096    ///
5097    /// While constraints are _additive_, in that they're combined with the requirements of the
5098    /// constituent packages, overrides are _absolute_, in that they completely replace the
5099    /// requirements of the constituent packages.
5100    #[arg(long, alias = "override", env = EnvVars::UV_OVERRIDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5101    pub overrides: Vec<Maybe<PathBuf>>,
5102
5103    /// Run the tool in an isolated virtual environment, ignoring any already-installed tools.
5104    #[arg(long, env = EnvVars::UV_ISOLATED, value_parser = clap::builder::BoolishValueParser::new())]
5105    pub isolated: bool,
5106
5107    /// Load environment variables from a `.env` file.
5108    ///
5109    /// Can be provided multiple times, with subsequent files overriding values defined in previous
5110    /// files.
5111    #[arg(long, value_delimiter = ' ', env = EnvVars::UV_ENV_FILE)]
5112    pub env_file: Vec<PathBuf>,
5113
5114    /// Avoid reading environment variables from a `.env` file.
5115    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), env = EnvVars::UV_NO_ENV_FILE)]
5116    pub no_env_file: bool,
5117
5118    #[command(flatten)]
5119    pub installer: ResolverInstallerArgs,
5120
5121    #[command(flatten)]
5122    pub build: BuildOptionsArgs,
5123
5124    #[command(flatten)]
5125    pub refresh: RefreshArgs,
5126
5127    /// Whether to use Git LFS when adding a dependency from Git.
5128    #[arg(long, env = EnvVars::UV_GIT_LFS, value_parser = clap::builder::BoolishValueParser::new())]
5129    pub lfs: bool,
5130
5131    /// The Python interpreter to use to build the run environment.
5132    ///
5133    /// See `uv help python` for details on Python discovery and supported request formats.
5134    #[arg(
5135        long,
5136        short,
5137        env = EnvVars::UV_PYTHON,
5138        verbatim_doc_comment,
5139        help_heading = "Python options",
5140        value_parser = parse_maybe_string,
5141    )]
5142    pub python: Option<Maybe<String>>,
5143
5144    /// Whether to show resolver and installer output from any environment modifications.
5145    ///
5146    /// By default, environment modifications are omitted, but enabled under `--verbose`.
5147    #[arg(long, env = EnvVars::UV_SHOW_RESOLUTION, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
5148    pub show_resolution: bool,
5149
5150    /// The platform for which requirements should be installed.
5151    ///
5152    /// Represented as a "target triple", a string that describes the target platform in terms of
5153    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5154    /// `aarch64-apple-darwin`.
5155    ///
5156    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5157    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5158    ///
5159    /// When targeting iOS, the default minimum version is `13.0`. Use
5160    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5161    ///
5162    /// When targeting Android, the default minimum Android API level is `24`. Use
5163    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5164    ///
5165    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5166    /// platform; as a result, the installed distributions may not be compatible with the _current_
5167    /// platform. Conversely, any distributions that are built from source may be incompatible with
5168    /// the _target_ platform, as they will be built for the _current_ platform. The
5169    /// `--python-platform` option is intended for advanced use cases.
5170    #[arg(long)]
5171    pub python_platform: Option<TargetTriple>,
5172
5173    #[arg(long, hide = true)]
5174    pub generate_shell_completion: Option<clap_complete_command::Shell>,
5175}
5176
5177#[derive(Args)]
5178pub struct UvxArgs {
5179    #[command(flatten)]
5180    pub tool_run: ToolRunArgs,
5181
5182    /// Display the uvx version.
5183    #[arg(short = 'V', long, action = clap::ArgAction::Version)]
5184    pub version: Option<bool>,
5185}
5186
5187#[derive(Args)]
5188pub struct ToolInstallArgs {
5189    /// The package to install commands from.
5190    pub package: String,
5191
5192    /// The package to install commands from.
5193    ///
5194    /// This option is provided for parity with `uv tool run`, but is redundant with `package`.
5195    #[arg(long, hide = true)]
5196    pub from: Option<String>,
5197
5198    /// Include the following additional requirements.
5199    #[arg(short = 'w', long)]
5200    pub with: Vec<comma::CommaSeparatedRequirements>,
5201
5202    /// Run with the packages listed in the given files.
5203    ///
5204    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5205    /// and `pylock.toml`.
5206    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path)]
5207    pub with_requirements: Vec<Maybe<PathBuf>>,
5208
5209    /// Install the target package in editable mode, such that changes in the package's source
5210    /// directory are reflected without reinstallation.
5211    #[arg(short, long)]
5212    pub editable: bool,
5213
5214    /// Include the given packages in editable mode.
5215    #[arg(long)]
5216    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5217
5218    /// Install executables from the following packages.
5219    #[arg(long)]
5220    pub with_executables_from: Vec<comma::CommaSeparatedRequirements>,
5221
5222    /// Constrain versions using the given requirements files.
5223    ///
5224    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5225    /// requirement that's installed. However, including a package in a constraints file will _not_
5226    /// trigger the installation of that package.
5227    ///
5228    /// This is equivalent to pip's `--constraint` option.
5229    #[arg(long, short, alias = "constraint", env = EnvVars::UV_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5230    pub constraints: Vec<Maybe<PathBuf>>,
5231
5232    /// Override versions using the given requirements files.
5233    ///
5234    /// Overrides files are `requirements.txt`-like files that force a specific version of a
5235    /// requirement to be installed, regardless of the requirements declared by any constituent
5236    /// package, and regardless of whether this would be considered an invalid resolution.
5237    ///
5238    /// While constraints are _additive_, in that they're combined with the requirements of the
5239    /// constituent packages, overrides are _absolute_, in that they completely replace the
5240    /// requirements of the constituent packages.
5241    #[arg(long, alias = "override", env = EnvVars::UV_OVERRIDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5242    pub overrides: Vec<Maybe<PathBuf>>,
5243
5244    /// Exclude packages from resolution using the given requirements files.
5245    ///
5246    /// Excludes files are `requirements.txt`-like files that specify packages to exclude
5247    /// from the resolution. When a package is excluded, it will be omitted from the
5248    /// dependency list entirely and its own dependencies will be ignored during the resolution
5249    /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
5250    /// any package listed in the provided file will be omitted from all resolved environments.
5251    #[arg(long, alias = "exclude", env = EnvVars::UV_EXCLUDE, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5252    pub excludes: Vec<Maybe<PathBuf>>,
5253
5254    /// Constrain build dependencies using the given requirements files when building source
5255    /// distributions.
5256    ///
5257    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5258    /// requirement that's installed. However, including a package in a constraints file will _not_
5259    /// trigger the installation of that package.
5260    #[arg(long, short, alias = "build-constraint", env = EnvVars::UV_BUILD_CONSTRAINT, value_delimiter = ' ', value_parser = parse_maybe_file_path)]
5261    pub build_constraints: Vec<Maybe<PathBuf>>,
5262
5263    #[command(flatten)]
5264    pub installer: ResolverInstallerArgs,
5265
5266    #[command(flatten)]
5267    pub build: BuildOptionsArgs,
5268
5269    #[command(flatten)]
5270    pub refresh: RefreshArgs,
5271
5272    /// Force installation of the tool.
5273    ///
5274    /// Will replace any existing entry points with the same name in the executable directory.
5275    #[arg(long)]
5276    pub force: bool,
5277
5278    /// Whether to use Git LFS when adding a dependency from Git.
5279    #[arg(long, env = EnvVars::UV_GIT_LFS, value_parser = clap::builder::BoolishValueParser::new())]
5280    pub lfs: bool,
5281
5282    /// The Python interpreter to use to build the tool environment.
5283    ///
5284    /// See `uv help python` for details on Python discovery and supported request formats.
5285    #[arg(
5286        long,
5287        short,
5288        env = EnvVars::UV_PYTHON,
5289        verbatim_doc_comment,
5290        help_heading = "Python options",
5291        value_parser = parse_maybe_string,
5292    )]
5293    pub python: Option<Maybe<String>>,
5294
5295    /// The platform for which requirements should be installed.
5296    ///
5297    /// Represented as a "target triple", a string that describes the target platform in terms of
5298    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5299    /// `aarch64-apple-darwin`.
5300    ///
5301    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5302    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5303    ///
5304    /// When targeting iOS, the default minimum version is `13.0`. Use
5305    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5306    ///
5307    /// When targeting Android, the default minimum Android API level is `24`. Use
5308    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5309    ///
5310    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5311    /// platform; as a result, the installed distributions may not be compatible with the _current_
5312    /// platform. Conversely, any distributions that are built from source may be incompatible with
5313    /// the _target_ platform, as they will be built for the _current_ platform. The
5314    /// `--python-platform` option is intended for advanced use cases.
5315    #[arg(long)]
5316    pub python_platform: Option<TargetTriple>,
5317}
5318
5319#[derive(Args)]
5320pub struct ToolListArgs {
5321    /// Whether to display the path to each tool environment and installed executable.
5322    #[arg(long)]
5323    pub show_paths: bool,
5324
5325    /// Whether to display the version specifier(s) used to install each tool.
5326    #[arg(long)]
5327    pub show_version_specifiers: bool,
5328
5329    /// Whether to display the additional requirements installed with each tool.
5330    #[arg(long)]
5331    pub show_with: bool,
5332
5333    /// Whether to display the extra requirements installed with each tool.
5334    #[arg(long)]
5335    pub show_extras: bool,
5336
5337    /// Whether to display the Python version associated with each tool.
5338    #[arg(long)]
5339    pub show_python: bool,
5340
5341    // Hide unused global Python options.
5342    #[arg(long, hide = true)]
5343    pub python_preference: Option<PythonPreference>,
5344
5345    #[arg(long, hide = true)]
5346    pub no_python_downloads: bool,
5347}
5348
5349#[derive(Args)]
5350pub struct ToolDirArgs {
5351    /// Show the directory into which `uv tool` will install executables.
5352    ///
5353    /// By default, `uv tool dir` shows the directory into which the tool Python environments
5354    /// themselves are installed, rather than the directory containing the linked executables.
5355    ///
5356    /// The tool executable directory is determined according to the XDG standard and is derived
5357    /// from the following environment variables, in order of preference:
5358    ///
5359    /// - `$UV_TOOL_BIN_DIR`
5360    /// - `$XDG_BIN_HOME`
5361    /// - `$XDG_DATA_HOME/../bin`
5362    /// - `$HOME/.local/bin`
5363    #[arg(long, verbatim_doc_comment)]
5364    pub bin: bool,
5365}
5366
5367#[derive(Args)]
5368pub struct ToolUninstallArgs {
5369    /// The name of the tool to uninstall.
5370    #[arg(required = true)]
5371    pub name: Vec<PackageName>,
5372
5373    /// Uninstall all tools.
5374    #[arg(long, conflicts_with("name"))]
5375    pub all: bool,
5376}
5377
5378#[derive(Args)]
5379pub struct ToolUpgradeArgs {
5380    /// The name of the tool to upgrade, along with an optional version specifier.
5381    #[arg(required = true)]
5382    pub name: Vec<String>,
5383
5384    /// Upgrade all tools.
5385    #[arg(long, conflicts_with("name"))]
5386    pub all: bool,
5387
5388    /// Upgrade a tool, and specify it to use the given Python interpreter to build its environment.
5389    /// Use with `--all` to apply to all tools.
5390    ///
5391    /// See `uv help python` for details on Python discovery and supported request formats.
5392    #[arg(
5393        long,
5394        short,
5395        env = EnvVars::UV_PYTHON,
5396        verbatim_doc_comment,
5397        help_heading = "Python options",
5398        value_parser = parse_maybe_string,
5399    )]
5400    pub python: Option<Maybe<String>>,
5401
5402    /// The platform for which requirements should be installed.
5403    ///
5404    /// Represented as a "target triple", a string that describes the target platform in terms of
5405    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5406    /// `aarch64-apple-darwin`.
5407    ///
5408    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5409    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5410    ///
5411    /// When targeting iOS, the default minimum version is `13.0`. Use
5412    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5413    ///
5414    /// When targeting Android, the default minimum Android API level is `24`. Use
5415    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5416    ///
5417    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5418    /// platform; as a result, the installed distributions may not be compatible with the _current_
5419    /// platform. Conversely, any distributions that are built from source may be incompatible with
5420    /// the _target_ platform, as they will be built for the _current_ platform. The
5421    /// `--python-platform` option is intended for advanced use cases.
5422    #[arg(long)]
5423    pub python_platform: Option<TargetTriple>,
5424
5425    // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`, and
5426    // `--upgrade-package` options hidden, and the `--no-upgrade` option removed.
5427    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
5428    /// `--refresh`.
5429    #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")]
5430    pub upgrade: bool,
5431
5432    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
5433    /// file. Implies `--refresh-package`.
5434    #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")]
5435    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
5436
5437    #[command(flatten)]
5438    pub index_args: IndexArgs,
5439
5440    /// Reinstall all packages, regardless of whether they're already installed. Implies
5441    /// `--refresh`.
5442    #[arg(
5443        long,
5444        alias = "force-reinstall",
5445        overrides_with("no_reinstall"),
5446        help_heading = "Installer options"
5447    )]
5448    pub reinstall: bool,
5449
5450    #[arg(
5451        long,
5452        overrides_with("reinstall"),
5453        hide = true,
5454        help_heading = "Installer options"
5455    )]
5456    pub no_reinstall: bool,
5457
5458    /// Reinstall a specific package, regardless of whether it's already installed. Implies
5459    /// `--refresh-package`.
5460    #[arg(long, help_heading = "Installer options")]
5461    pub reinstall_package: Vec<PackageName>,
5462
5463    /// The strategy to use when resolving against multiple index URLs.
5464    ///
5465    /// By default, uv will stop at the first index on which a given package is available, and limit
5466    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
5467    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
5468    /// to an alternate index.
5469    #[arg(
5470        long,
5471        value_enum,
5472        env = EnvVars::UV_INDEX_STRATEGY,
5473        help_heading = "Index options"
5474    )]
5475    pub index_strategy: Option<IndexStrategy>,
5476
5477    /// Attempt to use `keyring` for authentication for index URLs.
5478    ///
5479    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
5480    /// the `keyring` CLI to handle authentication.
5481    ///
5482    /// Defaults to `disabled`.
5483    #[arg(
5484        long,
5485        value_enum,
5486        env = EnvVars::UV_KEYRING_PROVIDER,
5487        help_heading = "Index options"
5488    )]
5489    pub keyring_provider: Option<KeyringProviderType>,
5490
5491    /// The strategy to use when selecting between the different compatible versions for a given
5492    /// package requirement.
5493    ///
5494    /// By default, uv will use the latest compatible version of each package (`highest`).
5495    #[arg(
5496        long,
5497        value_enum,
5498        env = EnvVars::UV_RESOLUTION,
5499        help_heading = "Resolver options"
5500    )]
5501    pub resolution: Option<ResolutionMode>,
5502
5503    /// The strategy to use when considering pre-release versions.
5504    ///
5505    /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
5506    /// with first-party requirements that contain an explicit pre-release marker in the declared
5507    /// specifiers (`if-necessary-or-explicit`).
5508    #[arg(
5509        long,
5510        value_enum,
5511        env = EnvVars::UV_PRERELEASE,
5512        help_heading = "Resolver options"
5513    )]
5514    pub prerelease: Option<PrereleaseMode>,
5515
5516    #[arg(long, hide = true)]
5517    pub pre: bool,
5518
5519    /// The strategy to use when selecting multiple versions of a given package across Python
5520    /// versions and platforms.
5521    ///
5522    /// By default, uv will optimize for selecting the latest version of each package for each
5523    /// supported Python version (`requires-python`), while minimizing the number of selected
5524    /// versions across platforms.
5525    ///
5526    /// Under `fewest`, uv will minimize the number of selected versions for each package,
5527    /// preferring older versions that are compatible with a wider range of supported Python
5528    /// versions or platforms.
5529    #[arg(
5530        long,
5531        value_enum,
5532        env = EnvVars::UV_FORK_STRATEGY,
5533        help_heading = "Resolver options"
5534    )]
5535    pub fork_strategy: Option<ForkStrategy>,
5536
5537    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
5538    #[arg(
5539        long,
5540        short = 'C',
5541        alias = "config-settings",
5542        help_heading = "Build options"
5543    )]
5544    pub config_setting: Option<Vec<ConfigSettingEntry>>,
5545
5546    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
5547    #[arg(
5548        long,
5549        alias = "config-settings-package",
5550        help_heading = "Build options"
5551    )]
5552    pub config_setting_package: Option<Vec<ConfigSettingPackageEntry>>,
5553
5554    /// Disable isolation when building source distributions.
5555    ///
5556    /// Assumes that build dependencies specified by PEP 518 are already installed.
5557    #[arg(
5558        long,
5559        overrides_with("build_isolation"),
5560        help_heading = "Build options",
5561        env = EnvVars::UV_NO_BUILD_ISOLATION,
5562        value_parser = clap::builder::BoolishValueParser::new(),
5563    )]
5564    pub no_build_isolation: bool,
5565
5566    /// Disable isolation when building source distributions for a specific package.
5567    ///
5568    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
5569    #[arg(long, help_heading = "Build options")]
5570    pub no_build_isolation_package: Vec<PackageName>,
5571
5572    #[arg(
5573        long,
5574        overrides_with("no_build_isolation"),
5575        hide = true,
5576        help_heading = "Build options"
5577    )]
5578    pub build_isolation: bool,
5579
5580    /// Limit candidate packages to those that were uploaded prior to the given date.
5581    ///
5582    /// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
5583    /// format (e.g., `2006-12-02`) in your system's configured time zone.
5584    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
5585    pub exclude_newer: Option<ExcludeNewerTimestamp>,
5586
5587    /// Limit candidate packages for specific packages to those that were uploaded prior to the given date.
5588    ///
5589    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339 timestamp
5590    /// (e.g., `2006-12-02T02:07:43Z`) or local date (e.g., `2006-12-02`) in your system's configured time zone.
5591    ///
5592    /// Can be provided multiple times for different packages.
5593    #[arg(long, help_heading = "Resolver options")]
5594    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
5595
5596    /// The method to use when installing packages from the global cache.
5597    ///
5598    /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
5599    /// Windows.
5600    ///
5601    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
5602    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
5603    /// will break all installed packages by way of removing the underlying source files. Use
5604    /// symlinks with caution.
5605    #[arg(
5606        long,
5607        value_enum,
5608        env = EnvVars::UV_LINK_MODE,
5609        help_heading = "Installer options"
5610    )]
5611    pub link_mode: Option<uv_install_wheel::LinkMode>,
5612
5613    /// Compile Python files to bytecode after installation.
5614    ///
5615    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
5616    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
5617    /// in which start time is critical, such as CLI applications and Docker containers, this option
5618    /// can be enabled to trade longer installation times for faster start times.
5619    ///
5620    /// When enabled, uv will process the entire site-packages directory (including packages that
5621    /// are not being modified by the current operation) for consistency. Like pip, it will also
5622    /// ignore errors.
5623    #[arg(
5624        long,
5625        alias = "compile",
5626        overrides_with("no_compile_bytecode"),
5627        help_heading = "Installer options",
5628        env = EnvVars::UV_COMPILE_BYTECODE,
5629        value_parser = clap::builder::BoolishValueParser::new(),
5630    )]
5631    pub compile_bytecode: bool,
5632
5633    #[arg(
5634        long,
5635        alias = "no-compile",
5636        overrides_with("compile_bytecode"),
5637        hide = true,
5638        help_heading = "Installer options"
5639    )]
5640    pub no_compile_bytecode: bool,
5641
5642    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
5643    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
5644    /// URL, or local path sources.
5645    #[arg(
5646        long,
5647        env = EnvVars::UV_NO_SOURCES,
5648        value_parser = clap::builder::BoolishValueParser::new(),
5649        help_heading = "Resolver options",
5650    )]
5651    pub no_sources: bool,
5652
5653    #[command(flatten)]
5654    pub build: BuildOptionsArgs,
5655}
5656
5657#[derive(Args)]
5658pub struct PythonNamespace {
5659    #[command(subcommand)]
5660    pub command: PythonCommand,
5661}
5662
5663#[derive(Subcommand)]
5664pub enum PythonCommand {
5665    /// List the available Python installations.
5666    ///
5667    /// By default, installed Python versions and the downloads for latest available patch version
5668    /// of each supported Python major version are shown.
5669    ///
5670    /// Use `--managed-python` to view only managed Python versions.
5671    ///
5672    /// Use `--no-managed-python` to omit managed Python versions.
5673    ///
5674    /// Use `--all-versions` to view all available patch versions.
5675    ///
5676    /// Use `--only-installed` to omit available downloads.
5677    #[command(alias = "ls")]
5678    List(PythonListArgs),
5679
5680    /// Download and install Python versions.
5681    ///
5682    /// Supports CPython and PyPy. CPython distributions are downloaded from the Astral
5683    /// `python-build-standalone` project. PyPy distributions are downloaded from `python.org`. The
5684    /// available Python versions are bundled with each uv release. To install new Python versions,
5685    /// you may need upgrade uv.
5686    ///
5687    /// Python versions are installed into the uv Python directory, which can be retrieved with `uv
5688    /// python dir`.
5689    ///
5690    /// By default, Python executables are added to a directory on the path with a minor version
5691    /// suffix, e.g., `python3.13`. To install `python3` and `python`, use the `--default` flag. Use
5692    /// `uv python dir --bin` to see the target directory.
5693    ///
5694    /// Multiple Python versions may be requested.
5695    ///
5696    /// See `uv help python` to view supported request formats.
5697    Install(PythonInstallArgs),
5698
5699    /// Upgrade installed Python versions.
5700    ///
5701    /// Upgrades versions to the latest supported patch release. Requires the `python-upgrade`
5702    /// preview feature.
5703    ///
5704    /// A target Python minor version to upgrade may be provided, e.g., `3.13`. Multiple versions
5705    /// may be provided to perform more than one upgrade.
5706    ///
5707    /// If no target version is provided, then uv will upgrade all managed CPython versions.
5708    ///
5709    /// During an upgrade, uv will not uninstall outdated patch versions.
5710    ///
5711    /// When an upgrade is performed, virtual environments created by uv will automatically
5712    /// use the new version. However, if the virtual environment was created before the
5713    /// upgrade functionality was added, it will continue to use the old Python version; to enable
5714    /// upgrades, the environment must be recreated.
5715    ///
5716    /// Upgrades are not yet supported for alternative implementations, like PyPy.
5717    Upgrade(PythonUpgradeArgs),
5718
5719    /// Search for a Python installation.
5720    ///
5721    /// Displays the path to the Python executable.
5722    ///
5723    /// See `uv help python` to view supported request formats and details on discovery behavior.
5724    Find(PythonFindArgs),
5725
5726    /// Pin to a specific Python version.
5727    ///
5728    /// Writes the pinned Python version to a `.python-version` file, which is used by other uv
5729    /// commands to determine the required Python version.
5730    ///
5731    /// If no version is provided, uv will look for an existing `.python-version` file and display
5732    /// the currently pinned version. If no `.python-version` file is found, uv will exit with an
5733    /// error.
5734    ///
5735    /// See `uv help python` to view supported request formats.
5736    Pin(PythonPinArgs),
5737
5738    /// Show the uv Python installation directory.
5739    ///
5740    /// By default, Python installations are stored in the uv data directory at
5741    /// `$XDG_DATA_HOME/uv/python` or `$HOME/.local/share/uv/python` on Unix and
5742    /// `%APPDATA%\uv\data\python` on Windows.
5743    ///
5744    /// The Python installation directory may be overridden with `$UV_PYTHON_INSTALL_DIR`.
5745    ///
5746    /// To view the directory where uv installs Python executables instead, use the `--bin` flag.
5747    /// The Python executable directory may be overridden with `$UV_PYTHON_BIN_DIR`. Note that
5748    /// Python executables are only installed when preview mode is enabled.
5749    Dir(PythonDirArgs),
5750
5751    /// Uninstall Python versions.
5752    Uninstall(PythonUninstallArgs),
5753
5754    /// Ensure that the Python executable directory is on the `PATH`.
5755    ///
5756    /// If the Python executable directory is not present on the `PATH`, uv will attempt to add it to
5757    /// the relevant shell configuration files.
5758    ///
5759    /// If the shell configuration files already include a blurb to add the executable directory to
5760    /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5761    ///
5762    /// The Python executable directory is determined according to the XDG standard and can be
5763    /// retrieved with `uv python dir --bin`.
5764    #[command(alias = "ensurepath")]
5765    UpdateShell,
5766}
5767
5768#[derive(Args)]
5769pub struct PythonListArgs {
5770    /// A Python request to filter by.
5771    ///
5772    /// See `uv help python` to view supported request formats.
5773    pub request: Option<String>,
5774
5775    /// List all Python versions, including old patch versions.
5776    ///
5777    /// By default, only the latest patch version is shown for each minor version.
5778    #[arg(long)]
5779    pub all_versions: bool,
5780
5781    /// List Python downloads for all platforms.
5782    ///
5783    /// By default, only downloads for the current platform are shown.
5784    #[arg(long)]
5785    pub all_platforms: bool,
5786
5787    /// List Python downloads for all architectures.
5788    ///
5789    /// By default, only downloads for the current architecture are shown.
5790    #[arg(long, alias = "all_architectures")]
5791    pub all_arches: bool,
5792
5793    /// Only show installed Python versions.
5794    ///
5795    /// By default, installed distributions and available downloads for the current platform are shown.
5796    #[arg(long, conflicts_with("only_downloads"))]
5797    pub only_installed: bool,
5798
5799    /// Only show available Python downloads.
5800    ///
5801    /// By default, installed distributions and available downloads for the current platform are shown.
5802    #[arg(long, conflicts_with("only_installed"))]
5803    pub only_downloads: bool,
5804
5805    /// Show the URLs of available Python downloads.
5806    ///
5807    /// By default, these display as `<download available>`.
5808    #[arg(long)]
5809    pub show_urls: bool,
5810
5811    /// Select the output format.
5812    #[arg(long, value_enum, default_value_t = PythonListFormat::default())]
5813    pub output_format: PythonListFormat,
5814
5815    /// URL pointing to JSON of custom Python installations.
5816    #[arg(long)]
5817    pub python_downloads_json_url: Option<String>,
5818}
5819
5820#[derive(Args)]
5821pub struct PythonDirArgs {
5822    /// Show the directory into which `uv python` will install Python executables.
5823    ///
5824    /// Note that this directory is only used when installing Python with preview mode enabled.
5825    ///
5826    /// The Python executable directory is determined according to the XDG standard and is derived
5827    /// from the following environment variables, in order of preference:
5828    ///
5829    /// - `$UV_PYTHON_BIN_DIR`
5830    /// - `$XDG_BIN_HOME`
5831    /// - `$XDG_DATA_HOME/../bin`
5832    /// - `$HOME/.local/bin`
5833    #[arg(long, verbatim_doc_comment)]
5834    pub bin: bool,
5835}
5836
5837#[derive(Args)]
5838pub struct PythonInstallArgs {
5839    /// The directory to store the Python installation in.
5840    ///
5841    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
5842    /// discover the Python installation.
5843    ///
5844    /// See `uv python dir` to view the current Python installation directory. Defaults to
5845    /// `~/.local/share/uv/python`.
5846    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)]
5847    pub install_dir: Option<PathBuf>,
5848
5849    /// Install a Python executable into the `bin` directory.
5850    ///
5851    /// This is the default behavior. If this flag is provided explicitly, uv will error if the
5852    /// executable cannot be installed.
5853    ///
5854    /// This can also be set with `UV_PYTHON_INSTALL_BIN=1`.
5855    ///
5856    /// See `UV_PYTHON_BIN_DIR` to customize the target directory.
5857    #[arg(long, overrides_with("no_bin"), hide = true)]
5858    pub bin: bool,
5859
5860    /// Do not install a Python executable into the `bin` directory.
5861    ///
5862    /// This can also be set with `UV_PYTHON_INSTALL_BIN=0`.
5863    #[arg(long, overrides_with("bin"), conflicts_with("default"))]
5864    pub no_bin: bool,
5865
5866    /// Register the Python installation in the Windows registry.
5867    ///
5868    /// This is the default behavior on Windows. If this flag is provided explicitly, uv will error if the
5869    /// registry entry cannot be created.
5870    ///
5871    /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=1`.
5872    #[arg(long, overrides_with("no_registry"), hide = true)]
5873    pub registry: bool,
5874
5875    /// Do not register the Python installation in the Windows registry.
5876    ///
5877    /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=0`.
5878    #[arg(long, overrides_with("registry"))]
5879    pub no_registry: bool,
5880
5881    /// The Python version(s) to install.
5882    ///
5883    /// If not provided, the requested Python version(s) will be read from the `UV_PYTHON`
5884    /// environment variable then `.python-versions` or `.python-version` files. If none of the
5885    /// above are present, uv will check if it has installed any Python versions. If not, it will
5886    /// install the latest stable version of Python.
5887    ///
5888    /// See `uv help python` to view supported request formats.
5889    #[arg(env = EnvVars::UV_PYTHON)]
5890    pub targets: Vec<String>,
5891
5892    /// Set the URL to use as the source for downloading Python installations.
5893    ///
5894    /// The provided URL will replace
5895    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
5896    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
5897    ///
5898    /// Distributions can be read from a local directory by using the `file://` URL scheme.
5899    #[arg(long)]
5900    pub mirror: Option<String>,
5901
5902    /// Set the URL to use as the source for downloading PyPy installations.
5903    ///
5904    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
5905    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
5906    ///
5907    /// Distributions can be read from a local directory by using the `file://` URL scheme.
5908    #[arg(long)]
5909    pub pypy_mirror: Option<String>,
5910
5911    /// URL pointing to JSON of custom Python installations.
5912    #[arg(long)]
5913    pub python_downloads_json_url: Option<String>,
5914
5915    /// Reinstall the requested Python version, if it's already installed.
5916    ///
5917    /// By default, uv will exit successfully if the version is already
5918    /// installed.
5919    #[arg(long, short)]
5920    pub reinstall: bool,
5921
5922    /// Replace existing Python executables during installation.
5923    ///
5924    /// By default, uv will refuse to replace executables that it does not manage.
5925    ///
5926    /// Implies `--reinstall`.
5927    #[arg(long, short)]
5928    pub force: bool,
5929
5930    /// Upgrade existing Python installations to the latest patch version.
5931    ///
5932    /// By default, uv will not upgrade already-installed Python versions to newer patch releases.
5933    /// With `--upgrade`, uv will upgrade to the latest available patch version for the specified
5934    /// minor version(s).
5935    ///
5936    /// If the requested versions are not yet installed, uv will install them.
5937    ///
5938    /// This option is only supported for minor version requests, e.g., `3.12`; uv will exit with an
5939    /// error if a patch version, e.g., `3.12.2`, is requested.
5940    #[arg(long, short = 'U')]
5941    pub upgrade: bool,
5942
5943    /// Use as the default Python version.
5944    ///
5945    /// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
5946    /// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
5947    /// also installed.
5948    ///
5949    /// Alternative Python variants will still include their tag. For example, installing
5950    /// 3.13+freethreaded with `--default` will include in `python3t` and `pythont`, not `python3`
5951    /// and `python`.
5952    ///
5953    /// If multiple Python versions are requested, uv will exit with an error.
5954    #[arg(long, conflicts_with("no_bin"))]
5955    pub default: bool,
5956}
5957
5958impl PythonInstallArgs {
5959    #[must_use]
5960    pub fn install_mirrors(&self) -> PythonInstallMirrors {
5961        PythonInstallMirrors {
5962            python_install_mirror: self.mirror.clone(),
5963            pypy_install_mirror: self.pypy_mirror.clone(),
5964            python_downloads_json_url: self.python_downloads_json_url.clone(),
5965        }
5966    }
5967}
5968
5969#[derive(Args)]
5970pub struct PythonUpgradeArgs {
5971    /// The directory Python installations are stored in.
5972    ///
5973    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
5974    /// discover the Python installation.
5975    ///
5976    /// See `uv python dir` to view the current Python installation directory. Defaults to
5977    /// `~/.local/share/uv/python`.
5978    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)]
5979    pub install_dir: Option<PathBuf>,
5980
5981    /// The Python minor version(s) to upgrade.
5982    ///
5983    /// If no target version is provided, then uv will upgrade all managed CPython versions.
5984    #[arg(env = EnvVars::UV_PYTHON)]
5985    pub targets: Vec<String>,
5986
5987    /// Set the URL to use as the source for downloading Python installations.
5988    ///
5989    /// The provided URL will replace
5990    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
5991    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
5992    ///
5993    /// Distributions can be read from a local directory by using the `file://` URL scheme.
5994    #[arg(long)]
5995    pub mirror: Option<String>,
5996
5997    /// Set the URL to use as the source for downloading PyPy installations.
5998    ///
5999    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6000    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6001    ///
6002    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6003    #[arg(long)]
6004    pub pypy_mirror: Option<String>,
6005
6006    /// Reinstall the latest Python patch, if it's already installed.
6007    ///
6008    /// By default, uv will exit successfully if the latest patch is already
6009    /// installed.
6010    #[arg(long, short)]
6011    pub reinstall: bool,
6012
6013    /// URL pointing to JSON of custom Python installations.
6014    #[arg(long)]
6015    pub python_downloads_json_url: Option<String>,
6016}
6017
6018impl PythonUpgradeArgs {
6019    #[must_use]
6020    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6021        PythonInstallMirrors {
6022            python_install_mirror: self.mirror.clone(),
6023            pypy_install_mirror: self.pypy_mirror.clone(),
6024            python_downloads_json_url: self.python_downloads_json_url.clone(),
6025        }
6026    }
6027}
6028
6029#[derive(Args)]
6030pub struct PythonUninstallArgs {
6031    /// The directory where the Python was installed.
6032    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR)]
6033    pub install_dir: Option<PathBuf>,
6034
6035    /// The Python version(s) to uninstall.
6036    ///
6037    /// See `uv help python` to view supported request formats.
6038    #[arg(required = true)]
6039    pub targets: Vec<String>,
6040
6041    /// Uninstall all managed Python versions.
6042    #[arg(long, conflicts_with("targets"))]
6043    pub all: bool,
6044}
6045
6046#[derive(Args)]
6047pub struct PythonFindArgs {
6048    /// The Python request.
6049    ///
6050    /// See `uv help python` to view supported request formats.
6051    pub request: Option<String>,
6052
6053    /// Avoid discovering a project or workspace.
6054    ///
6055    /// Otherwise, when no request is provided, the Python requirement of a project in the current
6056    /// directory or parent directories will be used.
6057    #[arg(long, alias = "no_workspace")]
6058    pub no_project: bool,
6059
6060    /// Only find system Python interpreters.
6061    ///
6062    /// By default, uv will report the first Python interpreter it would use, including those in an
6063    /// active virtual environment or a virtual environment in the current working directory or any
6064    /// parent directory.
6065    ///
6066    /// The `--system` option instructs uv to skip virtual environment Python interpreters and
6067    /// restrict its search to the system path.
6068    #[arg(
6069        long,
6070        env = EnvVars::UV_SYSTEM_PYTHON,
6071        value_parser = clap::builder::BoolishValueParser::new(),
6072        overrides_with("no_system")
6073    )]
6074    pub system: bool,
6075
6076    #[arg(long, overrides_with("system"), hide = true)]
6077    pub no_system: bool,
6078
6079    /// Find the environment for a Python script, rather than the current project.
6080    #[arg(
6081        long,
6082        conflicts_with = "request",
6083        conflicts_with = "no_project",
6084        conflicts_with = "system",
6085        conflicts_with = "no_system"
6086    )]
6087    pub script: Option<PathBuf>,
6088
6089    /// Show the Python version that would be used instead of the path to the interpreter.
6090    #[arg(long)]
6091    pub show_version: bool,
6092
6093    /// URL pointing to JSON of custom Python installations.
6094    #[arg(long)]
6095    pub python_downloads_json_url: Option<String>,
6096}
6097
6098#[derive(Args)]
6099pub struct PythonPinArgs {
6100    /// The Python version request.
6101    ///
6102    /// uv supports more formats than other tools that read `.python-version` files, i.e., `pyenv`.
6103    /// If compatibility with those tools is needed, only use version numbers instead of complex
6104    /// requests such as `cpython@3.10`.
6105    ///
6106    /// If no request is provided, the currently pinned version will be shown.
6107    ///
6108    /// See `uv help python` to view supported request formats.
6109    pub request: Option<String>,
6110
6111    /// Write the resolved Python interpreter path instead of the request.
6112    ///
6113    /// Ensures that the exact same interpreter is used.
6114    ///
6115    /// This option is usually not safe to use when committing the `.python-version` file to version
6116    /// control.
6117    #[arg(long, overrides_with("resolved"))]
6118    pub resolved: bool,
6119
6120    #[arg(long, overrides_with("no_resolved"), hide = true)]
6121    pub no_resolved: bool,
6122
6123    /// Avoid validating the Python pin is compatible with the project or workspace.
6124    ///
6125    /// By default, a project or workspace is discovered in the current directory or any parent
6126    /// directory. If a workspace is found, the Python pin is validated against the workspace's
6127    /// `requires-python` constraint.
6128    #[arg(long, alias = "no-workspace")]
6129    pub no_project: bool,
6130
6131    /// Update the global Python version pin.
6132    ///
6133    /// Writes the pinned Python version to a `.python-version` file in the uv user configuration
6134    /// directory: `XDG_CONFIG_HOME/uv` on Linux/macOS and `%APPDATA%/uv` on Windows.
6135    ///
6136    /// When a local Python version pin is not found in the working directory or an ancestor
6137    /// directory, this version will be used instead.
6138    #[arg(long)]
6139    pub global: bool,
6140
6141    /// Remove the Python version pin.
6142    #[arg(long, conflicts_with = "request", conflicts_with = "resolved")]
6143    pub rm: bool,
6144}
6145
6146#[derive(Args)]
6147pub struct AuthLogoutArgs {
6148    /// The domain or URL of the service to logout from.
6149    pub service: Service,
6150
6151    /// The username to logout.
6152    #[arg(long, short)]
6153    pub username: Option<String>,
6154
6155    /// The keyring provider to use for storage of credentials.
6156    ///
6157    /// Only `--keyring-provider native` is supported for `logout`, which uses the system keyring
6158    /// via an integration built into uv.
6159    #[arg(
6160        long,
6161        value_enum,
6162        env = EnvVars::UV_KEYRING_PROVIDER,
6163    )]
6164    pub keyring_provider: Option<KeyringProviderType>,
6165}
6166
6167#[derive(Args)]
6168pub struct AuthLoginArgs {
6169    /// The domain or URL of the service to log into.
6170    pub service: Service,
6171
6172    /// The username to use for the service.
6173    #[arg(long, short, conflicts_with = "token")]
6174    pub username: Option<String>,
6175
6176    /// The password to use for the service.
6177    ///
6178    /// Use `-` to read the password from stdin.
6179    #[arg(long, conflicts_with = "token")]
6180    pub password: Option<String>,
6181
6182    /// The token to use for the service.
6183    ///
6184    /// The username will be set to `__token__`.
6185    ///
6186    /// Use `-` to read the token from stdin.
6187    #[arg(long, short, conflicts_with = "username", conflicts_with = "password")]
6188    pub token: Option<String>,
6189
6190    /// The keyring provider to use for storage of credentials.
6191    ///
6192    /// Only `--keyring-provider native` is supported for `login`, which uses the system keyring via
6193    /// an integration built into uv.
6194    #[arg(
6195        long,
6196        value_enum,
6197        env = EnvVars::UV_KEYRING_PROVIDER,
6198    )]
6199    pub keyring_provider: Option<KeyringProviderType>,
6200}
6201
6202#[derive(Args)]
6203pub struct AuthTokenArgs {
6204    /// The domain or URL of the service to lookup.
6205    pub service: Service,
6206
6207    /// The username to lookup.
6208    #[arg(long, short)]
6209    pub username: Option<String>,
6210
6211    /// The keyring provider to use for reading credentials.
6212    #[arg(
6213        long,
6214        value_enum,
6215        env = EnvVars::UV_KEYRING_PROVIDER,
6216    )]
6217    pub keyring_provider: Option<KeyringProviderType>,
6218}
6219
6220#[derive(Args)]
6221pub struct AuthDirArgs {
6222    /// The domain or URL of the service to lookup.
6223    pub service: Option<Service>,
6224}
6225
6226#[derive(Args)]
6227pub struct AuthHelperArgs {
6228    #[command(subcommand)]
6229    pub command: AuthHelperCommand,
6230
6231    /// The credential helper protocol to use
6232    #[arg(long, value_enum, required = true)]
6233    pub protocol: AuthHelperProtocol,
6234}
6235
6236/// Credential helper protocols supported by uv
6237#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
6238pub enum AuthHelperProtocol {
6239    /// Bazel credential helper protocol as described in [the
6240    /// spec](https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md)
6241    Bazel,
6242}
6243
6244#[derive(Subcommand)]
6245pub enum AuthHelperCommand {
6246    /// Retrieve credentials for a URI
6247    Get,
6248}
6249
6250#[derive(Args)]
6251pub struct GenerateShellCompletionArgs {
6252    /// The shell to generate the completion script for
6253    pub shell: clap_complete_command::Shell,
6254
6255    // Hide unused global options.
6256    #[arg(long, short, hide = true)]
6257    pub no_cache: bool,
6258    #[arg(long, hide = true)]
6259    pub cache_dir: Option<PathBuf>,
6260
6261    #[arg(long, hide = true)]
6262    pub python_preference: Option<PythonPreference>,
6263    #[arg(long, hide = true)]
6264    pub no_python_downloads: bool,
6265
6266    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
6267    pub quiet: u8,
6268    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
6269    pub verbose: u8,
6270    #[arg(long, conflicts_with = "no_color", hide = true)]
6271    pub color: Option<ColorChoice>,
6272    #[arg(long, hide = true)]
6273    pub native_tls: bool,
6274    #[arg(long, hide = true)]
6275    pub offline: bool,
6276    #[arg(long, hide = true)]
6277    pub no_progress: bool,
6278    #[arg(long, hide = true)]
6279    pub config_file: Option<PathBuf>,
6280    #[arg(long, hide = true)]
6281    pub no_config: bool,
6282    #[arg(long, short, action = clap::ArgAction::HelpShort, hide = true)]
6283    pub help: Option<bool>,
6284    #[arg(short = 'V', long, hide = true)]
6285    pub version: bool,
6286}
6287
6288#[derive(Args)]
6289pub struct IndexArgs {
6290    /// The URLs to use when resolving dependencies, in addition to the default index.
6291    ///
6292    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6293    /// directory laid out in the same format.
6294    ///
6295    /// All indexes provided via this flag take priority over the index specified by
6296    /// `--default-index` (which defaults to PyPI). When multiple `--index` flags are provided,
6297    /// earlier values take priority.
6298    ///
6299    /// Index names are not supported as values. Relative paths must be disambiguated from index
6300    /// names with `./` or `../` on Unix or `.\\`, `..\\`, `./` or `../` on Windows.
6301    //
6302    // The nested Vec structure (`Vec<Vec<Maybe<Index>>>`) is required for clap's
6303    // value parsing mechanism, which processes one value at a time, in order to handle
6304    // `UV_INDEX` the same way pip handles `PIP_EXTRA_INDEX_URL`.
6305    #[arg(long, env = EnvVars::UV_INDEX, value_parser = parse_indices, help_heading = "Index options")]
6306    pub index: Option<Vec<Vec<Maybe<Index>>>>,
6307
6308    /// The URL of the default package index (by default: <https://pypi.org/simple>).
6309    ///
6310    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6311    /// directory laid out in the same format.
6312    ///
6313    /// The index given by this flag is given lower priority than all other indexes specified via
6314    /// the `--index` flag.
6315    #[arg(long, env = EnvVars::UV_DEFAULT_INDEX, value_parser = parse_default_index, help_heading = "Index options")]
6316    pub default_index: Option<Maybe<Index>>,
6317
6318    /// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default:
6319    /// <https://pypi.org/simple>).
6320    ///
6321    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6322    /// directory laid out in the same format.
6323    ///
6324    /// The index given by this flag is given lower priority than all other indexes specified via
6325    /// the `--extra-index-url` flag.
6326    #[arg(long, short, env = EnvVars::UV_INDEX_URL, value_parser = parse_index_url, help_heading = "Index options")]
6327    pub index_url: Option<Maybe<PipIndex>>,
6328
6329    /// (Deprecated: use `--index` instead) Extra URLs of package indexes to use, in addition to
6330    /// `--index-url`.
6331    ///
6332    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6333    /// directory laid out in the same format.
6334    ///
6335    /// All indexes provided via this flag take priority over the index specified by `--index-url`
6336    /// (which defaults to PyPI). When multiple `--extra-index-url` flags are provided, earlier
6337    /// values take priority.
6338    #[arg(long, env = EnvVars::UV_EXTRA_INDEX_URL, value_delimiter = ' ', value_parser = parse_extra_index_url, help_heading = "Index options")]
6339    pub extra_index_url: Option<Vec<Maybe<PipExtraIndex>>>,
6340
6341    /// Locations to search for candidate distributions, in addition to those found in the registry
6342    /// indexes.
6343    ///
6344    /// If a path, the target must be a directory that contains packages as wheel files (`.whl`) or
6345    /// source distributions (e.g., `.tar.gz` or `.zip`) at the top level.
6346    ///
6347    /// If a URL, the page must contain a flat list of links to package files adhering to the
6348    /// formats described above.
6349    #[arg(
6350        long,
6351        short,
6352        env = EnvVars::UV_FIND_LINKS,
6353        value_delimiter = ',',
6354        value_parser = parse_find_links,
6355        help_heading = "Index options"
6356    )]
6357    pub find_links: Option<Vec<Maybe<PipFindLinks>>>,
6358
6359    /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
6360    /// provided via `--find-links`.
6361    #[arg(long, help_heading = "Index options")]
6362    pub no_index: bool,
6363}
6364
6365#[derive(Args)]
6366pub struct RefreshArgs {
6367    /// Refresh all cached data.
6368    #[arg(
6369        long,
6370        conflicts_with("offline"),
6371        overrides_with("no_refresh"),
6372        help_heading = "Cache options"
6373    )]
6374    pub refresh: bool,
6375
6376    #[arg(
6377        long,
6378        conflicts_with("offline"),
6379        overrides_with("refresh"),
6380        hide = true,
6381        help_heading = "Cache options"
6382    )]
6383    pub no_refresh: bool,
6384
6385    /// Refresh cached data for a specific package.
6386    #[arg(long, help_heading = "Cache options")]
6387    pub refresh_package: Vec<PackageName>,
6388}
6389
6390#[derive(Args)]
6391pub struct BuildOptionsArgs {
6392    /// Don't build source distributions.
6393    ///
6394    /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
6395    /// already-built source distributions will be reused, but operations that require building
6396    /// distributions will exit with an error.
6397    #[arg(
6398        long,
6399        env = EnvVars::UV_NO_BUILD,
6400        overrides_with("build"),
6401        value_parser = clap::builder::BoolishValueParser::new(),
6402        help_heading = "Build options",
6403    )]
6404    pub no_build: bool,
6405
6406    #[arg(
6407        long,
6408        overrides_with("no_build"),
6409        hide = true,
6410        help_heading = "Build options"
6411    )]
6412    pub build: bool,
6413
6414    /// Don't build source distributions for a specific package.
6415    #[arg(long, help_heading = "Build options", env = EnvVars::UV_NO_BUILD_PACKAGE, value_delimiter = ' ')]
6416    pub no_build_package: Vec<PackageName>,
6417
6418    /// Don't install pre-built wheels.
6419    ///
6420    /// The given packages will be built and installed from source. The resolver will still use
6421    /// pre-built wheels to extract package metadata, if available.
6422    #[arg(
6423        long,
6424        env = EnvVars::UV_NO_BINARY,
6425        overrides_with("binary"),
6426        value_parser = clap::builder::BoolishValueParser::new(),
6427        help_heading = "Build options"
6428    )]
6429    pub no_binary: bool,
6430
6431    #[arg(
6432        long,
6433        overrides_with("no_binary"),
6434        hide = true,
6435        help_heading = "Build options"
6436    )]
6437    pub binary: bool,
6438
6439    /// Don't install pre-built wheels for a specific package.
6440    #[arg(long, help_heading = "Build options", env = EnvVars::UV_NO_BINARY_PACKAGE, value_delimiter = ' ')]
6441    pub no_binary_package: Vec<PackageName>,
6442}
6443
6444/// Arguments that are used by commands that need to install (but not resolve) packages.
6445#[derive(Args)]
6446pub struct InstallerArgs {
6447    #[command(flatten)]
6448    pub index_args: IndexArgs,
6449
6450    /// Reinstall all packages, regardless of whether they're already installed. Implies
6451    /// `--refresh`.
6452    #[arg(
6453        long,
6454        alias = "force-reinstall",
6455        overrides_with("no_reinstall"),
6456        help_heading = "Installer options"
6457    )]
6458    pub reinstall: bool,
6459
6460    #[arg(
6461        long,
6462        overrides_with("reinstall"),
6463        hide = true,
6464        help_heading = "Installer options"
6465    )]
6466    pub no_reinstall: bool,
6467
6468    /// Reinstall a specific package, regardless of whether it's already installed. Implies
6469    /// `--refresh-package`.
6470    #[arg(long, help_heading = "Installer options")]
6471    pub reinstall_package: Vec<PackageName>,
6472
6473    /// The strategy to use when resolving against multiple index URLs.
6474    ///
6475    /// By default, uv will stop at the first index on which a given package is available, and limit
6476    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6477    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6478    /// to an alternate index.
6479    #[arg(
6480        long,
6481        value_enum,
6482        env = EnvVars::UV_INDEX_STRATEGY,
6483        help_heading = "Index options"
6484    )]
6485    pub index_strategy: Option<IndexStrategy>,
6486
6487    /// Attempt to use `keyring` for authentication for index URLs.
6488    ///
6489    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6490    /// the `keyring` CLI to handle authentication.
6491    ///
6492    /// Defaults to `disabled`.
6493    #[arg(
6494        long,
6495        value_enum,
6496        env = EnvVars::UV_KEYRING_PROVIDER,
6497        help_heading = "Index options"
6498    )]
6499    pub keyring_provider: Option<KeyringProviderType>,
6500
6501    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
6502    #[arg(
6503        long,
6504        short = 'C',
6505        alias = "config-settings",
6506        help_heading = "Build options"
6507    )]
6508    pub config_setting: Option<Vec<ConfigSettingEntry>>,
6509
6510    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
6511    #[arg(
6512        long,
6513        alias = "config-settings-package",
6514        help_heading = "Build options"
6515    )]
6516    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
6517
6518    /// Disable isolation when building source distributions.
6519    ///
6520    /// Assumes that build dependencies specified by PEP 518 are already installed.
6521    #[arg(
6522        long,
6523        overrides_with("build_isolation"),
6524        help_heading = "Build options",
6525        env = EnvVars::UV_NO_BUILD_ISOLATION,
6526        value_parser = clap::builder::BoolishValueParser::new(),
6527    )]
6528    pub no_build_isolation: bool,
6529
6530    #[arg(
6531        long,
6532        overrides_with("no_build_isolation"),
6533        hide = true,
6534        help_heading = "Build options"
6535    )]
6536    pub build_isolation: bool,
6537
6538    /// Limit candidate packages to those that were uploaded prior to the given date.
6539    ///
6540    /// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
6541    /// format (e.g., `2006-12-02`) in your system's configured time zone.
6542    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6543    pub exclude_newer: Option<ExcludeNewerTimestamp>,
6544
6545    /// Limit candidate packages for specific packages to those that were uploaded prior to the given date.
6546    ///
6547    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339 timestamp
6548    /// (e.g., `2006-12-02T02:07:43Z`) or local date (e.g., `2006-12-02`) in your system's configured time zone.
6549    ///
6550    /// Can be provided multiple times for different packages.
6551    #[arg(long, help_heading = "Resolver options")]
6552    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6553
6554    /// The method to use when installing packages from the global cache.
6555    ///
6556    /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
6557    /// Windows.
6558    ///
6559    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
6560    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
6561    /// will break all installed packages by way of removing the underlying source files. Use
6562    /// symlinks with caution.
6563    #[arg(
6564        long,
6565        value_enum,
6566        env = EnvVars::UV_LINK_MODE,
6567        help_heading = "Installer options"
6568    )]
6569    pub link_mode: Option<uv_install_wheel::LinkMode>,
6570
6571    /// Compile Python files to bytecode after installation.
6572    ///
6573    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6574    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6575    /// in which start time is critical, such as CLI applications and Docker containers, this option
6576    /// can be enabled to trade longer installation times for faster start times.
6577    ///
6578    /// When enabled, uv will process the entire site-packages directory (including packages that
6579    /// are not being modified by the current operation) for consistency. Like pip, it will also
6580    /// ignore errors.
6581    #[arg(
6582        long,
6583        alias = "compile",
6584        overrides_with("no_compile_bytecode"),
6585        help_heading = "Installer options",
6586        env = EnvVars::UV_COMPILE_BYTECODE,
6587        value_parser = clap::builder::BoolishValueParser::new(),
6588    )]
6589    pub compile_bytecode: bool,
6590
6591    #[arg(
6592        long,
6593        alias = "no-compile",
6594        overrides_with("compile_bytecode"),
6595        hide = true,
6596        help_heading = "Installer options"
6597    )]
6598    pub no_compile_bytecode: bool,
6599
6600    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6601    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6602    /// URL, or local path sources.
6603    #[arg(
6604        long,
6605        env = EnvVars::UV_NO_SOURCES,
6606        value_parser = clap::builder::BoolishValueParser::new(),
6607        help_heading = "Resolver options"
6608    )]
6609    pub no_sources: bool,
6610}
6611
6612/// Arguments that are used by commands that need to resolve (but not install) packages.
6613#[derive(Args)]
6614pub struct ResolverArgs {
6615    #[command(flatten)]
6616    pub index_args: IndexArgs,
6617
6618    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
6619    /// `--refresh`.
6620    #[arg(
6621        long,
6622        short = 'U',
6623        overrides_with("no_upgrade"),
6624        help_heading = "Resolver options"
6625    )]
6626    pub upgrade: bool,
6627
6628    #[arg(
6629        long,
6630        overrides_with("upgrade"),
6631        hide = true,
6632        help_heading = "Resolver options"
6633    )]
6634    pub no_upgrade: bool,
6635
6636    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
6637    /// file. Implies `--refresh-package`.
6638    #[arg(long, short = 'P', help_heading = "Resolver options")]
6639    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
6640
6641    /// The strategy to use when resolving against multiple index URLs.
6642    ///
6643    /// By default, uv will stop at the first index on which a given package is available, and limit
6644    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6645    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6646    /// to an alternate index.
6647    #[arg(
6648        long,
6649        value_enum,
6650        env = EnvVars::UV_INDEX_STRATEGY,
6651        help_heading = "Index options"
6652    )]
6653    pub index_strategy: Option<IndexStrategy>,
6654
6655    /// Attempt to use `keyring` for authentication for index URLs.
6656    ///
6657    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6658    /// the `keyring` CLI to handle authentication.
6659    ///
6660    /// Defaults to `disabled`.
6661    #[arg(
6662        long,
6663        value_enum,
6664        env = EnvVars::UV_KEYRING_PROVIDER,
6665        help_heading = "Index options"
6666    )]
6667    pub keyring_provider: Option<KeyringProviderType>,
6668
6669    /// The strategy to use when selecting between the different compatible versions for a given
6670    /// package requirement.
6671    ///
6672    /// By default, uv will use the latest compatible version of each package (`highest`).
6673    #[arg(
6674        long,
6675        value_enum,
6676        env = EnvVars::UV_RESOLUTION,
6677        help_heading = "Resolver options"
6678    )]
6679    pub resolution: Option<ResolutionMode>,
6680
6681    /// The strategy to use when considering pre-release versions.
6682    ///
6683    /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
6684    /// with first-party requirements that contain an explicit pre-release marker in the declared
6685    /// specifiers (`if-necessary-or-explicit`).
6686    #[arg(
6687        long,
6688        value_enum,
6689        env = EnvVars::UV_PRERELEASE,
6690        help_heading = "Resolver options"
6691    )]
6692    pub prerelease: Option<PrereleaseMode>,
6693
6694    #[arg(long, hide = true, help_heading = "Resolver options")]
6695    pub pre: bool,
6696
6697    /// The strategy to use when selecting multiple versions of a given package across Python
6698    /// versions and platforms.
6699    ///
6700    /// By default, uv will optimize for selecting the latest version of each package for each
6701    /// supported Python version (`requires-python`), while minimizing the number of selected
6702    /// versions across platforms.
6703    ///
6704    /// Under `fewest`, uv will minimize the number of selected versions for each package,
6705    /// preferring older versions that are compatible with a wider range of supported Python
6706    /// versions or platforms.
6707    #[arg(
6708        long,
6709        value_enum,
6710        env = EnvVars::UV_FORK_STRATEGY,
6711        help_heading = "Resolver options"
6712    )]
6713    pub fork_strategy: Option<ForkStrategy>,
6714
6715    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
6716    #[arg(
6717        long,
6718        short = 'C',
6719        alias = "config-settings",
6720        help_heading = "Build options"
6721    )]
6722    pub config_setting: Option<Vec<ConfigSettingEntry>>,
6723
6724    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
6725    #[arg(
6726        long,
6727        alias = "config-settings-package",
6728        help_heading = "Build options"
6729    )]
6730    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
6731
6732    /// Disable isolation when building source distributions.
6733    ///
6734    /// Assumes that build dependencies specified by PEP 518 are already installed.
6735    #[arg(
6736        long,
6737        overrides_with("build_isolation"),
6738        help_heading = "Build options",
6739        env = EnvVars::UV_NO_BUILD_ISOLATION,
6740        value_parser = clap::builder::BoolishValueParser::new(),
6741    )]
6742    pub no_build_isolation: bool,
6743
6744    /// Disable isolation when building source distributions for a specific package.
6745    ///
6746    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
6747    #[arg(long, help_heading = "Build options")]
6748    pub no_build_isolation_package: Vec<PackageName>,
6749
6750    #[arg(
6751        long,
6752        overrides_with("no_build_isolation"),
6753        hide = true,
6754        help_heading = "Build options"
6755    )]
6756    pub build_isolation: bool,
6757
6758    /// Limit candidate packages to those that were uploaded prior to the given date.
6759    ///
6760    /// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
6761    /// format (e.g., `2006-12-02`) in your system's configured time zone.
6762    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6763    pub exclude_newer: Option<ExcludeNewerTimestamp>,
6764
6765    /// Limit candidate packages for a specific package to those that were uploaded prior to the given date.
6766    ///
6767    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339 timestamp
6768    /// (e.g., `2006-12-02T02:07:43Z`) or local date (e.g., `2006-12-02`) in your system's configured time zone.
6769    ///
6770    /// Can be provided multiple times for different packages.
6771    #[arg(long, help_heading = "Resolver options")]
6772    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6773
6774    /// The method to use when installing packages from the global cache.
6775    ///
6776    /// This option is only used when building source distributions.
6777    ///
6778    /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
6779    /// Windows.
6780    ///
6781    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
6782    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
6783    /// will break all installed packages by way of removing the underlying source files. Use
6784    /// symlinks with caution.
6785    #[arg(
6786        long,
6787        value_enum,
6788        env = EnvVars::UV_LINK_MODE,
6789        help_heading = "Installer options"
6790    )]
6791    pub link_mode: Option<uv_install_wheel::LinkMode>,
6792
6793    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6794    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6795    /// URL, or local path sources.
6796    #[arg(
6797        long,
6798        env = EnvVars::UV_NO_SOURCES,
6799        value_parser = clap::builder::BoolishValueParser::new(),
6800        help_heading = "Resolver options",
6801    )]
6802    pub no_sources: bool,
6803}
6804
6805/// Arguments that are used by commands that need to resolve and install packages.
6806#[derive(Args)]
6807pub struct ResolverInstallerArgs {
6808    #[command(flatten)]
6809    pub index_args: IndexArgs,
6810
6811    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
6812    /// `--refresh`.
6813    #[arg(
6814        long,
6815        short = 'U',
6816        overrides_with("no_upgrade"),
6817        help_heading = "Resolver options"
6818    )]
6819    pub upgrade: bool,
6820
6821    #[arg(
6822        long,
6823        overrides_with("upgrade"),
6824        hide = true,
6825        help_heading = "Resolver options"
6826    )]
6827    pub no_upgrade: bool,
6828
6829    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output file.
6830    /// Implies `--refresh-package`.
6831    #[arg(long, short = 'P', help_heading = "Resolver options")]
6832    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
6833
6834    /// Reinstall all packages, regardless of whether they're already installed. Implies
6835    /// `--refresh`.
6836    #[arg(
6837        long,
6838        alias = "force-reinstall",
6839        overrides_with("no_reinstall"),
6840        help_heading = "Installer options"
6841    )]
6842    pub reinstall: bool,
6843
6844    #[arg(
6845        long,
6846        overrides_with("reinstall"),
6847        hide = true,
6848        help_heading = "Installer options"
6849    )]
6850    pub no_reinstall: bool,
6851
6852    /// Reinstall a specific package, regardless of whether it's already installed. Implies
6853    /// `--refresh-package`.
6854    #[arg(long, help_heading = "Installer options")]
6855    pub reinstall_package: Vec<PackageName>,
6856
6857    /// The strategy to use when resolving against multiple index URLs.
6858    ///
6859    /// By default, uv will stop at the first index on which a given package is available, and limit
6860    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6861    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6862    /// to an alternate index.
6863    #[arg(
6864        long,
6865        value_enum,
6866        env = EnvVars::UV_INDEX_STRATEGY,
6867        help_heading = "Index options"
6868    )]
6869    pub index_strategy: Option<IndexStrategy>,
6870
6871    /// Attempt to use `keyring` for authentication for index URLs.
6872    ///
6873    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6874    /// the `keyring` CLI to handle authentication.
6875    ///
6876    /// Defaults to `disabled`.
6877    #[arg(
6878        long,
6879        value_enum,
6880        env = EnvVars::UV_KEYRING_PROVIDER,
6881        help_heading = "Index options"
6882    )]
6883    pub keyring_provider: Option<KeyringProviderType>,
6884
6885    /// The strategy to use when selecting between the different compatible versions for a given
6886    /// package requirement.
6887    ///
6888    /// By default, uv will use the latest compatible version of each package (`highest`).
6889    #[arg(
6890        long,
6891        value_enum,
6892        env = EnvVars::UV_RESOLUTION,
6893        help_heading = "Resolver options"
6894    )]
6895    pub resolution: Option<ResolutionMode>,
6896
6897    /// The strategy to use when considering pre-release versions.
6898    ///
6899    /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
6900    /// with first-party requirements that contain an explicit pre-release marker in the declared
6901    /// specifiers (`if-necessary-or-explicit`).
6902    #[arg(
6903        long,
6904        value_enum,
6905        env = EnvVars::UV_PRERELEASE,
6906        help_heading = "Resolver options"
6907    )]
6908    pub prerelease: Option<PrereleaseMode>,
6909
6910    #[arg(long, hide = true)]
6911    pub pre: bool,
6912
6913    /// The strategy to use when selecting multiple versions of a given package across Python
6914    /// versions and platforms.
6915    ///
6916    /// By default, uv will optimize for selecting the latest version of each package for each
6917    /// supported Python version (`requires-python`), while minimizing the number of selected
6918    /// versions across platforms.
6919    ///
6920    /// Under `fewest`, uv will minimize the number of selected versions for each package,
6921    /// preferring older versions that are compatible with a wider range of supported Python
6922    /// versions or platforms.
6923    #[arg(
6924        long,
6925        value_enum,
6926        env = EnvVars::UV_FORK_STRATEGY,
6927        help_heading = "Resolver options"
6928    )]
6929    pub fork_strategy: Option<ForkStrategy>,
6930
6931    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
6932    #[arg(
6933        long,
6934        short = 'C',
6935        alias = "config-settings",
6936        help_heading = "Build options"
6937    )]
6938    pub config_setting: Option<Vec<ConfigSettingEntry>>,
6939
6940    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
6941    #[arg(
6942        long,
6943        alias = "config-settings-package",
6944        help_heading = "Build options"
6945    )]
6946    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
6947
6948    /// Disable isolation when building source distributions.
6949    ///
6950    /// Assumes that build dependencies specified by PEP 518 are already installed.
6951    #[arg(
6952        long,
6953        overrides_with("build_isolation"),
6954        help_heading = "Build options",
6955        env = EnvVars::UV_NO_BUILD_ISOLATION,
6956        value_parser = clap::builder::BoolishValueParser::new(),
6957    )]
6958    pub no_build_isolation: bool,
6959
6960    /// Disable isolation when building source distributions for a specific package.
6961    ///
6962    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
6963    #[arg(long, help_heading = "Build options")]
6964    pub no_build_isolation_package: Vec<PackageName>,
6965
6966    #[arg(
6967        long,
6968        overrides_with("no_build_isolation"),
6969        hide = true,
6970        help_heading = "Build options"
6971    )]
6972    pub build_isolation: bool,
6973
6974    /// Limit candidate packages to those that were uploaded prior to the given date.
6975    ///
6976    /// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
6977    /// format (e.g., `2006-12-02`) in your system's configured time zone.
6978    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6979    pub exclude_newer: Option<ExcludeNewerTimestamp>,
6980
6981    /// Limit candidate packages for specific packages to those that were uploaded prior to the given date.
6982    ///
6983    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339 timestamp
6984    /// (e.g., `2006-12-02T02:07:43Z`) or local date (e.g., `2006-12-02`) in your system's configured time zone.
6985    ///
6986    /// Can be provided multiple times for different packages.
6987    #[arg(long, help_heading = "Resolver options")]
6988    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6989
6990    /// The method to use when installing packages from the global cache.
6991    ///
6992    /// Defaults to `clone` (also known as Copy-on-Write) on macOS, and `hardlink` on Linux and
6993    /// Windows.
6994    ///
6995    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
6996    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
6997    /// will break all installed packages by way of removing the underlying source files. Use
6998    /// symlinks with caution.
6999    #[arg(
7000        long,
7001        value_enum,
7002        env = EnvVars::UV_LINK_MODE,
7003        help_heading = "Installer options"
7004    )]
7005    pub link_mode: Option<uv_install_wheel::LinkMode>,
7006
7007    /// Compile Python files to bytecode after installation.
7008    ///
7009    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7010    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7011    /// in which start time is critical, such as CLI applications and Docker containers, this option
7012    /// can be enabled to trade longer installation times for faster start times.
7013    ///
7014    /// When enabled, uv will process the entire site-packages directory (including packages that
7015    /// are not being modified by the current operation) for consistency. Like pip, it will also
7016    /// ignore errors.
7017    #[arg(
7018        long,
7019        alias = "compile",
7020        overrides_with("no_compile_bytecode"),
7021        help_heading = "Installer options",
7022        env = EnvVars::UV_COMPILE_BYTECODE,
7023        value_parser = clap::builder::BoolishValueParser::new(),
7024    )]
7025    pub compile_bytecode: bool,
7026
7027    #[arg(
7028        long,
7029        alias = "no-compile",
7030        overrides_with("compile_bytecode"),
7031        hide = true,
7032        help_heading = "Installer options"
7033    )]
7034    pub no_compile_bytecode: bool,
7035
7036    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7037    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7038    /// URL, or local path sources.
7039    #[arg(
7040        long,
7041        env = EnvVars::UV_NO_SOURCES,
7042        value_parser = clap::builder::BoolishValueParser::new(),
7043        help_heading = "Resolver options",
7044    )]
7045    pub no_sources: bool,
7046}
7047
7048/// Arguments that are used by commands that need to fetch from the Simple API.
7049#[derive(Args)]
7050pub struct FetchArgs {
7051    #[command(flatten)]
7052    pub index_args: IndexArgs,
7053
7054    /// The strategy to use when resolving against multiple index URLs.
7055    ///
7056    /// By default, uv will stop at the first index on which a given package is available, and limit
7057    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7058    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7059    /// to an alternate index.
7060    #[arg(
7061        long,
7062        value_enum,
7063        env = EnvVars::UV_INDEX_STRATEGY,
7064        help_heading = "Index options"
7065    )]
7066    pub index_strategy: Option<IndexStrategy>,
7067
7068    /// Attempt to use `keyring` for authentication for index URLs.
7069    ///
7070    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7071    /// the `keyring` CLI to handle authentication.
7072    ///
7073    /// Defaults to `disabled`.
7074    #[arg(
7075        long,
7076        value_enum,
7077        env = EnvVars::UV_KEYRING_PROVIDER,
7078        help_heading = "Index options"
7079    )]
7080    pub keyring_provider: Option<KeyringProviderType>,
7081
7082    /// Limit candidate packages to those that were uploaded prior to the given date.
7083    ///
7084    /// Accepts both RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`) and local dates in the same
7085    /// format (e.g., `2006-12-02`) in your system's configured time zone.
7086    #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7087    pub exclude_newer: Option<ExcludeNewerTimestamp>,
7088}
7089
7090#[derive(Args)]
7091pub struct DisplayTreeArgs {
7092    /// Maximum display depth of the dependency tree
7093    #[arg(long, short, default_value_t = 255)]
7094    pub depth: u8,
7095
7096    /// Prune the given package from the display of the dependency tree.
7097    #[arg(long)]
7098    pub prune: Vec<PackageName>,
7099
7100    /// Display only the specified packages.
7101    #[arg(long)]
7102    pub package: Vec<PackageName>,
7103
7104    /// Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its
7105    /// dependencies, further occurrences will not re-display its dependencies, and will include a
7106    /// (*) to indicate it has already been shown. This flag will cause those duplicates to be
7107    /// repeated.
7108    #[arg(long)]
7109    pub no_dedupe: bool,
7110
7111    /// Show the reverse dependencies for the given package. This flag will invert the tree and
7112    /// display the packages that depend on the given package.
7113    #[arg(long, alias = "reverse")]
7114    pub invert: bool,
7115
7116    /// Show the latest available version of each package in the tree.
7117    #[arg(long)]
7118    pub outdated: bool,
7119
7120    /// Show compressed wheel sizes for packages in the tree.
7121    #[arg(long)]
7122    pub show_sizes: bool,
7123}
7124
7125#[derive(Args, Debug)]
7126pub struct PublishArgs {
7127    /// Paths to the files to upload. Accepts glob expressions.
7128    ///
7129    /// Defaults to the `dist` directory. Selects only wheels and source distributions
7130    /// and their attestations, while ignoring other files.
7131    #[arg(default_value = "dist/*")]
7132    pub files: Vec<String>,
7133
7134    /// The name of an index in the configuration to use for publishing.
7135    ///
7136    /// The index must have a `publish-url` setting, for example:
7137    ///
7138    /// ```toml
7139    /// [[tool.uv.index]]
7140    /// name = "pypi"
7141    /// url = "https://pypi.org/simple"
7142    /// publish-url = "https://upload.pypi.org/legacy/"
7143    /// ```
7144    ///
7145    /// The index `url` will be used to check for existing files to skip duplicate uploads.
7146    ///
7147    /// With these settings, the following two calls are equivalent:
7148    ///
7149    /// ```shell
7150    /// uv publish --index pypi
7151    /// uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pypi.org/simple
7152    /// ```
7153    #[arg(
7154        long,
7155        verbatim_doc_comment,
7156        env = EnvVars::UV_PUBLISH_INDEX,
7157        conflicts_with = "publish_url",
7158        conflicts_with = "check_url"
7159    )]
7160    pub index: Option<String>,
7161
7162    /// The username for the upload.
7163    #[arg(short, long, env = EnvVars::UV_PUBLISH_USERNAME)]
7164    pub username: Option<String>,
7165
7166    /// The password for the upload.
7167    #[arg(short, long, env = EnvVars::UV_PUBLISH_PASSWORD)]
7168    pub password: Option<String>,
7169
7170    /// The token for the upload.
7171    ///
7172    /// Using a token is equivalent to passing `__token__` as `--username` and the token as
7173    /// `--password` password.
7174    #[arg(
7175        short,
7176        long,
7177        env = EnvVars::UV_PUBLISH_TOKEN,
7178        conflicts_with = "username",
7179        conflicts_with = "password"
7180    )]
7181    pub token: Option<String>,
7182
7183    /// Configure trusted publishing.
7184    ///
7185    /// By default, uv checks for trusted publishing when running in a supported environment, but
7186    /// ignores it if it isn't configured.
7187    ///
7188    /// uv's supported environments for trusted publishing include GitHub Actions and GitLab CI/CD.
7189    #[arg(long)]
7190    pub trusted_publishing: Option<TrustedPublishing>,
7191
7192    /// Attempt to use `keyring` for authentication for remote requirements files.
7193    ///
7194    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7195    /// the `keyring` CLI to handle authentication.
7196    ///
7197    /// Defaults to `disabled`.
7198    #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
7199    pub keyring_provider: Option<KeyringProviderType>,
7200
7201    /// The URL of the upload endpoint (not the index URL).
7202    ///
7203    /// Note that there are typically different URLs for index access (e.g., `https:://.../simple`)
7204    /// and index upload.
7205    ///
7206    /// Defaults to PyPI's publish URL (<https://upload.pypi.org/legacy/>).
7207    #[arg(long, env = EnvVars::UV_PUBLISH_URL)]
7208    pub publish_url: Option<DisplaySafeUrl>,
7209
7210    /// Check an index URL for existing files to skip duplicate uploads.
7211    ///
7212    /// This option allows retrying publishing that failed after only some, but not all files have
7213    /// been uploaded, and handles errors due to parallel uploads of the same file.
7214    ///
7215    /// Before uploading, the index is checked. If the exact same file already exists in the index,
7216    /// the file will not be uploaded. If an error occurred during the upload, the index is checked
7217    /// again, to handle cases where the identical file was uploaded twice in parallel.
7218    ///
7219    /// The exact behavior will vary based on the index. When uploading to PyPI, uploading the same
7220    /// file succeeds even without `--check-url`, while most other indexes error. When uploading to
7221    /// pyx, the index URL can be inferred automatically from the publish URL.
7222    ///
7223    /// The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).
7224    #[arg(long, env = EnvVars::UV_PUBLISH_CHECK_URL)]
7225    pub check_url: Option<IndexUrl>,
7226
7227    #[arg(long, hide = true)]
7228    pub skip_existing: bool,
7229
7230    /// Perform a dry run without uploading files.
7231    ///
7232    /// When enabled, the command will check for existing files if `--check-url` is provided,
7233    /// and will perform validation against the index if supported, but will not upload any files.
7234    #[arg(long)]
7235    pub dry_run: bool,
7236
7237    /// Do not upload attestations for the published files.
7238    ///
7239    /// By default, uv attempts to upload matching PEP 740 attestations with each distribution
7240    /// that is published.
7241    #[arg(long, env = EnvVars::UV_PUBLISH_NO_ATTESTATIONS)]
7242    pub no_attestations: bool,
7243}
7244
7245#[derive(Args)]
7246pub struct WorkspaceNamespace {
7247    #[command(subcommand)]
7248    pub command: WorkspaceCommand,
7249}
7250
7251#[derive(Subcommand)]
7252pub enum WorkspaceCommand {
7253    /// View metadata about the current workspace.
7254    ///
7255    /// The output of this command is not yet stable.
7256    Metadata(MetadataArgs),
7257    /// Display the path of a workspace member.
7258    ///
7259    /// By default, the path to the workspace root directory is displayed.
7260    /// The `--package` option can be used to display the path to a workspace member instead.
7261    ///
7262    /// If used outside of a workspace, i.e., if a `pyproject.toml` cannot be found, uv will exit with an error.
7263    Dir(WorkspaceDirArgs),
7264    /// List the members of a workspace.
7265    ///
7266    /// Displays newline separated names of workspace members.
7267    #[command(hide = true)]
7268    List(WorkspaceListArgs),
7269}
7270
7271#[derive(Args, Debug)]
7272pub struct MetadataArgs;
7273
7274#[derive(Args, Debug)]
7275pub struct WorkspaceDirArgs {
7276    /// Display the path to a specific package in the workspace.
7277    #[arg(long)]
7278    pub package: Option<PackageName>,
7279}
7280
7281#[derive(Args, Debug)]
7282pub struct WorkspaceListArgs {
7283    /// Show paths instead of names.
7284    #[arg(long)]
7285    pub paths: bool,
7286}
7287
7288/// See [PEP 517](https://peps.python.org/pep-0517/) and
7289/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.
7290#[derive(Subcommand)]
7291pub enum BuildBackendCommand {
7292    /// PEP 517 hook `build_sdist`.
7293    BuildSdist { sdist_directory: PathBuf },
7294    /// PEP 517 hook `build_wheel`.
7295    BuildWheel {
7296        wheel_directory: PathBuf,
7297        #[arg(long)]
7298        metadata_directory: Option<PathBuf>,
7299    },
7300    /// PEP 660 hook `build_editable`.
7301    BuildEditable {
7302        wheel_directory: PathBuf,
7303        #[arg(long)]
7304        metadata_directory: Option<PathBuf>,
7305    },
7306    /// PEP 517 hook `get_requires_for_build_sdist`.
7307    GetRequiresForBuildSdist,
7308    /// PEP 517 hook `get_requires_for_build_wheel`.
7309    GetRequiresForBuildWheel,
7310    /// PEP 517 hook `prepare_metadata_for_build_wheel`.
7311    PrepareMetadataForBuildWheel { wheel_directory: PathBuf },
7312    /// PEP 660 hook `get_requires_for_build_editable`.
7313    GetRequiresForBuildEditable,
7314    /// PEP 660 hook `prepare_metadata_for_build_editable`.
7315    PrepareMetadataForBuildEditable { wheel_directory: PathBuf },
7316}