Skip to main content

uv_cli/
lib.rs

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