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    /// Path to a PEM-encoded CA certificate bundle.
975    ///
976    /// If provided, this overrides the default certificate source.
977    #[arg(global = true, long, value_name = "FILE", value_hint = ValueHint::FilePath)]
978    pub cert: Option<PathBuf>,
979}
980
981#[derive(Subcommand)]
982pub enum PipCommand {
983    /// Compile a `requirements.in` file to a `requirements.txt` or `pylock.toml` file.
984    #[command(
985        after_help = "Use `uv help pip compile` for more details.",
986        after_long_help = ""
987    )]
988    Compile(PipCompileArgs),
989    /// Sync an environment with a `requirements.txt` or `pylock.toml` file.
990    ///
991    /// When syncing an environment, any packages not listed in the `requirements.txt` or
992    /// `pylock.toml` file will be removed. To retain extraneous packages, use `uv pip install`
993    /// instead.
994    ///
995    /// The input file is presumed to be the output of a `pip compile` or `uv export` operation,
996    /// in which it will include all transitive dependencies. If transitive dependencies are not
997    /// present in the file, they will not be installed. Use `--strict` to warn if any transitive
998    /// dependencies are missing.
999    #[command(
1000        after_help = "Use `uv help pip sync` for more details.",
1001        after_long_help = ""
1002    )]
1003    Sync(Box<PipSyncArgs>),
1004    /// Install packages into an environment.
1005    #[command(
1006        after_help = "Use `uv help pip install` for more details.",
1007        after_long_help = ""
1008    )]
1009    Install(PipInstallArgs),
1010    /// Uninstall packages from an environment.
1011    #[command(
1012        after_help = "Use `uv help pip uninstall` for more details.",
1013        after_long_help = ""
1014    )]
1015    Uninstall(PipUninstallArgs),
1016    /// List, in requirements format, packages installed in an environment.
1017    #[command(
1018        after_help = "Use `uv help pip freeze` for more details.",
1019        after_long_help = ""
1020    )]
1021    Freeze(PipFreezeArgs),
1022    /// List, in tabular format, packages installed in an environment.
1023    #[command(
1024        after_help = "Use `uv help pip list` for more details.",
1025        after_long_help = "",
1026        alias = "ls"
1027    )]
1028    List(PipListArgs),
1029    /// Show information about one or more installed packages.
1030    #[command(
1031        after_help = "Use `uv help pip show` for more details.",
1032        after_long_help = ""
1033    )]
1034    Show(PipShowArgs),
1035    /// Display the dependency tree for an environment.
1036    #[command(
1037        after_help = "Use `uv help pip tree` for more details.",
1038        after_long_help = ""
1039    )]
1040    Tree(PipTreeArgs),
1041    /// Verify installed packages have compatible dependencies.
1042    #[command(
1043        after_help = "Use `uv help pip check` for more details.",
1044        after_long_help = ""
1045    )]
1046    Check(PipCheckArgs),
1047    /// Display debug information (unsupported)
1048    #[command(hide = true)]
1049    Debug(PipDebugArgs),
1050}
1051
1052#[derive(Subcommand)]
1053pub enum ProjectCommand {
1054    /// Run a command or script.
1055    ///
1056    /// Ensures that the command runs in a Python environment.
1057    ///
1058    /// When used with a file ending in `.py` or an HTTP(S) URL, the file will be treated as a
1059    /// script and run with a Python interpreter, i.e., `uv run file.py` is equivalent to `uv run
1060    /// python file.py`. For URLs, the script is temporarily downloaded before execution. If the
1061    /// script contains inline dependency metadata, it will be installed into an isolated, ephemeral
1062    /// environment. When used with `-`, the input will be read from stdin, and treated as a Python
1063    /// script.
1064    ///
1065    /// When used in a project, the project environment will be created and updated before invoking
1066    /// the command.
1067    ///
1068    /// When used outside a project, if a virtual environment can be found in the current directory
1069    /// or a parent directory, the command will be run in that environment. Otherwise, the command
1070    /// will be run in the environment of the discovered interpreter.
1071    ///
1072    /// When running a script, the project or workspace is discovered from the script's directory.
1073    /// Otherwise, the project or workspace is discovered from the current working directory.
1074    ///
1075    /// Arguments following the command (or script) are not interpreted as arguments to uv. All
1076    /// options to uv must be provided before the command, e.g., `uv run --verbose foo`. A `--` can
1077    /// be used to separate the command from uv options for clarity, e.g., `uv run --python 3.12 --
1078    /// python`.
1079    #[command(
1080        after_help = "Use `uv help run` for more details.",
1081        after_long_help = ""
1082    )]
1083    Run(RunArgs),
1084    /// Create a new project.
1085    ///
1086    /// Follows the `pyproject.toml` specification.
1087    ///
1088    /// If a `pyproject.toml` already exists at the target, uv will exit with an error.
1089    ///
1090    /// If a `pyproject.toml` is found in any of the parent directories of the target path, the
1091    /// project will be added as a workspace member of the parent.
1092    ///
1093    /// Some project state is not created until needed, e.g., the project virtual environment
1094    /// (`.venv`) and lockfile (`uv.lock`) are lazily created during the first sync.
1095    Init(InitArgs),
1096    /// Add dependencies to the project.
1097    ///
1098    /// Dependencies are added to the project's `pyproject.toml` file.
1099    ///
1100    /// If a given dependency exists already, it will be updated to the new version specifier unless
1101    /// it includes markers that differ from the existing specifier in which case another entry for
1102    /// the dependency will be added.
1103    ///
1104    /// The lockfile and project environment will be updated to reflect the added dependencies. To
1105    /// skip updating the lockfile, use `--frozen`. To skip updating the environment, use
1106    /// `--no-sync`.
1107    ///
1108    /// If any of the requested dependencies cannot be found, uv will exit with an error, unless the
1109    /// `--frozen` flag is provided, in which case uv will add the dependencies verbatim without
1110    /// checking that they exist or are compatible with the project.
1111    ///
1112    /// uv will search for a project in the current directory or any parent directory. If a project
1113    /// cannot be found, uv will exit with an error.
1114    #[command(
1115        after_help = "Use `uv help add` for more details.",
1116        after_long_help = ""
1117    )]
1118    Add(AddArgs),
1119    /// Remove dependencies from the project.
1120    ///
1121    /// Dependencies are removed from the project's `pyproject.toml` file.
1122    ///
1123    /// If multiple entries exist for a given dependency, i.e., each with different markers, all of
1124    /// the entries will be removed.
1125    ///
1126    /// The lockfile and project environment will be updated to reflect the removed dependencies. To
1127    /// skip updating the lockfile, use `--frozen`. To skip updating the environment, use
1128    /// `--no-sync`.
1129    ///
1130    /// If any of the requested dependencies are not present in the project, uv will exit with an
1131    /// error.
1132    ///
1133    /// If a package has been manually installed in the environment, i.e., with `uv pip install`, it
1134    /// will not be removed by `uv remove`.
1135    ///
1136    /// uv will search for a project in the current directory or any parent directory. If a project
1137    /// cannot be found, uv will exit with an error.
1138    #[command(
1139        after_help = "Use `uv help remove` for more details.",
1140        after_long_help = ""
1141    )]
1142    Remove(RemoveArgs),
1143    /// Read or update the project's version.
1144    Version(VersionArgs),
1145    /// Update the project's environment.
1146    ///
1147    /// Syncing ensures that all project dependencies are installed and up-to-date with the
1148    /// lockfile.
1149    ///
1150    /// By default, an exact sync is performed: uv removes packages that are not declared as
1151    /// dependencies of the project. Use the `--inexact` flag to keep extraneous packages. Note that
1152    /// if an extraneous package conflicts with a project dependency, it will still be removed.
1153    /// Additionally, if `--no-build-isolation` is used, uv will not remove extraneous packages to
1154    /// avoid removing possible build dependencies.
1155    ///
1156    /// If the project virtual environment (`.venv`) does not exist, it will be created.
1157    ///
1158    /// The project is re-locked before syncing unless the `--locked` or `--frozen` flag is
1159    /// provided.
1160    ///
1161    /// uv will search for a project in the current directory or any parent directory. If a project
1162    /// cannot be found, uv will exit with an error.
1163    ///
1164    /// Note that, when installing from a lockfile, uv will not provide warnings for yanked package
1165    /// versions.
1166    #[command(
1167        after_help = "Use `uv help sync` for more details.",
1168        after_long_help = ""
1169    )]
1170    Sync(SyncArgs),
1171    /// Update the project's lockfile.
1172    ///
1173    /// If the project lockfile (`uv.lock`) does not exist, it will be created. If a lockfile is
1174    /// present, its contents will be used as preferences for the resolution.
1175    ///
1176    /// If there are no changes to the project's dependencies, locking will have no effect unless
1177    /// the `--upgrade` flag is provided.
1178    #[command(
1179        after_help = "Use `uv help lock` for more details.",
1180        after_long_help = ""
1181    )]
1182    Lock(LockArgs),
1183    /// Upgrade a dependency in the project.
1184    #[command(hide = true)]
1185    Upgrade(UpgradeArgs),
1186    /// Export the project's lockfile to an alternate format.
1187    ///
1188    /// At present, `requirements.txt`, `pylock.toml` (PEP 751) and CycloneDX v1.5 JSON output
1189    /// formats are supported.
1190    ///
1191    /// The project is re-locked before exporting unless the `--locked` or `--frozen` flag is
1192    /// provided.
1193    ///
1194    /// uv will search for a project in the current directory or any parent directory. If a project
1195    /// cannot be found, uv will exit with an error.
1196    ///
1197    /// If operating in a workspace, the root will be exported by default; however, specific
1198    /// members can be selected using the `--package` option.
1199    #[command(
1200        after_help = "Use `uv help export` for more details.",
1201        after_long_help = ""
1202    )]
1203    Export(ExportArgs),
1204    /// Display the project's dependency tree.
1205    Tree(TreeArgs),
1206    /// Format Python code in the project.
1207    ///
1208    /// Formats Python code using the Ruff formatter. By default, all Python files in the project
1209    /// are formatted. This command has the same behavior as running `ruff format` in the project
1210    /// root.
1211    ///
1212    /// To check if files are formatted without modifying them, use `--check`. To see a diff of
1213    /// formatting changes, use `--diff`.
1214    ///
1215    /// Additional arguments can be passed to Ruff after `--`.
1216    #[command(
1217        after_help = "Use `uv help format` for more details.",
1218        after_long_help = ""
1219    )]
1220    Format(FormatArgs),
1221    /// Run checks on the project.
1222    ///
1223    /// Currently, this type checks Python code using ty. By default, all Python files in the
1224    /// project are checked.
1225    #[command(
1226        after_help = "Use `uv help check` for more details.",
1227        after_long_help = ""
1228    )]
1229    Check(CheckArgs),
1230    /// Audit the project's dependencies.
1231    ///
1232    /// Dependencies are audited for known vulnerabilities, as well as 'adverse' statuses such as
1233    /// deprecation and quarantine.
1234    ///
1235    /// By default, all extras and groups within the project are audited. To exclude extras
1236    /// and/or groups from the audit, use the `--no-extra`, `--no-group`, and related
1237    /// options.
1238    #[command(
1239        after_help = "Use `uv help audit` for more details.",
1240        after_long_help = ""
1241    )]
1242    Audit(AuditArgs),
1243}
1244
1245/// A re-implementation of `Option`, used to avoid Clap's automatic `Option` flattening in
1246/// [`parse_index_url`].
1247#[derive(Debug, Clone)]
1248pub enum Maybe<T> {
1249    Some(T),
1250    None,
1251}
1252
1253impl<T> Maybe<T> {
1254    pub fn into_option(self) -> Option<T> {
1255        match self {
1256            Self::Some(value) => Some(value),
1257            Self::None => None,
1258        }
1259    }
1260
1261    pub fn is_some(&self) -> bool {
1262        matches!(self, Self::Some(_))
1263    }
1264}
1265
1266/// Parse an `--index-url` argument into an [`PipIndex`], mapping the empty string to `None`.
1267fn parse_index_url(input: &str) -> Result<Maybe<PipIndex>, String> {
1268    if input.is_empty() {
1269        Ok(Maybe::None)
1270    } else {
1271        IndexUrl::from_str(input)
1272            .map(Index::from_index_url)
1273            .map(|index| Index {
1274                origin: Some(Origin::Cli),
1275                ..index
1276            })
1277            .map(PipIndex::from)
1278            .map(Maybe::Some)
1279            .map_err(|err| err.to_string())
1280    }
1281}
1282
1283/// Parse an `--extra-index-url` argument into an [`PipExtraIndex`], mapping the empty string to `None`.
1284fn parse_extra_index_url(input: &str) -> Result<Maybe<PipExtraIndex>, String> {
1285    if input.is_empty() {
1286        Ok(Maybe::None)
1287    } else {
1288        IndexUrl::from_str(input)
1289            .map(Index::from_extra_index_url)
1290            .map(|index| Index {
1291                origin: Some(Origin::Cli),
1292                ..index
1293            })
1294            .map(PipExtraIndex::from)
1295            .map(Maybe::Some)
1296            .map_err(|err| err.to_string())
1297    }
1298}
1299
1300/// Parse a `--find-links` argument into an [`PipFindLinks`], mapping the empty string to `None`.
1301fn parse_find_links(input: &str) -> Result<Maybe<PipFindLinks>, String> {
1302    if input.is_empty() {
1303        Ok(Maybe::None)
1304    } else {
1305        IndexUrl::from_str(input)
1306            .map(Index::from_find_links)
1307            .map(|index| Index {
1308                origin: Some(Origin::Cli),
1309                ..index
1310            })
1311            .map(PipFindLinks::from)
1312            .map(Maybe::Some)
1313            .map_err(|err| err.to_string())
1314    }
1315}
1316
1317/// Parse an `--index` argument into a [`Vec<Index>`], mapping the empty string to an empty Vec.
1318///
1319/// This function splits the input on all whitespace characters rather than a single delimiter,
1320/// which is necessary to parse environment variables like `PIP_EXTRA_INDEX_URL`.
1321/// The standard `clap::Args` `value_delimiter` only supports single-character delimiters.
1322fn parse_indices(input: &str) -> Result<Vec<Maybe<Index>>, String> {
1323    if input.trim().is_empty() {
1324        return Ok(Vec::new());
1325    }
1326    let mut indices = Vec::new();
1327    for token in input.split_whitespace() {
1328        match Index::from_str(token) {
1329            Ok(index) => indices.push(Maybe::Some(Index {
1330                default: false,
1331                origin: Some(Origin::Cli),
1332                ..index
1333            })),
1334            Err(e) => return Err(e.to_string()),
1335        }
1336    }
1337    Ok(indices)
1338}
1339
1340/// Parse a `--default-index` argument into an [`Index`], mapping the empty string to `None`.
1341fn parse_default_index(input: &str) -> Result<Maybe<Index>, String> {
1342    if input.is_empty() {
1343        Ok(Maybe::None)
1344    } else {
1345        match Index::from_str(input) {
1346            Ok(index) => Ok(Maybe::Some(Index {
1347                default: true,
1348                origin: Some(Origin::Cli),
1349                ..index
1350            })),
1351            Err(err) => Err(err.to_string()),
1352        }
1353    }
1354}
1355
1356/// Parse a string into an [`Url`], mapping the empty string to `None`.
1357fn parse_insecure_host(input: &str) -> Result<Maybe<TrustedHost>, String> {
1358    if input.is_empty() {
1359        Ok(Maybe::None)
1360    } else {
1361        match TrustedHost::from_str(input) {
1362            Ok(host) => Ok(Maybe::Some(host)),
1363            Err(err) => Err(err.to_string()),
1364        }
1365    }
1366}
1367
1368/// Parse a string into a [`PathBuf`]. The string can represent a file, either as a path or a
1369/// `file://` URL.
1370fn parse_file_path(input: &str) -> Result<PathBuf, String> {
1371    if input.starts_with("file://") {
1372        let url = match url::Url::from_str(input) {
1373            Ok(url) => url,
1374            Err(err) => return Err(err.to_string()),
1375        };
1376        url.to_file_path()
1377            .map_err(|()| "invalid file URL".to_string())
1378    } else {
1379        Ok(PathBuf::from(input))
1380    }
1381}
1382
1383/// Parse a string into a [`PathBuf`], mapping the empty string to `None`.
1384fn parse_maybe_file_path(input: &str) -> Result<Maybe<PathBuf>, String> {
1385    if input.is_empty() {
1386        Ok(Maybe::None)
1387    } else {
1388        parse_file_path(input).map(Maybe::Some)
1389    }
1390}
1391
1392// Parse a string, mapping the empty string to `None`.
1393#[expect(clippy::unnecessary_wraps)]
1394fn parse_maybe_string(input: &str) -> Result<Maybe<String>, String> {
1395    if input.is_empty() {
1396        Ok(Maybe::None)
1397    } else {
1398        Ok(Maybe::Some(input.to_string()))
1399    }
1400}
1401
1402#[derive(Args)]
1403#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
1404pub struct PipCompileArgs {
1405    /// Include the packages listed in the given files.
1406    ///
1407    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
1408    /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
1409    ///
1410    /// If a `pyproject.toml`, `setup.py`, or `setup.cfg` file is provided, uv will extract the
1411    /// requirements for the relevant project.
1412    ///
1413    /// If `-` is provided, then requirements will be read from stdin.
1414    ///
1415    /// The order of the requirements files and the requirements in them is used to determine
1416    /// priority during resolution.
1417    #[arg(group = "sources", value_parser = parse_file_path, value_hint = ValueHint::FilePath)]
1418    pub src_file: Vec<PathBuf>,
1419
1420    /// Constrain versions using the given requirements files.
1421    ///
1422    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1423    /// requirement that's installed. However, including a package in a constraints file will _not_
1424    /// trigger the installation of that package.
1425    ///
1426    /// This is equivalent to pip's `--constraint` option.
1427    #[arg(
1428        long,
1429        short,
1430        alias = "constraint",
1431        env = EnvVars::UV_CONSTRAINT,
1432        value_delimiter = ' ',
1433        value_parser = parse_maybe_file_path,
1434        value_hint = ValueHint::FilePath,
1435    )]
1436    pub constraints: Vec<Maybe<PathBuf>>,
1437
1438    /// Override versions using the given requirements files.
1439    ///
1440    /// Overrides files are `requirements.txt`-like files that force a specific version of a
1441    /// requirement to be installed, regardless of the requirements declared by any constituent
1442    /// package, and regardless of whether this would be considered an invalid resolution.
1443    ///
1444    /// While constraints are _additive_, in that they're combined with the requirements of the
1445    /// constituent packages, overrides are _absolute_, in that they completely replace the
1446    /// requirements of the constituent packages.
1447    #[arg(
1448        long,
1449        alias = "override",
1450        env = EnvVars::UV_OVERRIDE,
1451        value_delimiter = ' ',
1452        value_parser = parse_maybe_file_path,
1453        value_hint = ValueHint::FilePath,
1454    )]
1455    pub overrides: Vec<Maybe<PathBuf>>,
1456
1457    /// Exclude packages from resolution using the given requirements files.
1458    ///
1459    /// Excludes files are `requirements.txt`-like files that specify packages to exclude
1460    /// from the resolution. When a package is excluded, it will be omitted from the
1461    /// dependency list entirely and its own dependencies will be ignored during the resolution
1462    /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
1463    /// any package listed in the provided file will be omitted from all resolved environments.
1464    #[arg(
1465        long,
1466        alias = "exclude",
1467        env = EnvVars::UV_EXCLUDE,
1468        value_delimiter = ' ',
1469        value_parser = parse_maybe_file_path,
1470        value_hint = ValueHint::FilePath,
1471    )]
1472    pub excludes: Vec<Maybe<PathBuf>>,
1473
1474    /// Constrain build dependencies using the given requirements files when building source
1475    /// distributions.
1476    ///
1477    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1478    /// requirement that's installed. However, including a package in a constraints file will _not_
1479    /// trigger the installation of that package.
1480    #[arg(
1481        long,
1482        short,
1483        alias = "build-constraint",
1484        env = EnvVars::UV_BUILD_CONSTRAINT,
1485        value_delimiter = ' ',
1486        value_parser = parse_maybe_file_path,
1487        value_hint = ValueHint::FilePath,
1488    )]
1489    pub build_constraints: Vec<Maybe<PathBuf>>,
1490
1491    /// Include optional dependencies from the specified extra name; may be provided more than once.
1492    ///
1493    /// Only applies to `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1494    #[arg(long, value_delimiter = ',', conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
1495    pub extra: Option<Vec<ExtraName>>,
1496
1497    /// Include all optional dependencies.
1498    ///
1499    /// Only applies to `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1500    #[arg(long, conflicts_with = "extra")]
1501    pub all_extras: bool,
1502
1503    #[arg(long, overrides_with("all_extras"), hide = true)]
1504    pub no_all_extras: bool,
1505
1506    /// Install the specified dependency group from a `pyproject.toml`.
1507    ///
1508    /// If no path is provided, the `pyproject.toml` in the working directory is used.
1509    ///
1510    /// May be provided multiple times.
1511    #[arg(long, group = "sources")]
1512    pub group: Vec<PipGroupName>,
1513
1514    #[command(flatten)]
1515    pub resolver: ResolverArgs,
1516
1517    #[command(flatten)]
1518    pub refresh: RefreshArgs,
1519
1520    /// Ignore package dependencies, instead only add those packages explicitly listed
1521    /// on the command line to the resulting requirements file.
1522    #[arg(long)]
1523    pub no_deps: bool,
1524
1525    #[arg(long, overrides_with("no_deps"), hide = true)]
1526    pub deps: bool,
1527
1528    /// Write the compiled requirements to the given `requirements.txt` or `pylock.toml` file.
1529    ///
1530    /// If the file already exists, the existing versions will be preferred when resolving
1531    /// dependencies, unless `--upgrade` is also specified.
1532    #[arg(long, short, value_hint = ValueHint::FilePath)]
1533    pub output_file: Option<PathBuf>,
1534
1535    /// The format in which the resolution should be output.
1536    ///
1537    /// Supports both `requirements.txt` and `pylock.toml` (PEP 751) output formats.
1538    ///
1539    /// uv will infer the output format from the file extension of the output file, if
1540    /// provided. Otherwise, defaults to `requirements.txt`.
1541    #[arg(long, value_enum)]
1542    pub format: Option<PipCompileFormat>,
1543
1544    /// Include extras in the output file.
1545    ///
1546    /// By default, uv strips extras, as any packages pulled in by the extras are already included
1547    /// as dependencies in the output file directly. Further, output files generated with
1548    /// `--no-strip-extras` cannot be used as constraints files in `install` and `sync` invocations.
1549    #[arg(long, overrides_with("strip_extras"))]
1550    pub no_strip_extras: bool,
1551
1552    #[arg(long, overrides_with("no_strip_extras"), hide = true)]
1553    pub strip_extras: bool,
1554
1555    /// Include environment markers in the output file.
1556    ///
1557    /// By default, uv strips environment markers, as the resolution generated by `compile` is
1558    /// only guaranteed to be correct for the target environment.
1559    #[arg(long, overrides_with("strip_markers"))]
1560    pub no_strip_markers: bool,
1561
1562    #[arg(long, overrides_with("no_strip_markers"), hide = true)]
1563    pub strip_markers: bool,
1564
1565    /// Exclude comment annotations indicating the source of each package.
1566    #[arg(long, overrides_with("annotate"))]
1567    pub no_annotate: bool,
1568
1569    #[arg(long, overrides_with("no_annotate"), hide = true)]
1570    pub annotate: bool,
1571
1572    /// Exclude the comment header at the top of the generated output file.
1573    #[arg(long, overrides_with("header"))]
1574    pub no_header: bool,
1575
1576    #[arg(long, overrides_with("no_header"), hide = true)]
1577    pub header: bool,
1578
1579    /// The style of the annotation comments included in the output file, used to indicate the
1580    /// source of each package.
1581    ///
1582    /// Defaults to `split`.
1583    #[arg(long, value_enum)]
1584    pub annotation_style: Option<AnnotationStyle>,
1585
1586    /// The header comment to include at the top of the output file generated by `uv pip compile`.
1587    ///
1588    /// Used to reflect custom build scripts and commands that wrap `uv pip compile`.
1589    #[arg(long, env = EnvVars::UV_CUSTOM_COMPILE_COMMAND, value_hint = ValueHint::Other)]
1590    pub custom_compile_command: Option<String>,
1591
1592    /// The Python interpreter to use during resolution.
1593    ///
1594    /// A Python interpreter is required for building source distributions to determine package
1595    /// metadata when there are not wheels.
1596    ///
1597    /// The interpreter is also used to determine the default minimum Python version, unless
1598    /// `--python-version` is provided.
1599    ///
1600    /// This option respects `UV_PYTHON`, but when set via environment variable, it is overridden
1601    /// by `--python-version`.
1602    ///
1603    /// See `uv help python` for details on Python discovery and supported request formats.
1604    #[arg(
1605        long,
1606        short,
1607        verbatim_doc_comment,
1608        help_heading = "Python options",
1609        value_parser = parse_maybe_string,
1610        value_hint = ValueHint::Other,
1611    )]
1612    pub python: Option<Maybe<String>>,
1613
1614    /// Install packages into the system Python environment.
1615    ///
1616    /// By default, uv uses the virtual environment in the current working directory or any parent
1617    /// directory, falling back to searching for a Python executable in `PATH`. The `--system`
1618    /// option instructs uv to avoid using a virtual environment Python and restrict its search to
1619    /// the system path.
1620    #[arg(
1621        long,
1622        env = EnvVars::UV_SYSTEM_PYTHON,
1623        value_parser = clap::builder::BoolishValueParser::new(),
1624        overrides_with("no_system")
1625    )]
1626    pub system: bool,
1627
1628    #[arg(long, overrides_with("system"), hide = true)]
1629    pub no_system: bool,
1630
1631    /// Include distribution hashes in the output file.
1632    #[arg(long, overrides_with("no_generate_hashes"))]
1633    pub generate_hashes: bool,
1634
1635    #[arg(long, overrides_with("generate_hashes"), hide = true)]
1636    pub no_generate_hashes: bool,
1637
1638    /// Don't build source distributions.
1639    ///
1640    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
1641    /// operations that require building a source distribution will exit with an error. uv may
1642    /// still build editable requirements, and their build backends may run arbitrary Python code.
1643    ///
1644    /// Alias for `--only-binary :all:`.
1645    #[arg(
1646        long,
1647        conflicts_with = "no_binary",
1648        conflicts_with = "only_binary",
1649        overrides_with("build")
1650    )]
1651    pub no_build: bool,
1652
1653    #[arg(
1654        long,
1655        conflicts_with = "no_binary",
1656        conflicts_with = "only_binary",
1657        overrides_with("no_build"),
1658        hide = true
1659    )]
1660    pub build: bool,
1661
1662    /// Don't install pre-built wheels.
1663    ///
1664    /// The given packages will be built and installed from source. The resolver will still use
1665    /// pre-built wheels to extract package metadata, if available.
1666    ///
1667    /// Multiple packages may be provided. Disable binaries for all packages with `:all:`.
1668    /// Clear previously specified packages with `:none:`.
1669    #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1670    pub no_binary: Option<Vec<PackageNameSpecifier>>,
1671
1672    /// Only use pre-built wheels; don't build source distributions.
1673    ///
1674    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
1675    /// operations that require building a source distribution for the given packages will exit
1676    /// with an error. uv may still build editable requirements, and their build backends may run
1677    /// arbitrary Python code.
1678    ///
1679    /// Multiple packages may be provided. Disable binaries for all packages with `:all:`.
1680    /// Clear previously specified packages with `:none:`.
1681    #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1682    pub only_binary: Option<Vec<PackageNameSpecifier>>,
1683
1684    /// The Python version to use for resolution.
1685    ///
1686    /// For example, `3.8` or `3.8.17`.
1687    ///
1688    /// Defaults to the version of the Python interpreter used for resolution.
1689    ///
1690    /// Defines the minimum Python version that must be supported by the
1691    /// resolved requirements.
1692    ///
1693    /// If a patch version is omitted, the minimum patch version is assumed. For
1694    /// example, `3.8` is mapped to `3.8.0`.
1695    #[arg(long, help_heading = "Python options")]
1696    pub python_version: Option<PythonVersion>,
1697
1698    /// The platform for which requirements should be resolved.
1699    ///
1700    /// Represented as a "target triple", a string that describes the target platform in terms of
1701    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
1702    /// `aarch64-apple-darwin`.
1703    ///
1704    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
1705    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
1706    ///
1707    /// When targeting iOS, the default minimum version is `13.0`. Use
1708    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
1709    ///
1710    /// When targeting Android, the default minimum Android API level is `24`. Use
1711    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
1712    #[arg(long)]
1713    pub python_platform: Option<TargetTriple>,
1714
1715    /// Perform a universal resolution, attempting to generate a single `requirements.txt` output
1716    /// file that is compatible with all operating systems, architectures, and Python
1717    /// implementations.
1718    ///
1719    /// In universal mode, the current Python version (or user-provided `--python-version`) will be
1720    /// treated as a lower bound. For example, `--universal --python-version 3.7` would produce a
1721    /// universal resolution for Python 3.7 and later.
1722    ///
1723    /// Implies `--no-strip-markers`.
1724    #[arg(
1725        long,
1726        overrides_with("no_universal"),
1727        conflicts_with("python_platform"),
1728        conflicts_with("strip_markers")
1729    )]
1730    pub universal: bool,
1731
1732    #[arg(long, overrides_with("universal"), hide = true)]
1733    pub no_universal: bool,
1734
1735    /// Specify a package to omit from the output resolution. Its dependencies will still be
1736    /// included in the resolution. Equivalent to pip-compile's `--unsafe-package` option.
1737    #[arg(long, alias = "unsafe-package", value_delimiter = ',', value_hint = ValueHint::Other)]
1738    pub no_emit_package: Option<Vec<PackageName>>,
1739
1740    /// Include `--index-url` and `--extra-index-url` entries in the generated output file.
1741    #[arg(long, overrides_with("no_emit_index_url"))]
1742    pub emit_index_url: bool,
1743
1744    #[arg(long, overrides_with("emit_index_url"), hide = true)]
1745    pub no_emit_index_url: bool,
1746
1747    /// Include `--find-links` entries in the generated output file.
1748    #[arg(long, overrides_with("no_emit_find_links"))]
1749    pub emit_find_links: bool,
1750
1751    #[arg(long, overrides_with("emit_find_links"), hide = true)]
1752    pub no_emit_find_links: bool,
1753
1754    /// Include `--no-binary` and `--only-binary` entries in the generated output file.
1755    #[arg(long, overrides_with("no_emit_build_options"))]
1756    pub emit_build_options: bool,
1757
1758    #[arg(long, overrides_with("emit_build_options"), hide = true)]
1759    pub no_emit_build_options: bool,
1760
1761    /// Whether to emit a marker string indicating when it is known that the
1762    /// resulting set of pinned dependencies is valid.
1763    ///
1764    /// The pinned dependencies may be valid even when the marker expression is
1765    /// false, but when the expression is true, the requirements are known to
1766    /// be correct.
1767    #[arg(long, overrides_with("no_emit_marker_expression"), hide = true)]
1768    pub emit_marker_expression: bool,
1769
1770    #[arg(long, overrides_with("emit_marker_expression"), hide = true)]
1771    pub no_emit_marker_expression: bool,
1772
1773    /// Include comment annotations indicating the index used to resolve each package (e.g.,
1774    /// `# from https://pypi.org/simple`).
1775    #[arg(long, overrides_with("no_emit_index_annotation"))]
1776    pub emit_index_annotation: bool,
1777
1778    #[arg(long, overrides_with("emit_index_annotation"), hide = true)]
1779    pub no_emit_index_annotation: bool,
1780
1781    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`).
1782    ///
1783    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
1784    /// and will instead use the defined backend.
1785    ///
1786    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
1787    /// uv will use the PyTorch index for CUDA 12.6.
1788    ///
1789    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
1790    /// installed CUDA drivers.
1791    ///
1792    /// This option is in preview and may change in any future release.
1793    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
1794    pub torch_backend: Option<TorchMode>,
1795
1796    #[command(flatten)]
1797    pub compat_args: compat::PipCompileCompatArgs,
1798}
1799
1800#[derive(Args)]
1801pub struct PipSyncArgs {
1802    /// Include the packages listed in the given files.
1803    ///
1804    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
1805    /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
1806    ///
1807    /// If a `pyproject.toml`, `setup.py`, or `setup.cfg` file is provided, uv will
1808    /// extract the requirements for the relevant project.
1809    ///
1810    /// If `-` is provided, then requirements will be read from stdin.
1811    #[arg(required(true), value_parser = parse_file_path, value_hint = ValueHint::FilePath)]
1812    pub src_file: Vec<PathBuf>,
1813
1814    /// Constrain versions using the given requirements files.
1815    ///
1816    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1817    /// requirement that's installed. However, including a package in a constraints file will _not_
1818    /// trigger the installation of that package.
1819    ///
1820    /// This is equivalent to pip's `--constraint` option.
1821    #[arg(
1822        long,
1823        short,
1824        alias = "constraint",
1825        env = EnvVars::UV_CONSTRAINT,
1826        value_delimiter = ' ',
1827        value_parser = parse_maybe_file_path,
1828        value_hint = ValueHint::FilePath,
1829    )]
1830    pub constraints: Vec<Maybe<PathBuf>>,
1831
1832    /// Constrain build dependencies using the given requirements files when building source
1833    /// distributions.
1834    ///
1835    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
1836    /// requirement that's installed. However, including a package in a constraints file will _not_
1837    /// trigger the installation of that package.
1838    #[arg(
1839        long,
1840        short,
1841        alias = "build-constraint",
1842        env = EnvVars::UV_BUILD_CONSTRAINT,
1843        value_delimiter = ' ',
1844        value_parser = parse_maybe_file_path,
1845        value_hint = ValueHint::FilePath,
1846    )]
1847    pub build_constraints: Vec<Maybe<PathBuf>>,
1848
1849    /// Include optional dependencies from the specified extra name; may be provided more than once.
1850    ///
1851    /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1852    #[arg(long, value_delimiter = ',', conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
1853    pub extra: Option<Vec<ExtraName>>,
1854
1855    /// Include all optional dependencies.
1856    ///
1857    /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
1858    #[arg(long, conflicts_with = "extra", overrides_with = "no_all_extras")]
1859    pub all_extras: bool,
1860
1861    #[arg(long, overrides_with("all_extras"), hide = true)]
1862    pub no_all_extras: bool,
1863
1864    /// Install the specified dependency group from a `pylock.toml` or `pyproject.toml`.
1865    ///
1866    /// If no path is provided, the `pylock.toml` or `pyproject.toml` in the working directory is
1867    /// used.
1868    ///
1869    /// May be provided multiple times.
1870    #[arg(long, group = "sources")]
1871    pub group: Vec<PipGroupName>,
1872
1873    #[command(flatten)]
1874    pub installer: InstallerArgs,
1875
1876    #[command(flatten)]
1877    pub refresh: RefreshArgs,
1878
1879    #[command(flatten)]
1880    pub hash_checking: HashCheckingArgs,
1881
1882    /// The Python interpreter into which packages should be installed.
1883    ///
1884    /// By default, syncing requires a virtual environment. A path to an alternative Python can be
1885    /// provided, but it is only recommended in continuous integration (CI) environments and should
1886    /// be used with caution, as it can modify the system Python installation.
1887    ///
1888    /// See `uv help python` for details on Python discovery and supported request formats.
1889    #[arg(
1890        long,
1891        short,
1892        env = EnvVars::UV_PYTHON,
1893        verbatim_doc_comment,
1894        help_heading = "Python options",
1895        value_parser = parse_maybe_string,
1896        value_hint = ValueHint::Other,
1897    )]
1898    pub python: Option<Maybe<String>>,
1899
1900    /// Install packages into the system Python environment.
1901    ///
1902    /// By default, uv installs into the virtual environment in the current working directory or any
1903    /// parent directory. The `--system` option instructs uv to instead use the first Python found
1904    /// in the system `PATH`.
1905    ///
1906    /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
1907    /// should be used with caution, as it can modify the system Python installation.
1908    #[arg(
1909        long,
1910        env = EnvVars::UV_SYSTEM_PYTHON,
1911        value_parser = clap::builder::BoolishValueParser::new(),
1912        overrides_with("no_system")
1913    )]
1914    pub system: bool,
1915
1916    #[arg(long, overrides_with("system"), hide = true)]
1917    pub no_system: bool,
1918
1919    /// Allow uv to modify an `EXTERNALLY-MANAGED` Python installation.
1920    ///
1921    /// WARNING: `--break-system-packages` is intended for use in continuous integration (CI)
1922    /// environments, when installing into Python installations that are managed by an external
1923    /// package manager, like `apt`. It should be used with caution, as such Python installations
1924    /// explicitly recommend against modifications by other package managers (like uv or `pip`).
1925    #[arg(
1926        long,
1927        env = EnvVars::UV_BREAK_SYSTEM_PACKAGES,
1928        value_parser = clap::builder::BoolishValueParser::new(),
1929        overrides_with("no_break_system_packages")
1930    )]
1931    pub break_system_packages: bool,
1932
1933    #[arg(long, overrides_with("break_system_packages"))]
1934    pub no_break_system_packages: bool,
1935
1936    /// Install packages into the specified directory, rather than into the virtual or system Python
1937    /// environment. The packages will be installed at the top-level of the directory.
1938    ///
1939    /// Unlike other install operations, this command does not require discovery of an existing Python
1940    /// environment and only searches for a Python interpreter to use for package resolution.
1941    /// If a suitable Python interpreter cannot be found, uv will install one.
1942    /// To disable this, add `--no-python-downloads`.
1943    #[arg(short = 't', long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
1944    pub target: Option<PathBuf>,
1945
1946    /// Install packages into `lib`, `bin`, and other top-level folders under the specified
1947    /// directory, as if a virtual environment were present at that location.
1948    ///
1949    /// In general, prefer the use of `--python` to install into an alternate environment, as
1950    /// scripts and other artifacts installed via `--prefix` will reference the installing
1951    /// interpreter, rather than any interpreter added to the `--prefix` directory, rendering them
1952    /// non-portable.
1953    ///
1954    /// Unlike other install operations, this command does not require discovery of an existing Python
1955    /// environment and only searches for a Python interpreter to use for package resolution.
1956    /// If a suitable Python interpreter cannot be found, uv will install one.
1957    /// To disable this, add `--no-python-downloads`.
1958    #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
1959    pub prefix: Option<PathBuf>,
1960
1961    /// Don't build source distributions.
1962    ///
1963    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
1964    /// operations that require building a source distribution will exit with an error. uv may
1965    /// still build editable requirements, and their build backends may run arbitrary Python code.
1966    ///
1967    /// Alias for `--only-binary :all:`.
1968    #[arg(
1969        long,
1970        conflicts_with = "no_binary",
1971        conflicts_with = "only_binary",
1972        overrides_with("build")
1973    )]
1974    pub no_build: bool,
1975
1976    #[arg(
1977        long,
1978        conflicts_with = "no_binary",
1979        conflicts_with = "only_binary",
1980        overrides_with("no_build"),
1981        hide = true
1982    )]
1983    pub build: bool,
1984
1985    /// Don't install pre-built wheels.
1986    ///
1987    /// The given packages will be built and installed from source. The resolver will still use
1988    /// pre-built wheels to extract package metadata, if available.
1989    ///
1990    /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
1991    /// previously specified packages with `:none:`.
1992    #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
1993    pub no_binary: Option<Vec<PackageNameSpecifier>>,
1994
1995    /// Only use pre-built wheels; don't build source distributions.
1996    ///
1997    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
1998    /// operations that require building a source distribution for the given packages will exit
1999    /// with an error. uv may still build editable requirements, and their build backends may run
2000    /// arbitrary Python code.
2001    ///
2002    /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
2003    /// previously specified packages with `:none:`.
2004    #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
2005    pub only_binary: Option<Vec<PackageNameSpecifier>>,
2006
2007    /// Allow sync of empty requirements, which will clear the environment of all packages.
2008    #[arg(long, overrides_with("no_allow_empty_requirements"))]
2009    pub allow_empty_requirements: bool,
2010
2011    #[arg(long, overrides_with("allow_empty_requirements"))]
2012    pub no_allow_empty_requirements: bool,
2013
2014    /// The minimum Python version that should be supported by the requirements (e.g., `3.7` or
2015    /// `3.7.9`).
2016    ///
2017    /// If a patch version is omitted, the minimum patch version is assumed. For example, `3.7` is
2018    /// mapped to `3.7.0`.
2019    #[arg(long)]
2020    pub python_version: Option<PythonVersion>,
2021
2022    /// The platform for which requirements should be installed.
2023    ///
2024    /// Represented as a "target triple", a string that describes the target platform in terms of
2025    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
2026    /// `aarch64-apple-darwin`.
2027    ///
2028    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
2029    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2030    ///
2031    /// When targeting iOS, the default minimum version is `13.0`. Use
2032    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2033    ///
2034    /// When targeting Android, the default minimum Android API level is `24`. Use
2035    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
2036    ///
2037    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
2038    /// platform; as a result, the installed distributions may not be compatible with the _current_
2039    /// platform. Conversely, any distributions that are built from source may be incompatible with
2040    /// the _target_ platform, as they will be built for the _current_ platform. The
2041    /// `--python-platform` option is intended for advanced use cases.
2042    #[arg(long)]
2043    pub python_platform: Option<TargetTriple>,
2044
2045    /// Validate the Python environment after completing the installation, to detect packages with
2046    /// missing dependencies or other issues.
2047    #[arg(long, overrides_with("no_strict"))]
2048    pub strict: bool,
2049
2050    #[arg(long, overrides_with("strict"), hide = true)]
2051    pub no_strict: bool,
2052
2053    /// Perform a dry run, i.e., don't actually install anything but resolve the dependencies and
2054    /// print the resulting plan.
2055    #[arg(long)]
2056    pub dry_run: bool,
2057
2058    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`).
2059    ///
2060    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
2061    /// and will instead use the defined backend.
2062    ///
2063    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
2064    /// uv will use the PyTorch index for CUDA 12.6.
2065    ///
2066    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
2067    /// installed CUDA drivers.
2068    ///
2069    /// This option is in preview and may change in any future release.
2070    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
2071    pub torch_backend: Option<TorchMode>,
2072
2073    #[command(flatten)]
2074    pub compat_args: compat::PipSyncCompatArgs,
2075}
2076
2077#[derive(Args)]
2078#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
2079pub struct PipInstallArgs {
2080    /// Install all listed packages.
2081    ///
2082    /// The order of the packages is used to determine priority during resolution.
2083    #[arg(group = "sources", value_hint = ValueHint::Other)]
2084    pub package: Vec<String>,
2085
2086    /// Install the packages listed in the given files.
2087    ///
2088    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
2089    /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
2090    ///
2091    /// If a `pyproject.toml`, `setup.py`, or `setup.cfg` file is provided, uv will extract the
2092    /// requirements for the relevant project.
2093    ///
2094    /// If `-` is provided, then requirements will be read from stdin.
2095    #[arg(
2096        long,
2097        short,
2098        alias = "requirement",
2099        group = "sources",
2100        value_parser = parse_file_path,
2101        value_hint = ValueHint::FilePath,
2102    )]
2103    pub requirements: Vec<PathBuf>,
2104
2105    /// Install the editable package based on the provided local file path.
2106    #[arg(long, short, group = "sources")]
2107    pub editable: Vec<String>,
2108
2109    /// Install any editable dependencies as non-editable [env: UV_NO_EDITABLE=]
2110    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
2111    pub no_editable: bool,
2112
2113    /// Install the specified editable packages as non-editable.
2114    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
2115    pub no_editable_package: Vec<PackageName>,
2116
2117    /// Constrain versions using the given requirements files.
2118    ///
2119    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
2120    /// requirement that's installed. However, including a package in a constraints file will _not_
2121    /// trigger the installation of that package.
2122    ///
2123    /// This is equivalent to pip's `--constraint` option.
2124    #[arg(
2125        long,
2126        short,
2127        alias = "constraint",
2128        env = EnvVars::UV_CONSTRAINT,
2129        value_delimiter = ' ',
2130        value_parser = parse_maybe_file_path,
2131        value_hint = ValueHint::FilePath,
2132    )]
2133    pub constraints: Vec<Maybe<PathBuf>>,
2134
2135    /// Override versions using the given requirements files.
2136    ///
2137    /// Overrides files are `requirements.txt`-like files that force a specific version of a
2138    /// requirement to be installed, regardless of the requirements declared by any constituent
2139    /// package, and regardless of whether this would be considered an invalid resolution.
2140    ///
2141    /// While constraints are _additive_, in that they're combined with the requirements of the
2142    /// constituent packages, overrides are _absolute_, in that they completely replace the
2143    /// requirements of the constituent packages.
2144    #[arg(
2145        long,
2146        alias = "override",
2147        env = EnvVars::UV_OVERRIDE,
2148        value_delimiter = ' ',
2149        value_parser = parse_maybe_file_path,
2150        value_hint = ValueHint::FilePath,
2151    )]
2152    pub overrides: Vec<Maybe<PathBuf>>,
2153
2154    /// Exclude packages from resolution using the given requirements files.
2155    ///
2156    /// Excludes files are `requirements.txt`-like files that specify packages to exclude
2157    /// from the resolution. When a package is excluded, it will be omitted from the
2158    /// dependency list entirely and its own dependencies will be ignored during the resolution
2159    /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
2160    /// any package listed in the provided file will be omitted from all resolved environments.
2161    #[arg(
2162        long,
2163        alias = "exclude",
2164        env = EnvVars::UV_EXCLUDE,
2165        value_delimiter = ' ',
2166        value_parser = parse_maybe_file_path,
2167        value_hint = ValueHint::FilePath,
2168    )]
2169    pub excludes: Vec<Maybe<PathBuf>>,
2170
2171    /// Constrain build dependencies using the given requirements files when building source
2172    /// distributions.
2173    ///
2174    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
2175    /// requirement that's installed. However, including a package in a constraints file will _not_
2176    /// trigger the installation of that package.
2177    #[arg(
2178        long,
2179        short,
2180        alias = "build-constraint",
2181        env = EnvVars::UV_BUILD_CONSTRAINT,
2182        value_delimiter = ' ',
2183        value_parser = parse_maybe_file_path,
2184        value_hint = ValueHint::FilePath,
2185    )]
2186    pub build_constraints: Vec<Maybe<PathBuf>>,
2187
2188    /// Include optional dependencies from the specified extra name; may be provided more than once.
2189    ///
2190    /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
2191    #[arg(long, value_delimiter = ',', conflicts_with = "all_extras", value_parser = extra_name_with_clap_error)]
2192    pub extra: Option<Vec<ExtraName>>,
2193
2194    /// Include all optional dependencies.
2195    ///
2196    /// Only applies to `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg` sources.
2197    #[arg(long, conflicts_with = "extra", overrides_with = "no_all_extras")]
2198    pub all_extras: bool,
2199
2200    #[arg(long, overrides_with("all_extras"), hide = true)]
2201    pub no_all_extras: bool,
2202
2203    /// Install the specified dependency group from a `pylock.toml` or `pyproject.toml`.
2204    ///
2205    /// If no path is provided, the `pylock.toml` or `pyproject.toml` in the working directory is
2206    /// used.
2207    ///
2208    /// May be provided multiple times.
2209    #[arg(long, group = "sources")]
2210    pub group: Vec<PipGroupName>,
2211
2212    #[command(flatten)]
2213    pub installer: ResolverInstallerArgs,
2214
2215    #[command(flatten)]
2216    pub refresh: RefreshArgs,
2217
2218    /// Ignore package dependencies, instead only installing those packages explicitly listed
2219    /// on the command line or in the requirements files.
2220    #[arg(long, overrides_with("deps"))]
2221    pub no_deps: bool,
2222
2223    #[arg(long, overrides_with("no_deps"), hide = true)]
2224    pub deps: bool,
2225
2226    #[command(flatten)]
2227    pub hash_checking: HashCheckingArgs,
2228
2229    /// The Python interpreter into which packages should be installed.
2230    ///
2231    /// By default, installation requires a virtual environment. A path to an alternative Python can
2232    /// be provided, but it is only recommended in continuous integration (CI) environments and
2233    /// should be used with caution, as it can modify the system Python installation.
2234    ///
2235    /// See `uv help python` for details on Python discovery and supported request formats.
2236    #[arg(
2237        long,
2238        short,
2239        env = EnvVars::UV_PYTHON,
2240        verbatim_doc_comment,
2241        help_heading = "Python options",
2242        value_parser = parse_maybe_string,
2243        value_hint = ValueHint::Other,
2244    )]
2245    pub python: Option<Maybe<String>>,
2246
2247    /// Install packages into the system Python environment.
2248    ///
2249    /// By default, uv installs into the virtual environment in the current working directory or any
2250    /// parent directory. The `--system` option instructs uv to instead use the first Python found
2251    /// in the system `PATH`.
2252    ///
2253    /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
2254    /// should be used with caution, as it can modify the system Python installation.
2255    #[arg(
2256        long,
2257        env = EnvVars::UV_SYSTEM_PYTHON,
2258        value_parser = clap::builder::BoolishValueParser::new(),
2259        overrides_with("no_system")
2260    )]
2261    pub system: bool,
2262
2263    #[arg(long, overrides_with("system"), hide = true)]
2264    pub no_system: bool,
2265
2266    /// Allow uv to modify an `EXTERNALLY-MANAGED` Python installation.
2267    ///
2268    /// WARNING: `--break-system-packages` is intended for use in continuous integration (CI)
2269    /// environments, when installing into Python installations that are managed by an external
2270    /// package manager, like `apt`. It should be used with caution, as such Python installations
2271    /// explicitly recommend against modifications by other package managers (like uv or `pip`).
2272    #[arg(
2273        long,
2274        env = EnvVars::UV_BREAK_SYSTEM_PACKAGES,
2275        value_parser = clap::builder::BoolishValueParser::new(),
2276        overrides_with("no_break_system_packages")
2277    )]
2278    pub break_system_packages: bool,
2279
2280    #[arg(long, overrides_with("break_system_packages"))]
2281    pub no_break_system_packages: bool,
2282
2283    /// Install packages into the specified directory, rather than into the virtual or system Python
2284    /// environment. The packages will be installed at the top-level of the directory.
2285    ///
2286    /// Unlike other install operations, this command does not require discovery of an existing Python
2287    /// environment and only searches for a Python interpreter to use for package resolution.
2288    /// If a suitable Python interpreter cannot be found, uv will install one.
2289    /// To disable this, add `--no-python-downloads`.
2290    #[arg(short = 't', long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2291    pub target: Option<PathBuf>,
2292
2293    /// Install packages into `lib`, `bin`, and other top-level folders under the specified
2294    /// directory, as if a virtual environment were present at that location.
2295    ///
2296    /// In general, prefer the use of `--python` to install into an alternate environment, as
2297    /// scripts and other artifacts installed via `--prefix` will reference the installing
2298    /// interpreter, rather than any interpreter added to the `--prefix` directory, rendering them
2299    /// non-portable.
2300    ///
2301    /// Unlike other install operations, this command does not require discovery of an existing Python
2302    /// environment and only searches for a Python interpreter to use for package resolution.
2303    /// If a suitable Python interpreter cannot be found, uv will install one.
2304    /// To disable this, add `--no-python-downloads`.
2305    #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2306    pub prefix: Option<PathBuf>,
2307
2308    /// Don't build source distributions.
2309    ///
2310    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
2311    /// operations that require building a source distribution will exit with an error. uv may
2312    /// still build editable requirements, and their build backends may run arbitrary Python code.
2313    ///
2314    /// Alias for `--only-binary :all:`.
2315    #[arg(
2316        long,
2317        conflicts_with = "no_binary",
2318        conflicts_with = "only_binary",
2319        overrides_with("build")
2320    )]
2321    pub no_build: bool,
2322
2323    #[arg(
2324        long,
2325        conflicts_with = "no_binary",
2326        conflicts_with = "only_binary",
2327        overrides_with("no_build"),
2328        hide = true
2329    )]
2330    pub build: bool,
2331
2332    /// Don't install pre-built wheels.
2333    ///
2334    /// The given packages will be built and installed from source. The resolver will still use
2335    /// pre-built wheels to extract package metadata, if available.
2336    ///
2337    /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
2338    /// previously specified packages with `:none:`.
2339    #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
2340    pub no_binary: Option<Vec<PackageNameSpecifier>>,
2341
2342    /// Only use pre-built wheels; don't build source distributions.
2343    ///
2344    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
2345    /// operations that require building a source distribution for the given packages will exit
2346    /// with an error. uv may still build editable requirements, and their build backends may run
2347    /// arbitrary Python code.
2348    ///
2349    /// Multiple packages may be provided. Disable binaries for all packages with `:all:`. Clear
2350    /// previously specified packages with `:none:`.
2351    #[arg(long, value_delimiter = ',', conflicts_with = "no_build")]
2352    pub only_binary: Option<Vec<PackageNameSpecifier>>,
2353
2354    /// The minimum Python version that should be supported by the requirements (e.g., `3.7` or
2355    /// `3.7.9`).
2356    ///
2357    /// If a patch version is omitted, the minimum patch version is assumed. For example, `3.7` is
2358    /// mapped to `3.7.0`.
2359    #[arg(long)]
2360    pub python_version: Option<PythonVersion>,
2361
2362    /// The platform for which requirements should be installed.
2363    ///
2364    /// Represented as a "target triple", a string that describes the target platform in terms of
2365    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
2366    /// `aarch64-apple-darwin`.
2367    ///
2368    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
2369    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2370    ///
2371    /// When targeting iOS, the default minimum version is `13.0`. Use
2372    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2373    ///
2374    /// When targeting Android, the default minimum Android API level is `24`. Use
2375    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
2376    ///
2377    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
2378    /// platform; as a result, the installed distributions may not be compatible with the _current_
2379    /// platform. Conversely, any distributions that are built from source may be incompatible with
2380    /// the _target_ platform, as they will be built for the _current_ platform. The
2381    /// `--python-platform` option is intended for advanced use cases.
2382    #[arg(long)]
2383    pub python_platform: Option<TargetTriple>,
2384
2385    /// Do not remove extraneous packages present in the environment.
2386    #[arg(long, overrides_with("exact"), alias = "no-exact", hide = true)]
2387    pub inexact: bool,
2388
2389    /// Perform an exact sync, removing extraneous packages.
2390    ///
2391    /// By default, installing will make the minimum necessary changes to satisfy the requirements.
2392    /// When enabled, uv will update the environment to exactly match the requirements, removing
2393    /// packages that are not included in the requirements.
2394    #[arg(long, overrides_with("inexact"))]
2395    pub exact: bool,
2396
2397    /// Validate the Python environment after completing the installation, to detect packages with
2398    /// missing dependencies or other issues.
2399    #[arg(long, overrides_with("no_strict"))]
2400    pub strict: bool,
2401
2402    #[arg(long, overrides_with("strict"), hide = true)]
2403    pub no_strict: bool,
2404
2405    /// Perform a dry run, i.e., don't actually install anything but resolve the dependencies and
2406    /// print the resulting plan.
2407    #[arg(long)]
2408    pub dry_run: bool,
2409
2410    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
2411    ///
2412    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
2413    /// and will instead use the defined backend.
2414    ///
2415    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
2416    /// uv will use the PyTorch index for CUDA 12.6.
2417    ///
2418    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
2419    /// installed CUDA drivers.
2420    ///
2421    /// This option is in preview and may change in any future release.
2422    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
2423    pub torch_backend: Option<TorchMode>,
2424
2425    #[command(flatten)]
2426    pub compat_args: compat::PipInstallCompatArgs,
2427}
2428
2429#[derive(Args)]
2430#[command(group = clap::ArgGroup::new("sources").required(true).multiple(true))]
2431pub struct PipUninstallArgs {
2432    /// Uninstall all listed packages.
2433    #[arg(group = "sources", value_hint = ValueHint::Other)]
2434    pub package: Vec<String>,
2435
2436    /// Uninstall the packages listed in the given files.
2437    ///
2438    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
2439    /// `pylock.toml`, `pyproject.toml`, `setup.py`, and `setup.cfg`.
2440    #[arg(long, short, alias = "requirement", group = "sources", value_parser = parse_file_path, value_hint = ValueHint::FilePath)]
2441    pub requirements: Vec<PathBuf>,
2442
2443    /// The Python interpreter from which packages should be uninstalled.
2444    ///
2445    /// By default, uninstallation requires a virtual environment. A path to an alternative Python
2446    /// can be provided, but it is only recommended in continuous integration (CI) environments and
2447    /// should be used with caution, as it can modify the system Python installation.
2448    ///
2449    /// See `uv help python` for details on Python discovery and supported request formats.
2450    #[arg(
2451        long,
2452        short,
2453        env = EnvVars::UV_PYTHON,
2454        verbatim_doc_comment,
2455        help_heading = "Python options",
2456        value_parser = parse_maybe_string,
2457        value_hint = ValueHint::Other,
2458    )]
2459    pub python: Option<Maybe<String>>,
2460
2461    /// Attempt to use `keyring` for authentication for remote requirements files.
2462    ///
2463    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
2464    /// the `keyring` CLI to handle authentication.
2465    ///
2466    /// Defaults to `disabled`.
2467    #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
2468    pub keyring_provider: Option<KeyringProviderType>,
2469
2470    /// Use the system Python to uninstall packages.
2471    ///
2472    /// By default, uv uninstalls from the virtual environment in the current working directory or
2473    /// any parent directory. The `--system` option instructs uv to instead use the first Python
2474    /// found in the system `PATH`.
2475    ///
2476    /// WARNING: `--system` is intended for use in continuous integration (CI) environments and
2477    /// should be used with caution, as it can modify the system Python installation.
2478    #[arg(
2479        long,
2480        env = EnvVars::UV_SYSTEM_PYTHON,
2481        value_parser = clap::builder::BoolishValueParser::new(),
2482        overrides_with("no_system")
2483    )]
2484    pub system: bool,
2485
2486    #[arg(long, overrides_with("system"), hide = true)]
2487    pub no_system: bool,
2488
2489    /// Allow uv to modify an `EXTERNALLY-MANAGED` Python installation.
2490    ///
2491    /// WARNING: `--break-system-packages` is intended for use in continuous integration (CI)
2492    /// environments, when installing into Python installations that are managed by an external
2493    /// package manager, like `apt`. It should be used with caution, as such Python installations
2494    /// explicitly recommend against modifications by other package managers (like uv or `pip`).
2495    #[arg(
2496        long,
2497        env = EnvVars::UV_BREAK_SYSTEM_PACKAGES,
2498        value_parser = clap::builder::BoolishValueParser::new(),
2499        overrides_with("no_break_system_packages")
2500    )]
2501    pub break_system_packages: bool,
2502
2503    #[arg(long, overrides_with("break_system_packages"))]
2504    pub no_break_system_packages: bool,
2505
2506    /// Uninstall packages from the specified `--target` directory.
2507    #[arg(short = 't', long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2508    pub target: Option<PathBuf>,
2509
2510    /// Uninstall packages from the specified `--prefix` directory.
2511    #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2512    pub prefix: Option<PathBuf>,
2513
2514    /// Perform a dry run, i.e., don't actually uninstall anything but print the resulting plan.
2515    #[arg(long)]
2516    pub dry_run: bool,
2517
2518    #[command(flatten)]
2519    pub compat_args: compat::PipUninstallCompatArgs,
2520}
2521
2522#[derive(Args)]
2523pub struct PipFreezeArgs {
2524    /// Exclude any editable packages from output.
2525    #[arg(long)]
2526    pub exclude_editable: bool,
2527
2528    /// Exclude the specified package(s) from the output.
2529    #[arg(long)]
2530    pub r#exclude: Vec<PackageName>,
2531
2532    /// Validate the Python environment, to detect packages with missing dependencies and other
2533    /// issues.
2534    #[arg(long, overrides_with("no_strict"))]
2535    pub strict: bool,
2536
2537    #[arg(long, overrides_with("strict"), hide = true)]
2538    pub no_strict: bool,
2539
2540    /// The Python interpreter for which packages should be listed.
2541    ///
2542    /// By default, uv lists packages in a virtual environment but will show packages in a system
2543    /// Python environment if no virtual environment is found.
2544    ///
2545    /// See `uv help python` for details on Python discovery and supported request formats.
2546    #[arg(
2547        long,
2548        short,
2549        env = EnvVars::UV_PYTHON,
2550        verbatim_doc_comment,
2551        help_heading = "Python options",
2552        value_parser = parse_maybe_string,
2553        value_hint = ValueHint::Other,
2554    )]
2555    pub python: Option<Maybe<String>>,
2556
2557    /// Restrict to the specified installation path for listing packages (can be used multiple times).
2558    #[arg(long("path"), value_parser = parse_file_path, value_hint = ValueHint::DirPath)]
2559    pub paths: Option<Vec<PathBuf>>,
2560
2561    /// List packages in the system Python environment.
2562    ///
2563    /// Disables discovery of virtual environments.
2564    ///
2565    /// See `uv help python` for details on Python discovery.
2566    #[arg(
2567        long,
2568        env = EnvVars::UV_SYSTEM_PYTHON,
2569        value_parser = clap::builder::BoolishValueParser::new(),
2570        overrides_with("no_system")
2571    )]
2572    pub system: bool,
2573
2574    #[arg(long, overrides_with("system"), hide = true)]
2575    pub no_system: bool,
2576
2577    /// List packages from the specified `--target` directory.
2578    #[arg(short = 't', long, conflicts_with_all = ["prefix", "paths"], value_hint = ValueHint::DirPath)]
2579    pub target: Option<PathBuf>,
2580
2581    /// List packages from the specified `--prefix` directory.
2582    #[arg(long, conflicts_with_all = ["target", "paths"], value_hint = ValueHint::DirPath)]
2583    pub prefix: Option<PathBuf>,
2584
2585    #[command(flatten)]
2586    pub compat_args: compat::PipGlobalCompatArgs,
2587}
2588
2589#[derive(Args)]
2590pub struct PipListArgs {
2591    /// Only include editable projects.
2592    #[arg(short, long)]
2593    pub editable: bool,
2594
2595    /// Exclude any editable packages from output.
2596    #[arg(long, conflicts_with = "editable")]
2597    pub exclude_editable: bool,
2598
2599    /// Exclude the specified package(s) from the output.
2600    #[arg(long, value_hint = ValueHint::Other)]
2601    pub r#exclude: Vec<PackageName>,
2602
2603    /// Select the output format.
2604    #[arg(long, value_enum, default_value_t = ListFormat::default())]
2605    pub format: ListFormat,
2606
2607    /// List outdated packages.
2608    ///
2609    /// The latest version of each package will be shown alongside the installed version. Up-to-date
2610    /// packages will be omitted from the output.
2611    #[arg(long, overrides_with("no_outdated"))]
2612    pub outdated: bool,
2613
2614    #[arg(long, overrides_with("outdated"), hide = true)]
2615    pub no_outdated: bool,
2616
2617    /// Validate the Python environment, to detect packages with missing dependencies and other
2618    /// issues.
2619    #[arg(long, overrides_with("no_strict"))]
2620    pub strict: bool,
2621
2622    #[arg(long, overrides_with("strict"), hide = true)]
2623    pub no_strict: bool,
2624
2625    #[command(flatten)]
2626    pub fetch: FetchArgs,
2627
2628    /// The Python interpreter for which packages should be listed.
2629    ///
2630    /// By default, uv lists packages in a virtual environment but will show packages in a system
2631    /// Python environment if no virtual environment is found.
2632    ///
2633    /// See `uv help python` for details on Python discovery and supported request formats.
2634    #[arg(
2635        long,
2636        short,
2637        env = EnvVars::UV_PYTHON,
2638        verbatim_doc_comment,
2639        help_heading = "Python options",
2640        value_parser = parse_maybe_string,
2641        value_hint = ValueHint::Other,
2642    )]
2643    pub python: Option<Maybe<String>>,
2644
2645    /// List packages in the system Python environment.
2646    ///
2647    /// Disables discovery of virtual environments.
2648    ///
2649    /// See `uv help python` for details on Python discovery.
2650    #[arg(
2651        long,
2652        env = EnvVars::UV_SYSTEM_PYTHON,
2653        value_parser = clap::builder::BoolishValueParser::new(),
2654        overrides_with("no_system")
2655    )]
2656    pub system: bool,
2657
2658    #[arg(long, overrides_with("system"), hide = true)]
2659    pub no_system: bool,
2660
2661    /// List packages from the specified `--target` directory.
2662    #[arg(short = 't', long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2663    pub target: Option<PathBuf>,
2664
2665    /// List packages from the specified `--prefix` directory.
2666    #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2667    pub prefix: Option<PathBuf>,
2668
2669    #[command(flatten)]
2670    pub compat_args: compat::PipListCompatArgs,
2671}
2672
2673#[derive(Args)]
2674pub struct PipCheckArgs {
2675    /// The Python interpreter for which packages should be checked.
2676    ///
2677    /// By default, uv checks packages in a virtual environment but will check packages in a system
2678    /// Python environment if no virtual environment is found.
2679    ///
2680    /// See `uv help python` for details on Python discovery and supported request formats.
2681    #[arg(
2682        long,
2683        short,
2684        env = EnvVars::UV_PYTHON,
2685        verbatim_doc_comment,
2686        help_heading = "Python options",
2687        value_parser = parse_maybe_string,
2688        value_hint = ValueHint::Other,
2689    )]
2690    pub python: Option<Maybe<String>>,
2691
2692    /// Check packages in the system Python environment.
2693    ///
2694    /// Disables discovery of virtual environments.
2695    ///
2696    /// See `uv help python` for details on Python discovery.
2697    #[arg(
2698        long,
2699        env = EnvVars::UV_SYSTEM_PYTHON,
2700        value_parser = clap::builder::BoolishValueParser::new(),
2701        overrides_with("no_system")
2702    )]
2703    pub system: bool,
2704
2705    #[arg(long, overrides_with("system"), hide = true)]
2706    pub no_system: bool,
2707
2708    /// The Python version against which packages should be checked.
2709    ///
2710    /// By default, the installed packages are checked against the version of the current
2711    /// interpreter.
2712    #[arg(long)]
2713    pub python_version: Option<PythonVersion>,
2714
2715    /// The platform for which packages should be checked.
2716    ///
2717    /// By default, the installed packages are checked against the platform of the current
2718    /// interpreter.
2719    ///
2720    /// Represented as a "target triple", a string that describes the target platform in terms of
2721    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
2722    /// `aarch64-apple-darwin`.
2723    ///
2724    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
2725    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2726    ///
2727    /// When targeting iOS, the default minimum version is `13.0`. Use
2728    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
2729    ///
2730    /// When targeting Android, the default minimum Android API level is `24`. Use
2731    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
2732    #[arg(long)]
2733    pub python_platform: Option<TargetTriple>,
2734}
2735
2736#[derive(Args)]
2737pub struct PipShowArgs {
2738    /// The package(s) to display.
2739    #[arg(value_hint = ValueHint::Other)]
2740    pub package: Vec<PackageName>,
2741
2742    /// Validate the Python environment, to detect packages with missing dependencies and other
2743    /// issues.
2744    #[arg(long, overrides_with("no_strict"))]
2745    pub strict: bool,
2746
2747    #[arg(long, overrides_with("strict"), hide = true)]
2748    pub no_strict: bool,
2749
2750    /// Show the full list of installed files for each package.
2751    #[arg(short, long)]
2752    pub files: bool,
2753
2754    /// The Python interpreter to find the package in.
2755    ///
2756    /// By default, uv looks for packages in a virtual environment but will look for packages in a
2757    /// system Python environment if no virtual environment is found.
2758    ///
2759    /// See `uv help python` for details on Python discovery and supported request formats.
2760    #[arg(
2761        long,
2762        short,
2763        env = EnvVars::UV_PYTHON,
2764        verbatim_doc_comment,
2765        help_heading = "Python options",
2766        value_parser = parse_maybe_string,
2767        value_hint = ValueHint::Other,
2768    )]
2769    pub python: Option<Maybe<String>>,
2770
2771    /// Show a package in the system Python environment.
2772    ///
2773    /// Disables discovery of virtual environments.
2774    ///
2775    /// See `uv help python` for details on Python discovery.
2776    #[arg(
2777        long,
2778        env = EnvVars::UV_SYSTEM_PYTHON,
2779        value_parser = clap::builder::BoolishValueParser::new(),
2780        overrides_with("no_system")
2781    )]
2782    pub system: bool,
2783
2784    #[arg(long, overrides_with("system"), hide = true)]
2785    pub no_system: bool,
2786
2787    /// Show a package from the specified `--target` directory.
2788    #[arg(short = 't', long, conflicts_with = "prefix", value_hint = ValueHint::DirPath)]
2789    pub target: Option<PathBuf>,
2790
2791    /// Show a package from the specified `--prefix` directory.
2792    #[arg(long, conflicts_with = "target", value_hint = ValueHint::DirPath)]
2793    pub prefix: Option<PathBuf>,
2794
2795    #[command(flatten)]
2796    pub compat_args: compat::PipGlobalCompatArgs,
2797}
2798
2799#[derive(Args)]
2800pub struct PipTreeArgs {
2801    /// Show the version constraint(s) imposed on each package.
2802    #[arg(long)]
2803    pub show_version_specifiers: bool,
2804
2805    #[command(flatten)]
2806    pub tree: DisplayTreeArgs,
2807
2808    /// Validate the Python environment, to detect packages with missing dependencies and other
2809    /// issues.
2810    #[arg(long, overrides_with("no_strict"))]
2811    pub strict: bool,
2812
2813    #[arg(long, overrides_with("strict"), hide = true)]
2814    pub no_strict: bool,
2815
2816    #[command(flatten)]
2817    pub fetch: FetchArgs,
2818
2819    /// The Python interpreter for which packages should be listed.
2820    ///
2821    /// By default, uv lists packages in a virtual environment but will show packages in a system
2822    /// Python environment if no virtual environment is found.
2823    ///
2824    /// See `uv help python` for details on Python discovery and supported request formats.
2825    #[arg(
2826        long,
2827        short,
2828        env = EnvVars::UV_PYTHON,
2829        verbatim_doc_comment,
2830        help_heading = "Python options",
2831        value_parser = parse_maybe_string,
2832        value_hint = ValueHint::Other,
2833    )]
2834    pub python: Option<Maybe<String>>,
2835
2836    /// List packages in the system Python environment.
2837    ///
2838    /// Disables discovery of virtual environments.
2839    ///
2840    /// See `uv help python` for details on Python discovery.
2841    #[arg(
2842        long,
2843        env = EnvVars::UV_SYSTEM_PYTHON,
2844        value_parser = clap::builder::BoolishValueParser::new(),
2845        overrides_with("no_system")
2846    )]
2847    pub system: bool,
2848
2849    #[arg(long, overrides_with("system"), hide = true)]
2850    pub no_system: bool,
2851
2852    #[command(flatten)]
2853    pub compat_args: compat::PipGlobalCompatArgs,
2854}
2855
2856#[derive(Args)]
2857pub struct PipDebugArgs {
2858    #[arg(long, hide = true)]
2859    platform: Option<String>,
2860
2861    #[arg(long, hide = true)]
2862    python_version: Option<String>,
2863
2864    #[arg(long, hide = true)]
2865    implementation: Option<String>,
2866
2867    #[arg(long, hide = true)]
2868    abi: Option<String>,
2869}
2870
2871#[derive(Args)]
2872pub struct BuildArgs {
2873    /// The directory from which distributions should be built, or a source
2874    /// distribution archive to build into a wheel.
2875    ///
2876    /// Defaults to the current working directory.
2877    #[arg(value_parser = parse_file_path, value_hint = ValueHint::DirPath)]
2878    pub src: Option<PathBuf>,
2879
2880    /// Build a specific package in the workspace.
2881    ///
2882    /// The workspace will be discovered from the provided source directory, or the current
2883    /// directory if no source directory is provided.
2884    ///
2885    /// If the workspace member does not exist, uv will exit with an error.
2886    #[arg(long, conflicts_with("all_packages"), value_hint = ValueHint::Other)]
2887    pub package: Option<PackageName>,
2888
2889    /// Builds all packages in the workspace.
2890    ///
2891    /// The workspace will be discovered from the provided source directory, or the current
2892    /// directory if no source directory is provided.
2893    ///
2894    /// If the workspace member does not exist, uv will exit with an error.
2895    #[arg(long, alias = "all", conflicts_with("package"))]
2896    pub all_packages: bool,
2897
2898    /// The output directory to which distributions should be written.
2899    ///
2900    /// Defaults to the `dist` subdirectory within the source directory, or the
2901    /// directory containing the source distribution archive.
2902    #[arg(long, short, value_parser = parse_file_path, value_hint = ValueHint::DirPath)]
2903    pub out_dir: Option<PathBuf>,
2904
2905    /// Build a source distribution ("sdist") from the given directory.
2906    #[arg(long)]
2907    pub sdist: bool,
2908
2909    /// Build a binary distribution ("wheel") from the given directory.
2910    #[arg(long)]
2911    pub wheel: bool,
2912
2913    /// When using the uv build backend, list the files that would be included when building.
2914    ///
2915    /// Skips building the actual distribution, except when the source distribution is needed to
2916    /// build the wheel. The file list is collected directly without a PEP 517 environment. It only
2917    /// works with the uv build backend, there is no PEP 517 file list build hook.
2918    ///
2919    /// This option can be combined with `--sdist` and `--wheel` for inspecting different build
2920    /// paths.
2921    // Hidden while in preview.
2922    #[arg(long, hide = true)]
2923    pub list: bool,
2924
2925    #[arg(long, overrides_with("no_build_logs"), hide = true)]
2926    pub build_logs: bool,
2927
2928    /// Hide logs from the build backend.
2929    #[arg(long, overrides_with("build_logs"))]
2930    pub no_build_logs: bool,
2931
2932    /// Always build through PEP 517, don't use the fast path for the uv build backend.
2933    ///
2934    /// By default, uv won't create a PEP 517 build environment for packages using the uv build
2935    /// backend, but use a fast path that calls into the build backend directly. This option forces
2936    /// always using PEP 517.
2937    #[arg(long, conflicts_with = "list")]
2938    pub force_pep517: bool,
2939
2940    /// Clear the output directory before the build, removing stale artifacts.
2941    #[arg(long)]
2942    pub clear: bool,
2943
2944    #[arg(long, overrides_with("no_create_gitignore"), hide = true)]
2945    pub create_gitignore: bool,
2946
2947    /// Do not create a `.gitignore` file in the output directory.
2948    ///
2949    /// By default, uv creates a `.gitignore` file in the output directory to exclude build
2950    /// artifacts from version control. When this flag is used, the file will be omitted.
2951    #[arg(long, overrides_with("create_gitignore"))]
2952    pub no_create_gitignore: bool,
2953
2954    /// Constrain build dependencies using the given requirements files when building distributions.
2955    ///
2956    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
2957    /// build dependency that's installed. However, including a package in a constraints file will
2958    /// _not_ trigger the inclusion of that package on its own.
2959    #[arg(
2960        long,
2961        short,
2962        alias = "build-constraint",
2963        env = EnvVars::UV_BUILD_CONSTRAINT,
2964        value_delimiter = ' ',
2965        value_parser = parse_maybe_file_path,
2966        value_hint = ValueHint::FilePath,
2967    )]
2968    pub build_constraints: Vec<Maybe<PathBuf>>,
2969
2970    #[command(flatten)]
2971    pub hash_checking: HashCheckingArgs,
2972
2973    /// The Python interpreter to use for the build environment.
2974    ///
2975    /// By default, builds are executed in isolated virtual environments. The discovered interpreter
2976    /// will be used to create those environments, and will be symlinked or copied in depending on
2977    /// the platform.
2978    ///
2979    /// See `uv help python` to view supported request formats.
2980    #[arg(
2981        long,
2982        short,
2983        env = EnvVars::UV_PYTHON,
2984        verbatim_doc_comment,
2985        help_heading = "Python options",
2986        value_parser = parse_maybe_string,
2987        value_hint = ValueHint::Other,
2988    )]
2989    pub python: Option<Maybe<String>>,
2990
2991    #[command(flatten)]
2992    pub resolver: ResolverArgs,
2993
2994    #[command(flatten)]
2995    pub build: BuildOptionsArgs,
2996
2997    #[command(flatten)]
2998    pub refresh: RefreshArgs,
2999}
3000
3001#[derive(Args)]
3002pub struct VenvArgs {
3003    /// The Python interpreter to use for the virtual environment.
3004    ///
3005    /// During virtual environment creation, uv will not look for Python interpreters in virtual
3006    /// environments.
3007    ///
3008    /// See `uv help python` for details on Python discovery and supported request formats.
3009    #[arg(
3010        long,
3011        short,
3012        env = EnvVars::UV_PYTHON,
3013        verbatim_doc_comment,
3014        help_heading = "Python options",
3015        value_parser = parse_maybe_string,
3016        value_hint = ValueHint::Other,
3017    )]
3018    pub python: Option<Maybe<String>>,
3019
3020    /// Ignore virtual environments when searching for the Python interpreter.
3021    ///
3022    /// This is the default behavior and has no effect.
3023    #[arg(
3024        long,
3025        env = EnvVars::UV_SYSTEM_PYTHON,
3026        value_parser = clap::builder::BoolishValueParser::new(),
3027        overrides_with("no_system"),
3028        hide = true,
3029    )]
3030    pub system: bool,
3031
3032    /// This flag is included for compatibility only, it has no effect.
3033    ///
3034    /// uv will never search for interpreters in virtual environments when creating a virtual
3035    /// environment.
3036    #[arg(long, overrides_with("system"), hide = true)]
3037    pub no_system: bool,
3038
3039    /// Avoid discovering a project or workspace.
3040    ///
3041    /// By default, uv searches for projects in the current directory or any parent directory to
3042    /// determine the default path of the virtual environment and check for Python version
3043    /// constraints, if any.
3044    #[arg(
3045        long,
3046        alias = "no-workspace",
3047        env = EnvVars::UV_NO_PROJECT,
3048        value_parser = clap::builder::BoolishValueParser::new()
3049    )]
3050    pub no_project: bool,
3051
3052    /// Install seed packages (one or more of: `pip`, `setuptools`, and `wheel`) into the virtual
3053    /// environment [env: UV_VENV_SEED=]
3054    ///
3055    /// Note that `setuptools` and `wheel` are not included in Python 3.12+ environments.
3056    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3057    pub seed: bool,
3058
3059    /// Remove any existing files or directories at the target path [env: UV_VENV_CLEAR=]
3060    ///
3061    /// By default, `uv venv` will exit with an error if the given path is non-empty. The
3062    /// `--clear` option will instead clear a non-empty path before creating a new virtual
3063    /// environment.
3064    #[clap(long, short, overrides_with = "allow_existing", value_parser = clap::builder::BoolishValueParser::new())]
3065    pub clear: bool,
3066
3067    /// Allow `--clear` to remove a non-virtual environment directory.
3068    ///
3069    /// This will remove all files and directories at the target path.
3070    #[arg(long)]
3071    pub force: bool,
3072
3073    /// Fail without prompting if any existing files or directories are present at the target path.
3074    ///
3075    /// By default, when a TTY is available, `uv venv` will prompt to clear a non-empty directory.
3076    /// When `--no-clear` is used, the command will exit with an error instead of prompting.
3077    #[clap(
3078        long,
3079        overrides_with = "clear",
3080        conflicts_with = "allow_existing",
3081        hide = true
3082    )]
3083    pub no_clear: bool,
3084
3085    /// Preserve any existing files or directories at the target path.
3086    ///
3087    /// By default, `uv venv` will exit with an error if the given path is non-empty. The
3088    /// `--allow-existing` option will instead write to the given path, regardless of its contents,
3089    /// and without clearing it beforehand.
3090    ///
3091    /// WARNING: This option can lead to unexpected behavior if the existing virtual environment and
3092    /// the newly-created virtual environment are linked to different Python interpreters.
3093    #[clap(long, overrides_with = "clear")]
3094    pub allow_existing: bool,
3095
3096    /// The path to the virtual environment to create.
3097    ///
3098    /// Default to `.venv` in the working directory.
3099    ///
3100    /// Relative paths are resolved relative to the working directory.
3101    #[arg(value_hint = ValueHint::DirPath)]
3102    pub path: Option<PathBuf>,
3103
3104    /// Provide an alternative prompt prefix for the virtual environment.
3105    ///
3106    /// By default, the prompt is dependent on whether a path was provided to `uv venv`. If provided
3107    /// (e.g, `uv venv project`), the prompt is set to the directory name. If not provided
3108    /// (`uv venv`), the prompt is set to the current directory's name.
3109    ///
3110    /// If "." is provided, the current directory name will be used regardless of whether a path was
3111    /// provided to `uv venv`.
3112    #[arg(long, verbatim_doc_comment, value_hint = ValueHint::Other)]
3113    pub prompt: Option<String>,
3114
3115    /// Give the virtual environment access to the system site packages directory.
3116    ///
3117    /// Unlike `pip`, when a virtual environment is created with `--system-site-packages`, uv will
3118    /// _not_ take system site packages into account when running commands like `uv pip list` or `uv
3119    /// pip install`. The `--system-site-packages` flag will provide the virtual environment with
3120    /// access to the system site packages directory at runtime, but will not affect the behavior of
3121    /// uv commands.
3122    #[arg(long)]
3123    pub system_site_packages: bool,
3124
3125    /// Make the virtual environment relocatable [env: UV_VENV_RELOCATABLE=]
3126    ///
3127    /// A relocatable virtual environment can be moved around and redistributed without invalidating
3128    /// its associated entrypoint and activation scripts.
3129    ///
3130    /// Note that this can only be guaranteed for standard `console_scripts` and `gui_scripts`.
3131    /// Other scripts may be adjusted if they ship with a generic `#!python[w]` shebang, and
3132    /// binaries are left as-is.
3133    ///
3134    /// As a result of making the environment relocatable (by way of writing relative, rather than
3135    /// absolute paths), the entrypoints and scripts themselves will _not_ be relocatable. In other
3136    /// words, copying those entrypoints and scripts to a location outside the environment will not
3137    /// work, as they reference paths relative to the environment itself.
3138    #[expect(clippy::doc_markdown)]
3139    #[arg(long, overrides_with("no_relocatable"))]
3140    pub relocatable: bool,
3141
3142    /// Don't make the virtual environment relocatable.
3143    ///
3144    /// Disables the default relocatable behavior when the `relocatable-envs-default` preview
3145    /// feature is enabled.
3146    #[arg(long, overrides_with("relocatable"), hide = true)]
3147    pub no_relocatable: bool,
3148
3149    #[command(flatten)]
3150    pub index_args: IndexArgs,
3151
3152    #[command(flatten)]
3153    pub registry_client: RegistryClientArgs,
3154
3155    #[command(flatten)]
3156    pub exclude_newer: PackageExcludeNewerArgs,
3157
3158    /// The method to use when installing packages from the global cache.
3159    ///
3160    /// This option is only used for installing seed packages.
3161    ///
3162    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
3163    /// Windows.
3164    ///
3165    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
3166    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
3167    /// will break all installed packages by way of removing the underlying source files. Use
3168    /// symlinks with caution.
3169    #[arg(long, value_enum, env = EnvVars::UV_LINK_MODE)]
3170    pub link_mode: Option<uv_install_wheel::LinkMode>,
3171
3172    #[command(flatten)]
3173    pub refresh: RefreshArgs,
3174
3175    #[command(flatten)]
3176    pub compat_args: compat::VenvCompatArgs,
3177}
3178
3179#[derive(Parser, Debug, Clone)]
3180pub enum ExternalCommand {
3181    #[command(external_subcommand)]
3182    Cmd(Vec<OsString>),
3183}
3184
3185impl Deref for ExternalCommand {
3186    type Target = Vec<OsString>;
3187
3188    fn deref(&self) -> &Self::Target {
3189        match self {
3190            Self::Cmd(cmd) => cmd,
3191        }
3192    }
3193}
3194
3195impl DerefMut for ExternalCommand {
3196    fn deref_mut(&mut self) -> &mut Self::Target {
3197        match self {
3198            Self::Cmd(cmd) => cmd,
3199        }
3200    }
3201}
3202
3203impl ExternalCommand {
3204    pub fn split(&self) -> (Option<&OsString>, &[OsString]) {
3205        match self.as_slice() {
3206            [] => (None, &[]),
3207            [cmd, args @ ..] => (Some(cmd), args),
3208        }
3209    }
3210}
3211
3212#[derive(Debug, Default, Copy, Clone, clap::ValueEnum)]
3213pub enum AuthorFrom {
3214    /// Fetch the author information from some sources (e.g., Git) automatically.
3215    #[default]
3216    Auto,
3217    /// Fetch the author information from Git configuration only.
3218    Git,
3219    /// Do not infer the author information.
3220    None,
3221}
3222
3223#[derive(Args)]
3224pub struct InitArgs {
3225    /// The path to use for the project/script.
3226    ///
3227    /// Defaults to the current working directory when initializing an app or library; required when
3228    /// initializing a script. Accepts relative and absolute paths.
3229    ///
3230    /// If a `pyproject.toml` is found in any of the parent directories of the target path, the
3231    /// project will be added as a workspace member of the parent, unless `--no-workspace` is
3232    /// provided.
3233    #[arg(required_if_eq("script", "true"), value_hint = ValueHint::DirPath)]
3234    pub path: Option<PathBuf>,
3235
3236    /// The name of the project.
3237    ///
3238    /// Defaults to the name of the directory.
3239    #[arg(long, conflicts_with = "script", value_hint = ValueHint::Other)]
3240    pub name: Option<PackageName>,
3241
3242    /// Only create a `pyproject.toml`.
3243    ///
3244    /// Disables creating extra files like `README.md`, the `src/` tree, `.python-version` files,
3245    /// etc.
3246    ///
3247    /// A `[build-system]` table is only created with `--package` or `--build-backend`.
3248    ///
3249    /// When combined with `--script`, the script will only contain the inline metadata header.
3250    #[arg(long)]
3251    pub bare: bool,
3252
3253    /// Create a virtual project, rather than a package.
3254    ///
3255    /// This option is deprecated and will be removed in a future release.
3256    #[arg(long, hide = true, conflicts_with = "package")]
3257    pub r#virtual: bool,
3258
3259    /// Set up the project to be built as a Python package.
3260    ///
3261    /// Defines a `[build-system]` for the project.
3262    ///
3263    /// This is the default behavior.
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    /// This option creates the project structure as a flat directory that is not importable as a
3270    /// module and has no `[build-system]` entry. It can be used for applications that are not
3271    /// expected to be distributed as a package.
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 project kind is for web servers, scripts, and command-line interfaces.
3278    ///
3279    /// Applications are packaged by default. Use `--no-package` to create an unpackaged application.
3280    #[arg(long, alias = "application", conflicts_with_all = ["lib", "script"])]
3281    pub r#app: bool,
3282
3283    /// Create a project for a library.
3284    ///
3285    /// A library is a project that is intended to be built and distributed as a Python package.
3286    #[arg(long, alias = "library", conflicts_with_all=["app", "script"])]
3287    pub r#lib: bool,
3288
3289    /// Create a script.
3290    ///
3291    /// A script is a standalone file with embedded metadata enumerating its dependencies, along
3292    /// with any Python version requirements, as defined in the PEP 723 specification.
3293    ///
3294    /// PEP 723 scripts can be executed directly with `uv run`.
3295    ///
3296    /// By default, adds a requirement on the system Python version; use `--python` to specify an
3297    /// alternative Python version requirement.
3298    #[arg(long, conflicts_with_all=["app", "lib", "package", "build_backend", "description"])]
3299    pub r#script: bool,
3300
3301    /// Set the project description.
3302    #[arg(long, conflicts_with = "script", overrides_with = "no_description", value_hint = ValueHint::Other)]
3303    pub description: Option<String>,
3304
3305    /// Disable the description for the project.
3306    #[arg(long, conflicts_with = "script", overrides_with = "description")]
3307    pub no_description: bool,
3308
3309    /// Initialize a version control system for the project.
3310    ///
3311    /// By default, uv will initialize a Git repository (`git`). Use `--vcs none` to explicitly
3312    /// avoid initializing a version control system.
3313    #[arg(long, value_enum, conflicts_with = "script")]
3314    pub vcs: Option<VersionControlSystem>,
3315
3316    /// Initialize a build-backend of choice for the project.
3317    ///
3318    /// Implicitly sets `--package`.
3319    #[arg(long, value_enum, conflicts_with_all=["script", "no_package"], env = EnvVars::UV_INIT_BUILD_BACKEND)]
3320    pub build_backend: Option<ProjectBuildBackend>,
3321
3322    /// Invalid option name for build backend.
3323    #[arg(
3324        long,
3325        required(false),
3326        action(clap::ArgAction::SetTrue),
3327        value_parser=clap::builder::UnknownArgumentValueParser::suggest_arg("--build-backend"),
3328        hide(true)
3329    )]
3330    backend: Option<String>,
3331
3332    /// Do not create a `README.md` file.
3333    #[arg(long)]
3334    pub no_readme: bool,
3335
3336    /// Fill in the `authors` field in the `pyproject.toml`.
3337    ///
3338    /// By default, uv will attempt to infer the author information from some sources (e.g., Git)
3339    /// (`auto`). Use `--author-from git` to only infer from Git configuration. Use `--author-from
3340    /// none` to avoid inferring the author information.
3341    #[arg(long, value_enum)]
3342    pub author_from: Option<AuthorFrom>,
3343
3344    /// Do not create a `.python-version` file for the project.
3345    ///
3346    /// By default, uv will create a `.python-version` file containing the minor version of the
3347    /// discovered Python interpreter, which will cause subsequent uv commands to use that version.
3348    #[arg(long)]
3349    pub no_pin_python: bool,
3350
3351    /// Create a `.python-version` file for the project.
3352    ///
3353    /// This is the default.
3354    #[arg(long, hide = true)]
3355    pub pin_python: bool,
3356
3357    /// Avoid discovering a workspace and create a standalone project.
3358    ///
3359    /// By default, uv searches for workspaces in the current directory or any parent directory.
3360    #[arg(long, alias = "no-project")]
3361    pub no_workspace: bool,
3362
3363    /// The Python interpreter to use to determine the minimum supported Python version.
3364    ///
3365    /// See `uv help python` to view supported request formats.
3366    #[arg(
3367        long,
3368        short,
3369        env = EnvVars::UV_PYTHON,
3370        verbatim_doc_comment,
3371        help_heading = "Python options",
3372        value_parser = parse_maybe_string,
3373        value_hint = ValueHint::Other,
3374    )]
3375    pub python: Option<Maybe<String>>,
3376}
3377
3378#[derive(Args)]
3379pub struct RunArgs {
3380    /// Include optional dependencies from the specified extra name.
3381    ///
3382    /// May be provided more than once.
3383    ///
3384    /// This option is only available when running in a project.
3385    #[arg(
3386        long,
3387        conflicts_with = "all_extras",
3388        conflicts_with = "only_group",
3389        value_delimiter = ',',
3390        value_parser = extra_name_with_clap_error,
3391        value_hint = ValueHint::Other,
3392    )]
3393    pub extra: Option<Vec<ExtraName>>,
3394
3395    /// Include all optional dependencies.
3396    ///
3397    /// This option is only available when running in a project.
3398    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3399    pub all_extras: bool,
3400
3401    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3402    ///
3403    /// May be provided multiple times.
3404    #[arg(long, value_hint = ValueHint::Other)]
3405    pub no_extra: Vec<ExtraName>,
3406
3407    #[arg(long, overrides_with("all_extras"), hide = true)]
3408    pub no_all_extras: bool,
3409
3410    /// Include the development dependency group [env: UV_DEV=]
3411    ///
3412    /// Development dependencies are defined via `dependency-groups.dev` or
3413    /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
3414    ///
3415    /// This option is an alias for `--group dev`.
3416    ///
3417    /// This option is only available when running in a project.
3418    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
3419    pub dev: bool,
3420
3421    /// Disable the development dependency group [env: UV_NO_DEV=]
3422    ///
3423    /// This option is an alias of `--no-group dev`.
3424    /// See `--no-default-groups` to disable all default groups instead.
3425    ///
3426    /// This option is only available when running in a project.
3427    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
3428    pub no_dev: bool,
3429
3430    /// Include dependencies from the specified dependency group.
3431    ///
3432    /// May be provided multiple times.
3433    #[arg(long, conflicts_with_all = ["only_group", "only_dev"], value_hint = ValueHint::Other)]
3434    pub group: Vec<GroupName>,
3435
3436    /// Disable the specified dependency group [env: `UV_NO_GROUP`=]
3437    ///
3438    /// This option always takes precedence over default groups,
3439    /// `--all-groups`, and `--group`.
3440    ///
3441    /// May be provided multiple times.
3442    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
3443    pub no_group: Vec<GroupName>,
3444
3445    /// Ignore the default dependency groups.
3446    ///
3447    /// uv includes the groups defined in `tool.uv.default-groups` by default.
3448    /// This disables that option, however, specific groups can still be included with `--group`.
3449    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
3450    pub no_default_groups: bool,
3451
3452    /// Only include dependencies from the specified dependency group.
3453    ///
3454    /// The project and its dependencies will be omitted.
3455    ///
3456    /// May be provided multiple times. Implies `--no-default-groups`.
3457    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
3458    pub only_group: Vec<GroupName>,
3459
3460    /// Include dependencies from all dependency groups.
3461    ///
3462    /// `--no-group` can be used to exclude specific groups.
3463    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3464    pub all_groups: bool,
3465
3466    /// Run a Python module.
3467    ///
3468    /// Equivalent to `python -m <module>`.
3469    #[arg(short, long, conflicts_with_all = ["script", "gui_script"])]
3470    pub module: bool,
3471
3472    /// Only include the development dependency group.
3473    ///
3474    /// The project and its dependencies will be omitted.
3475    ///
3476    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3477    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3478    pub only_dev: bool,
3479
3480    /// Install any non-editable dependencies, including the project and any workspace members, as
3481    /// editable.
3482    #[arg(long, overrides_with = "no_editable", hide = true)]
3483    pub editable: bool,
3484
3485    /// Install any editable dependencies, including the project and any workspace members, as
3486    /// non-editable [env: UV_NO_EDITABLE=]
3487    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new())]
3488    pub no_editable: bool,
3489
3490    /// Install the specified editable packages as non-editable.
3491    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
3492    pub no_editable_package: Vec<PackageName>,
3493
3494    /// Do not remove extraneous packages present in the environment.
3495    #[arg(long, overrides_with("exact"), alias = "no-exact", hide = true)]
3496    pub inexact: bool,
3497
3498    /// Perform an exact sync, removing extraneous packages.
3499    ///
3500    /// When enabled, uv will remove any extraneous packages from the environment. By default, `uv
3501    /// run` will make the minimum necessary changes to satisfy the requirements.
3502    #[arg(long, overrides_with("inexact"))]
3503    pub exact: bool,
3504
3505    /// Load environment variables from a `.env` file.
3506    ///
3507    /// Can be provided multiple times, with subsequent files overriding values defined in previous
3508    /// files.
3509    #[arg(long, env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
3510    pub env_file: Vec<String>,
3511
3512    /// Avoid reading environment variables from a `.env` file [env: UV_NO_ENV_FILE=]
3513    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3514    pub no_env_file: bool,
3515
3516    /// The command to run.
3517    ///
3518    /// If the path to a Python script (i.e., ending in `.py`), it will be
3519    /// executed with the Python interpreter.
3520    #[command(subcommand)]
3521    pub command: Option<ExternalCommand>,
3522
3523    /// Run with the given packages installed.
3524    ///
3525    /// When used in a project, these dependencies will be layered on top of the project environment
3526    /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3527    /// specified by the project.
3528    #[arg(short = 'w', long, value_hint = ValueHint::Other)]
3529    pub with: Vec<comma::CommaSeparatedRequirements>,
3530
3531    /// Run with the given packages installed in editable mode.
3532    ///
3533    /// When used in a project, these dependencies will be layered on top of the project environment
3534    /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those
3535    /// specified by the project.
3536    #[arg(long, value_hint = ValueHint::DirPath)]
3537    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
3538
3539    /// Run with the packages listed in the given files.
3540    ///
3541    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
3542    /// and `pylock.toml`.
3543    ///
3544    /// The same environment semantics as `--with` apply.
3545    ///
3546    /// Using `pyproject.toml`, `setup.py`, or `setup.cfg` files is not allowed.
3547    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
3548    pub with_requirements: Vec<Maybe<PathBuf>>,
3549
3550    /// Run the command in an isolated virtual environment [env: UV_ISOLATED=]
3551    ///
3552    /// Usually, the project environment is reused for performance. This option forces a fresh
3553    /// environment to be used for the project, enforcing strict isolation between dependencies and
3554    /// declaration of requirements.
3555    ///
3556    /// An editable installation is still used for the project.
3557    ///
3558    /// When used with `--with` or `--with-requirements`, the additional dependencies will still be
3559    /// layered in a second environment.
3560    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3561    pub isolated: bool,
3562
3563    /// Prefer the active virtual environment over the project's virtual environment.
3564    ///
3565    /// If the project virtual environment is active or no virtual environment is active, this has
3566    /// no effect.
3567    #[arg(long, overrides_with = "no_active")]
3568    pub active: bool,
3569
3570    /// Prefer project's virtual environment over an active environment.
3571    ///
3572    /// This is the default behavior.
3573    #[arg(long, overrides_with = "active", hide = true)]
3574    pub no_active: bool,
3575
3576    /// Avoid syncing the virtual environment [env: UV_NO_SYNC=]
3577    ///
3578    /// Implies `--frozen`, as the project dependencies will be ignored (i.e., the lockfile will not
3579    /// be updated, since the environment will not be synced regardless).
3580    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
3581    pub no_sync: bool,
3582
3583    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
3584    ///
3585    /// Requires that the lockfile is up-to-date. If the lockfile is missing or
3586    /// needs to be updated, uv will exit with an error.
3587    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
3588    pub locked: bool,
3589
3590    /// Run without updating the `uv.lock` file [env: UV_FROZEN=]
3591    ///
3592    /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3593    /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3594    /// `pyproject.toml` includes changes to dependencies that have not been included in the
3595    /// lockfile yet, they will not be present in the environment.
3596    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3597    pub frozen: bool,
3598
3599    /// Run the given path as a Python script.
3600    ///
3601    /// Using `--script` will attempt to parse the path as a PEP 723 script,
3602    /// irrespective of its extension.
3603    #[arg(long, short, conflicts_with_all = ["module", "gui_script"])]
3604    pub script: bool,
3605
3606    /// Run the given path as a Python GUI script.
3607    ///
3608    /// Using `--gui-script` will attempt to parse the path as a PEP 723 script and run it with
3609    /// `pythonw.exe`, irrespective of its extension. Only available on Windows.
3610    #[arg(long, conflicts_with_all = ["script", "module"])]
3611    pub gui_script: bool,
3612
3613    #[command(flatten)]
3614    pub installer: ResolverInstallerArgs,
3615
3616    #[command(flatten)]
3617    pub build: BuildOptionsArgs,
3618
3619    #[command(flatten)]
3620    pub refresh: RefreshArgs,
3621
3622    /// Run the command with all workspace members installed.
3623    ///
3624    /// The workspace's environment (`.venv`) is updated to include all workspace members.
3625    ///
3626    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
3627    /// to all workspace members.
3628    #[arg(long, conflicts_with = "package")]
3629    pub all_packages: bool,
3630
3631    /// Run the command in a specific package in the workspace.
3632    ///
3633    /// If the workspace member does not exist, uv will exit with an error.
3634    #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
3635    pub package: Option<PackageName>,
3636
3637    /// Avoid discovering the project or workspace.
3638    ///
3639    /// Instead of searching for projects in the current directory and parent directories, run in an
3640    /// isolated, ephemeral environment populated by the `--with` requirements.
3641    ///
3642    /// If a virtual environment is active or found in a current or parent directory, it will be
3643    /// used as if there was no project or workspace.
3644    #[arg(
3645        long,
3646        alias = "no_workspace",
3647        env = EnvVars::UV_NO_PROJECT,
3648        value_parser = clap::builder::BoolishValueParser::new(),
3649        conflicts_with = "package"
3650    )]
3651    pub no_project: bool,
3652
3653    /// The Python interpreter to use for the run environment.
3654    ///
3655    /// If the interpreter request is satisfied by a discovered environment, the environment will be
3656    /// used.
3657    ///
3658    /// See `uv help python` to view supported request formats.
3659    #[arg(
3660        long,
3661        short,
3662        env = EnvVars::UV_PYTHON,
3663        verbatim_doc_comment,
3664        help_heading = "Python options",
3665        value_parser = parse_maybe_string,
3666        value_hint = ValueHint::Other,
3667    )]
3668    pub python: Option<Maybe<String>>,
3669
3670    /// Whether to show resolver and installer output from any environment modifications [env:
3671    /// UV_SHOW_RESOLUTION=]
3672    ///
3673    /// By default, environment modifications are omitted, but enabled under `--verbose`.
3674    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
3675    pub show_resolution: bool,
3676
3677    /// Number of times that `uv run` will allow recursive invocations.
3678    ///
3679    /// The current recursion depth is tracked by environment variable. If environment variables are
3680    /// cleared, uv will fail to detect the recursion depth.
3681    ///
3682    /// If uv reaches the maximum recursion depth, it will exit with an error.
3683    #[arg(long, hide = true, env = EnvVars::UV_RUN_MAX_RECURSION_DEPTH)]
3684    pub max_recursion_depth: Option<u32>,
3685
3686    /// The platform for which requirements should be installed.
3687    ///
3688    /// Represented as a "target triple", a string that describes the target platform in terms of
3689    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
3690    /// `aarch64-apple-darwin`.
3691    ///
3692    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
3693    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3694    ///
3695    /// When targeting iOS, the default minimum version is `13.0`. Use
3696    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
3697    ///
3698    /// When targeting Android, the default minimum Android API level is `24`. Use
3699    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
3700    ///
3701    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
3702    /// platform; as a result, the installed distributions may not be compatible with the _current_
3703    /// platform. Conversely, any distributions that are built from source may be incompatible with
3704    /// the _target_ platform, as they will be built for the _current_ platform. The
3705    /// `--python-platform` option is intended for advanced use cases.
3706    #[arg(long)]
3707    pub python_platform: Option<TargetTriple>,
3708}
3709
3710#[derive(Args)]
3711pub struct SyncArgs {
3712    /// Include optional dependencies from the specified extra name.
3713    ///
3714    /// May be provided more than once.
3715    ///
3716    /// When multiple extras or groups are specified that appear in `tool.uv.conflicts`, uv will
3717    /// report an error.
3718    ///
3719    /// Note that all optional dependencies are always included in the resolution; this option only
3720    /// affects the selection of packages to install.
3721    #[arg(
3722        long,
3723        conflicts_with = "all_extras",
3724        conflicts_with = "only_group",
3725        value_delimiter = ',',
3726        value_parser = extra_name_with_clap_error,
3727        value_hint = ValueHint::Other,
3728    )]
3729    pub extra: Option<Vec<ExtraName>>,
3730
3731    /// Select the output format.
3732    #[arg(long, value_enum, default_value_t = SyncFormat::default())]
3733    pub output_format: SyncFormat,
3734
3735    /// Include all optional dependencies.
3736    ///
3737    /// When two or more extras are declared as conflicting in `tool.uv.conflicts`, using this flag
3738    /// will always result in an error.
3739    ///
3740    /// Note that all optional dependencies are always included in the resolution; this option only
3741    /// affects the selection of packages to install.
3742    #[arg(long, conflicts_with = "extra", conflicts_with = "only_group")]
3743    pub all_extras: bool,
3744
3745    /// Exclude the specified optional dependencies, if `--all-extras` is supplied.
3746    ///
3747    /// May be provided multiple times.
3748    #[arg(long, value_hint = ValueHint::Other)]
3749    pub no_extra: Vec<ExtraName>,
3750
3751    #[arg(long, overrides_with("all_extras"), hide = true)]
3752    pub no_all_extras: bool,
3753
3754    /// Include the development dependency group [env: UV_DEV=]
3755    ///
3756    /// This option is an alias for `--group dev`.
3757    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
3758    pub dev: bool,
3759
3760    /// Disable the development dependency group [env: UV_NO_DEV=]
3761    ///
3762    /// This option is an alias of `--no-group dev`.
3763    /// See `--no-default-groups` to disable all default groups instead.
3764    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
3765    pub no_dev: bool,
3766
3767    /// Only include the development dependency group.
3768    ///
3769    /// The project and its dependencies will be omitted.
3770    ///
3771    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
3772    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
3773    pub only_dev: bool,
3774
3775    /// Include dependencies from the specified dependency group.
3776    ///
3777    /// When multiple extras or groups are specified that appear in
3778    /// `tool.uv.conflicts`, uv will report an error.
3779    ///
3780    /// May be provided multiple times.
3781    #[arg(long, conflicts_with_all = ["only_group", "only_dev"], value_hint = ValueHint::Other)]
3782    pub group: Vec<GroupName>,
3783
3784    /// Disable the specified dependency group [env: `UV_NO_GROUP`=]
3785    ///
3786    /// This option always takes precedence over default groups,
3787    /// `--all-groups`, and `--group`.
3788    ///
3789    /// May be provided multiple times.
3790    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
3791    pub no_group: Vec<GroupName>,
3792
3793    /// Ignore the default dependency groups.
3794    ///
3795    /// uv includes the groups defined in `tool.uv.default-groups` by default.
3796    /// This disables that option, however, specific groups can still be included with `--group`.
3797    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
3798    pub no_default_groups: bool,
3799
3800    /// Only include dependencies from the specified dependency group.
3801    ///
3802    /// The project and its dependencies will be omitted.
3803    ///
3804    /// May be provided multiple times. Implies `--no-default-groups`.
3805    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
3806    pub only_group: Vec<GroupName>,
3807
3808    /// Include dependencies from all dependency groups.
3809    ///
3810    /// `--no-group` can be used to exclude specific groups.
3811    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
3812    pub all_groups: bool,
3813
3814    /// Install any non-editable dependencies, including the project and any workspace members, as
3815    /// editable.
3816    #[arg(long, overrides_with = "no_editable", hide = true)]
3817    pub editable: bool,
3818
3819    /// Install any editable dependencies, including the project and any workspace members, as
3820    /// non-editable [env: UV_NO_EDITABLE=]
3821    #[arg(long, overrides_with = "editable", value_parser = clap::builder::BoolishValueParser::new())]
3822    pub no_editable: bool,
3823
3824    /// Install the specified editable packages as non-editable.
3825    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
3826    pub no_editable_package: Vec<PackageName>,
3827
3828    /// Do not remove extraneous packages present in the environment.
3829    ///
3830    /// When enabled, uv will make the minimum necessary changes to satisfy the requirements.
3831    /// By default, syncing will remove any extraneous packages from the environment
3832    #[arg(long, overrides_with("exact"), alias = "no-exact")]
3833    pub inexact: bool,
3834
3835    /// Perform an exact sync, removing extraneous packages.
3836    #[arg(long, overrides_with("inexact"), hide = true)]
3837    pub exact: bool,
3838
3839    /// Sync dependencies to the active virtual environment.
3840    ///
3841    /// Instead of creating or updating the virtual environment for the project or script, the
3842    /// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
3843    /// set.
3844    #[arg(long, overrides_with = "no_active")]
3845    pub active: bool,
3846
3847    /// Prefer project's virtual environment over an active environment.
3848    ///
3849    /// This is the default behavior.
3850    #[arg(long, overrides_with = "active", hide = true)]
3851    pub no_active: bool,
3852
3853    /// Do not install the current project [env: UV_NO_INSTALL_PROJECT=]
3854    ///
3855    /// By default, the current project is installed into the environment with all of its
3856    /// dependencies. The `--no-install-project` option allows the project to be excluded, but all
3857    /// of its dependencies are still installed. This is particularly useful in situations like
3858    /// building Docker images where installing the project separately from its dependencies allows
3859    /// optimal layer caching.
3860    ///
3861    /// The inverse `--only-install-project` can be used to install _only_ the project itself,
3862    /// excluding all dependencies.
3863    #[arg(long, conflicts_with = "only_install_project")]
3864    pub no_install_project: bool,
3865
3866    /// Only install the current project.
3867    #[arg(long, conflicts_with = "no_install_project", hide = true)]
3868    pub only_install_project: bool,
3869
3870    /// Do not install any workspace members, including the root project [env: UV_NO_INSTALL_WORKSPACE=]
3871    ///
3872    /// By default, all workspace members and their dependencies are installed into the
3873    /// environment. The `--no-install-workspace` option allows exclusion of all the workspace
3874    /// members while retaining their dependencies. This is particularly useful in situations like
3875    /// building Docker images where installing the workspace separately from its dependencies
3876    /// allows optimal layer caching.
3877    ///
3878    /// The inverse `--only-install-workspace` can be used to install _only_ workspace members,
3879    /// excluding all other dependencies.
3880    #[arg(long, conflicts_with = "only_install_workspace")]
3881    pub no_install_workspace: bool,
3882
3883    /// Only install workspace members, including the root project.
3884    #[arg(long, conflicts_with = "no_install_workspace", hide = true)]
3885    pub only_install_workspace: bool,
3886
3887    /// Do not install local path dependencies [env: UV_NO_INSTALL_LOCAL=]
3888    ///
3889    /// Skips the current project, workspace members, and any other local (path or editable)
3890    /// packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache
3891    /// heavy third-party dependencies first and layer local packages separately.
3892    ///
3893    /// The inverse `--only-install-local` can be used to install _only_ local packages, excluding
3894    /// all remote dependencies.
3895    #[arg(long, conflicts_with = "only_install_local")]
3896    pub no_install_local: bool,
3897
3898    /// Only install local path dependencies
3899    #[arg(long, conflicts_with = "no_install_local", hide = true)]
3900    pub only_install_local: bool,
3901
3902    /// Do not install the given package(s).
3903    ///
3904    /// By default, all of the project's dependencies are installed into the environment. The
3905    /// `--no-install-package` option allows exclusion of specific packages. Note this can result
3906    /// in a broken environment, and should be used with caution.
3907    ///
3908    /// The inverse `--only-install-package` can be used to install _only_ the specified packages,
3909    /// excluding all others.
3910    #[arg(long, conflicts_with = "only_install_package", value_hint = ValueHint::Other)]
3911    pub no_install_package: Vec<PackageName>,
3912
3913    /// Only install the given package(s).
3914    #[arg(long, conflicts_with = "no_install_package", hide = true, value_hint = ValueHint::Other)]
3915    pub only_install_package: Vec<PackageName>,
3916
3917    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
3918    ///
3919    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
3920    /// uv will exit with an error.
3921    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
3922    pub locked: bool,
3923
3924    /// Sync without updating the `uv.lock` file [env: UV_FROZEN=]
3925    ///
3926    /// Instead of checking if the lockfile is up-to-date, uses the versions in the lockfile as the
3927    /// source of truth. If the lockfile is missing, uv will exit with an error. If the
3928    /// `pyproject.toml` includes changes to dependencies that have not been included in the
3929    /// lockfile yet, they will not be present in the environment.
3930    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
3931    pub frozen: bool,
3932
3933    /// Perform a dry run, without writing the lockfile or modifying the project environment.
3934    ///
3935    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
3936    /// changes to both the lockfile and the project environment, but will not modify either.
3937    #[arg(long)]
3938    pub dry_run: bool,
3939
3940    #[command(flatten)]
3941    pub installer: ResolverInstallerArgs,
3942
3943    #[command(flatten)]
3944    pub build: BuildOptionsArgs,
3945
3946    #[command(flatten)]
3947    pub refresh: RefreshArgs,
3948
3949    /// Sync all packages in the workspace.
3950    ///
3951    /// The workspace's environment (`.venv`) is updated to include all workspace members.
3952    ///
3953    /// Any extras or groups specified via `--extra`, `--group`, or related options will be applied
3954    /// to all workspace members.
3955    #[arg(long, conflicts_with = "package")]
3956    pub all_packages: bool,
3957
3958    /// Sync for specific packages in the workspace.
3959    ///
3960    /// The workspace's environment (`.venv`) is updated to reflect the subset of dependencies
3961    /// declared by the specified workspace member packages.
3962    ///
3963    /// If any workspace member does not exist, uv will exit with an error.
3964    #[arg(long, conflicts_with = "all_packages", value_hint = ValueHint::Other)]
3965    pub package: Vec<PackageName>,
3966
3967    /// Sync the environment for a Python script, rather than the current project.
3968    ///
3969    /// If provided, uv will sync the dependencies based on the script's inline metadata table, in
3970    /// adherence with PEP 723.
3971    #[arg(
3972        long,
3973        conflicts_with = "all_packages",
3974        conflicts_with = "package",
3975        conflicts_with = "no_install_project",
3976        conflicts_with = "no_install_workspace",
3977        conflicts_with = "no_install_local",
3978        conflicts_with = "extra",
3979        conflicts_with = "all_extras",
3980        conflicts_with = "no_extra",
3981        conflicts_with = "no_all_extras",
3982        conflicts_with = "dev",
3983        conflicts_with = "no_dev",
3984        conflicts_with = "only_dev",
3985        conflicts_with = "group",
3986        conflicts_with = "no_group",
3987        conflicts_with = "no_default_groups",
3988        conflicts_with = "only_group",
3989        conflicts_with = "all_groups",
3990        value_hint = ValueHint::FilePath,
3991    )]
3992    pub script: Option<PathBuf>,
3993
3994    /// The Python interpreter to use for the project environment.
3995    ///
3996    /// By default, the first interpreter that meets the project's `requires-python` constraint is
3997    /// used.
3998    ///
3999    /// If a Python interpreter in a virtual environment is provided, the packages will not be
4000    /// synced to the given environment. The interpreter will be used to create a virtual
4001    /// environment in the project.
4002    ///
4003    /// See `uv help python` for details on Python discovery and supported request formats.
4004    #[arg(
4005        long,
4006        short,
4007        env = EnvVars::UV_PYTHON,
4008        verbatim_doc_comment,
4009        help_heading = "Python options",
4010        value_parser = parse_maybe_string,
4011        value_hint = ValueHint::Other,
4012    )]
4013    pub python: Option<Maybe<String>>,
4014
4015    /// The platform for which requirements should be installed.
4016    ///
4017    /// Represented as a "target triple", a string that describes the target platform in terms of
4018    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
4019    /// `aarch64-apple-darwin`.
4020    ///
4021    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
4022    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
4023    ///
4024    /// When targeting iOS, the default minimum version is `13.0`. Use
4025    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
4026    ///
4027    /// When targeting Android, the default minimum Android API level is `24`. Use
4028    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
4029    ///
4030    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
4031    /// platform; as a result, the installed distributions may not be compatible with the _current_
4032    /// platform. Conversely, any distributions that are built from source may be incompatible with
4033    /// the _target_ platform, as they will be built for the _current_ platform. The
4034    /// `--python-platform` option is intended for advanced use cases.
4035    #[arg(long)]
4036    pub python_platform: Option<TargetTriple>,
4037
4038    /// Check if the Python environment is synchronized with the project.
4039    ///
4040    /// If the environment is not up to date, uv will exit with an error.
4041    #[arg(long, overrides_with("no_check"))]
4042    pub check: bool,
4043
4044    #[arg(long, overrides_with("check"), hide = true)]
4045    pub no_check: bool,
4046}
4047
4048#[derive(Args)]
4049pub struct LockArgs {
4050    /// Check if the lockfile is up-to-date.
4051    ///
4052    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
4053    /// missing or needs to be updated, uv will exit with an error.
4054    ///
4055    /// Equivalent to `--locked`.
4056    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), conflicts_with_all = ["check_exists", "upgrade"], overrides_with = "check")]
4057    pub check: bool,
4058
4059    /// Check if the lockfile is up-to-date [env: UV_LOCKED=]
4060    ///
4061    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
4062    /// missing or needs to be updated, uv will exit with an error.
4063    ///
4064    /// Equivalent to `--check`.
4065    #[arg(long, conflicts_with_all = ["check_exists", "upgrade"], hide = true)]
4066    pub locked: bool,
4067
4068    /// Assert that a `uv.lock` exists without checking if it is up-to-date [env: UV_FROZEN=]
4069    ///
4070    /// Equivalent to `--frozen`.
4071    #[arg(long, alias = "frozen", conflicts_with_all = ["check", "locked"])]
4072    pub check_exists: bool,
4073
4074    /// Perform a dry run, without writing the lockfile.
4075    ///
4076    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
4077    /// changes, but will not write the lockfile to disk.
4078    #[arg(
4079        long,
4080        conflicts_with = "check_exists",
4081        conflicts_with = "check",
4082        conflicts_with = "locked"
4083    )]
4084    pub dry_run: bool,
4085
4086    /// Lock the specified Python script, rather than the current project.
4087    ///
4088    /// If provided, uv will lock the script (based on its inline metadata table, in adherence with
4089    /// PEP 723) to a `.lock` file adjacent to the script itself.
4090    #[arg(long, value_hint = ValueHint::FilePath)]
4091    pub script: Option<PathBuf>,
4092
4093    #[command(flatten)]
4094    pub resolver: ResolverArgs,
4095
4096    #[command(flatten)]
4097    pub build: BuildOptionsArgs,
4098
4099    #[command(flatten)]
4100    pub refresh: RefreshArgs,
4101
4102    /// The Python interpreter to use during resolution.
4103    ///
4104    /// A Python interpreter is required for building source distributions to determine package
4105    /// metadata when there are not wheels.
4106    ///
4107    /// The interpreter is also used as the fallback value for the minimum Python version if
4108    /// `requires-python` is not set.
4109    ///
4110    /// See `uv help python` for details on Python discovery and supported request formats.
4111    #[arg(
4112        long,
4113        short,
4114        env = EnvVars::UV_PYTHON,
4115        verbatim_doc_comment,
4116        help_heading = "Python options",
4117        value_parser = parse_maybe_string,
4118        value_hint = ValueHint::Other,
4119    )]
4120    pub python: Option<Maybe<String>>,
4121}
4122
4123#[derive(Args)]
4124pub struct UpgradeArgs {
4125    /// The packages to upgrade.
4126    #[arg(value_hint = ValueHint::Other)]
4127    pub packages: Vec<PackageName>,
4128
4129    /// Exclude the named package from upgrades.
4130    #[arg(long, value_hint = ValueHint::Other)]
4131    pub exclude: Vec<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    /// If a minor version is requested, all matching installed patch versions are reinstalled.
6438    ///
6439    /// By default, uv will exit successfully if the version is already
6440    /// installed.
6441    #[arg(long, short)]
6442    pub reinstall: bool,
6443
6444    /// Replace existing Python executables during installation.
6445    ///
6446    /// By default, uv will refuse to replace executables that it does not manage.
6447    ///
6448    /// Implies `--reinstall`.
6449    #[arg(long, short)]
6450    pub force: bool,
6451
6452    /// Upgrade existing Python installations to the latest patch version.
6453    ///
6454    /// By default, uv will not upgrade already-installed Python versions to newer patch releases.
6455    /// With `--upgrade`, uv will upgrade to the latest available patch version for the specified
6456    /// minor version(s).
6457    ///
6458    /// If the requested versions are not yet installed, uv will install them.
6459    ///
6460    /// This option is only supported for minor version requests, e.g., `3.12`; uv will exit with an
6461    /// error if a patch version, e.g., `3.12.2`, is requested.
6462    #[arg(long, short = 'U')]
6463    pub upgrade: bool,
6464
6465    /// Use as the default Python version.
6466    ///
6467    /// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
6468    /// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
6469    /// also installed.
6470    ///
6471    /// Alternative Python variants will still include their tag. For example, installing
6472    /// 3.13+freethreaded with `--default` will include `python3t` and `pythont` instead of
6473    /// `python3` and `python`.
6474    ///
6475    /// If multiple Python versions are requested, uv will exit with an error.
6476    #[arg(long, conflicts_with("no_bin"))]
6477    pub default: bool,
6478
6479    #[command(flatten)]
6480    pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6481}
6482
6483impl PythonInstallArgs {
6484    #[must_use]
6485    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6486        PythonInstallMirrors {
6487            python_install_mirror: self.mirror.clone(),
6488            pypy_install_mirror: self.pypy_mirror.clone(),
6489            python_downloads_json_url: self.python_downloads_json_url.clone(),
6490        }
6491    }
6492}
6493
6494#[derive(Args)]
6495pub struct PythonUpgradeArgs {
6496    /// The directory Python installations are stored in.
6497    ///
6498    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6499    /// discover the Python installation.
6500    ///
6501    /// See `uv python dir` to view the current Python installation directory. Defaults to
6502    /// `~/.local/share/uv/python`.
6503    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6504    pub install_dir: Option<PathBuf>,
6505
6506    /// The Python minor version(s) to upgrade.
6507    ///
6508    /// If no target version is provided, then uv will upgrade all managed CPython versions.
6509    #[arg(env = EnvVars::UV_PYTHON)]
6510    pub targets: Vec<String>,
6511
6512    /// Set the URL to use as the source for downloading Python installations.
6513    ///
6514    /// The provided URL will replace
6515    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6516    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6517    ///
6518    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6519    #[arg(long, value_hint = ValueHint::Url)]
6520    pub mirror: Option<String>,
6521
6522    /// Set the URL to use as the source for downloading PyPy installations.
6523    ///
6524    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6525    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6526    ///
6527    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6528    #[arg(long, value_hint = ValueHint::Url)]
6529    pub pypy_mirror: Option<String>,
6530
6531    /// Reinstall the latest Python patch, if it's already installed.
6532    ///
6533    /// By default, uv will exit successfully if the latest patch is already
6534    /// installed.
6535    #[arg(long, short)]
6536    pub reinstall: bool,
6537
6538    /// URL pointing to JSON of custom Python installations.
6539    #[arg(long, value_hint = ValueHint::Other)]
6540    pub python_downloads_json_url: Option<String>,
6541
6542    #[command(flatten)]
6543    pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6544}
6545
6546impl PythonUpgradeArgs {
6547    #[must_use]
6548    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6549        PythonInstallMirrors {
6550            python_install_mirror: self.mirror.clone(),
6551            pypy_install_mirror: self.pypy_mirror.clone(),
6552            python_downloads_json_url: self.python_downloads_json_url.clone(),
6553        }
6554    }
6555}
6556
6557#[derive(Args)]
6558pub struct PythonUninstallArgs {
6559    /// The directory where the Python was installed.
6560    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6561    pub install_dir: Option<PathBuf>,
6562
6563    /// The Python version(s) to uninstall.
6564    ///
6565    /// See `uv help python` to view supported request formats.
6566    #[arg(required = true)]
6567    pub targets: Vec<String>,
6568
6569    /// Uninstall all managed Python versions.
6570    #[arg(long, conflicts_with("targets"))]
6571    pub all: bool,
6572}
6573
6574#[derive(Args)]
6575pub struct PythonFindArgs {
6576    /// The Python request.
6577    ///
6578    /// See `uv help python` to view supported request formats.
6579    pub request: Option<String>,
6580
6581    /// Avoid discovering a project or workspace.
6582    ///
6583    /// Otherwise, when no request is provided, the Python requirement of a project in the current
6584    /// directory or parent directories will be used.
6585    #[arg(
6586        long,
6587        alias = "no_workspace",
6588        env = EnvVars::UV_NO_PROJECT,
6589        value_parser = clap::builder::BoolishValueParser::new()
6590    )]
6591    pub no_project: bool,
6592
6593    /// Only find system Python interpreters.
6594    ///
6595    /// By default, uv will report the first Python interpreter it would use, including those in an
6596    /// active virtual environment or a virtual environment in the current working directory or any
6597    /// parent directory.
6598    ///
6599    /// The `--system` option instructs uv to skip virtual environment Python interpreters and
6600    /// restrict its search to the system path.
6601    #[arg(
6602        long,
6603        env = EnvVars::UV_SYSTEM_PYTHON,
6604        value_parser = clap::builder::BoolishValueParser::new(),
6605        overrides_with("no_system")
6606    )]
6607    pub system: bool,
6608
6609    #[arg(long, overrides_with("system"), hide = true)]
6610    pub no_system: bool,
6611
6612    /// Find the environment for a Python script, rather than the current project.
6613    #[arg(
6614        long,
6615        conflicts_with = "request",
6616        conflicts_with = "no_project",
6617        conflicts_with = "system",
6618        conflicts_with = "no_system",
6619        value_hint = ValueHint::FilePath,
6620    )]
6621    pub script: Option<PathBuf>,
6622
6623    /// Show the Python version that would be used instead of the path to the interpreter.
6624    #[arg(long)]
6625    pub show_version: bool,
6626
6627    /// Resolve symlinks in the output path.
6628    ///
6629    /// When enabled, the output path will be canonicalized, resolving any symlinks.
6630    #[arg(long)]
6631    pub resolve_links: bool,
6632
6633    /// URL pointing to JSON of custom Python installations.
6634    #[arg(long, value_hint = ValueHint::Other)]
6635    pub python_downloads_json_url: Option<String>,
6636}
6637
6638#[derive(Args)]
6639pub struct PythonPinArgs {
6640    /// The Python version request.
6641    ///
6642    /// uv supports more formats than other tools that read `.python-version` files, i.e., `pyenv`.
6643    /// If compatibility with those tools is needed, only use version numbers instead of complex
6644    /// requests such as `cpython@3.10`.
6645    ///
6646    /// If no request is provided, the currently pinned version will be shown.
6647    ///
6648    /// See `uv help python` to view supported request formats.
6649    pub request: Option<String>,
6650
6651    /// Write the resolved Python interpreter path instead of the request.
6652    ///
6653    /// Ensures that the exact same interpreter is used.
6654    ///
6655    /// This option is usually not safe to use when committing the `.python-version` file to version
6656    /// control.
6657    #[arg(long, overrides_with("resolved"))]
6658    pub resolved: bool,
6659
6660    #[arg(long, overrides_with("no_resolved"), hide = true)]
6661    pub no_resolved: bool,
6662
6663    /// Avoid validating the Python pin is compatible with the project or workspace.
6664    ///
6665    /// By default, a project or workspace is discovered in the current directory or any parent
6666    /// directory. If a workspace is found, the Python pin is validated against the workspace's
6667    /// `requires-python` constraint.
6668    #[arg(
6669        long,
6670        alias = "no-workspace",
6671        env = EnvVars::UV_NO_PROJECT,
6672        value_parser = clap::builder::BoolishValueParser::new()
6673    )]
6674    pub no_project: bool,
6675
6676    /// Update the global Python version pin.
6677    ///
6678    /// Writes the pinned Python version to a `.python-version` file in the uv user configuration
6679    /// directory: `XDG_CONFIG_HOME/uv` on Linux/macOS and `%APPDATA%/uv` on Windows.
6680    ///
6681    /// When a local Python version pin is not found in the working directory or an ancestor
6682    /// directory, this version will be used instead.
6683    #[arg(long)]
6684    pub global: bool,
6685
6686    /// Remove the Python version pin.
6687    #[arg(long, conflicts_with = "request", conflicts_with = "resolved")]
6688    pub rm: bool,
6689
6690    /// URL pointing to JSON of custom Python installations.
6691    #[arg(long, value_hint = ValueHint::Other)]
6692    pub python_downloads_json_url: Option<String>,
6693}
6694
6695#[derive(Args)]
6696pub struct AuthLogoutArgs {
6697    /// The domain or URL of the service to logout from.
6698    pub service: Service,
6699
6700    /// The username to logout.
6701    #[arg(long, short, value_hint = ValueHint::Other)]
6702    pub username: Option<String>,
6703
6704    /// The keyring provider to use for storage of credentials.
6705    ///
6706    /// Only `--keyring-provider native` is supported for `logout`, which uses the system keyring
6707    /// via an integration built into uv.
6708    #[arg(
6709        long,
6710        value_enum,
6711        env = EnvVars::UV_KEYRING_PROVIDER,
6712    )]
6713    pub keyring_provider: Option<KeyringProviderType>,
6714}
6715
6716#[derive(Args)]
6717pub struct AuthLoginArgs {
6718    /// The domain or URL of the service to log into.
6719    #[arg(value_hint = ValueHint::Url)]
6720    pub service: Service,
6721
6722    /// The username to use for the service.
6723    #[arg(long, short, conflicts_with = "token", value_hint = ValueHint::Other)]
6724    pub username: Option<String>,
6725
6726    /// The password to use for the service.
6727    ///
6728    /// Use `-` to read the password from stdin.
6729    #[arg(long, conflicts_with = "token", value_hint = ValueHint::Other)]
6730    pub password: Option<String>,
6731
6732    /// The token to use for the service.
6733    ///
6734    /// The username will be set to `__token__`.
6735    ///
6736    /// Use `-` to read the token from stdin.
6737    #[arg(long, short, conflicts_with = "username", conflicts_with = "password", value_hint = ValueHint::Other)]
6738    pub token: Option<String>,
6739
6740    /// The keyring provider to use for storage of credentials.
6741    ///
6742    /// Only `--keyring-provider native` is supported for `login`, which uses the system keyring via
6743    /// an integration built into uv.
6744    #[arg(
6745        long,
6746        value_enum,
6747        env = EnvVars::UV_KEYRING_PROVIDER,
6748    )]
6749    pub keyring_provider: Option<KeyringProviderType>,
6750}
6751
6752#[derive(Args)]
6753pub struct AuthTokenArgs {
6754    /// The domain or URL of the service to lookup.
6755    #[arg(value_hint = ValueHint::Url)]
6756    pub service: Service,
6757
6758    /// The username to lookup.
6759    #[arg(long, short, value_hint = ValueHint::Other)]
6760    pub username: Option<String>,
6761
6762    /// The keyring provider to use for reading credentials.
6763    #[arg(
6764        long,
6765        value_enum,
6766        env = EnvVars::UV_KEYRING_PROVIDER,
6767    )]
6768    pub keyring_provider: Option<KeyringProviderType>,
6769}
6770
6771#[derive(Args)]
6772pub struct AuthDirArgs {
6773    /// The domain or URL of the service to lookup.
6774    #[arg(value_hint = ValueHint::Url)]
6775    pub service: Option<Service>,
6776}
6777
6778#[derive(Args)]
6779pub struct AuthHelperArgs {
6780    #[command(subcommand)]
6781    pub command: AuthHelperCommand,
6782
6783    /// The credential helper protocol to use
6784    #[arg(long, value_enum, required = true)]
6785    pub protocol: AuthHelperProtocol,
6786}
6787
6788/// Credential helper protocols supported by uv
6789#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
6790pub enum AuthHelperProtocol {
6791    /// Bazel credential helper protocol as described in [the
6792    /// spec](https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md)
6793    Bazel,
6794}
6795
6796#[derive(Subcommand)]
6797pub enum AuthHelperCommand {
6798    /// Retrieve credentials for a URI
6799    Get,
6800}
6801
6802#[derive(Args)]
6803pub struct GenerateShellCompletionArgs {
6804    /// The shell to generate the completion script for
6805    pub shell: clap_complete_command::Shell,
6806
6807    // Hide unused global options.
6808    #[arg(long, short, hide = true)]
6809    pub no_cache: bool,
6810    #[arg(long, hide = true)]
6811    pub cache_dir: Option<PathBuf>,
6812
6813    #[arg(long, hide = true)]
6814    pub python_preference: Option<PythonPreference>,
6815    #[arg(long, hide = true)]
6816    pub no_python_downloads: bool,
6817
6818    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
6819    pub quiet: u8,
6820    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
6821    pub verbose: u8,
6822    #[arg(long, conflicts_with = "no_color", hide = true)]
6823    pub color: Option<ColorChoice>,
6824    #[arg(long, hide = true)]
6825    pub native_tls: bool,
6826    #[arg(long, hide = true)]
6827    pub offline: bool,
6828    #[arg(long, hide = true)]
6829    pub no_progress: bool,
6830    #[arg(long, hide = true)]
6831    pub config_file: Option<PathBuf>,
6832    #[arg(long, hide = true)]
6833    pub no_config: bool,
6834    #[arg(long, short, action = clap::ArgAction::HelpShort, hide = true)]
6835    pub help: Option<bool>,
6836    #[arg(short = 'V', long, hide = true)]
6837    pub version: bool,
6838}
6839
6840#[derive(Args)]
6841pub struct IndexArgs {
6842    /// The URLs to use when resolving dependencies, in addition to the default index.
6843    ///
6844    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6845    /// directory laid out in the same format.
6846    ///
6847    /// All indexes provided via this flag take priority over the index specified by
6848    /// `--default-index` (which defaults to PyPI). When multiple `--index` flags are provided,
6849    /// earlier values take priority.
6850    ///
6851    /// Index names are not supported as values. Relative paths must be disambiguated from index
6852    /// names with `./` or `../` on Unix or `.\\`, `..\\`, `./` or `../` on Windows.
6853    //
6854    // The nested Vec structure (`Vec<Vec<Maybe<Index>>>`) is required for clap's
6855    // value parsing mechanism, which processes one value at a time, in order to handle
6856    // `UV_INDEX` the same way pip handles `PIP_EXTRA_INDEX_URL`.
6857    #[arg(
6858        long,
6859        env = EnvVars::UV_INDEX,
6860        hide_env_values = true,
6861        value_parser = parse_indices,
6862        help_heading = "Index options"
6863    )]
6864    pub index: Option<Vec<Vec<Maybe<Index>>>>,
6865
6866    /// The URL of the default package index (by default: <https://pypi.org/simple>).
6867    ///
6868    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6869    /// directory laid out in the same format.
6870    ///
6871    /// The index given by this flag is given lower priority than all other indexes specified via
6872    /// the `--index` flag.
6873    #[arg(
6874        long,
6875        env = EnvVars::UV_DEFAULT_INDEX,
6876        hide_env_values = true,
6877        value_parser = parse_default_index,
6878        help_heading = "Index options"
6879    )]
6880    pub default_index: Option<Maybe<Index>>,
6881
6882    /// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default:
6883    /// <https://pypi.org/simple>).
6884    ///
6885    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6886    /// directory laid out in the same format.
6887    ///
6888    /// The index given by this flag is given lower priority than all other indexes specified via
6889    /// the `--extra-index-url` flag.
6890    #[arg(
6891        long,
6892        short,
6893        env = EnvVars::UV_INDEX_URL,
6894        hide_env_values = true,
6895        value_parser = parse_index_url,
6896        help_heading = "Index options"
6897    )]
6898    pub index_url: Option<Maybe<PipIndex>>,
6899
6900    /// (Deprecated: use `--index` instead) Extra URLs of package indexes to use, in addition to
6901    /// `--index-url`.
6902    ///
6903    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6904    /// directory laid out in the same format.
6905    ///
6906    /// All indexes provided via this flag take priority over the index specified by `--index-url`
6907    /// (which defaults to PyPI). When multiple `--extra-index-url` flags are provided, earlier
6908    /// values take priority.
6909    #[arg(
6910        long,
6911        env = EnvVars::UV_EXTRA_INDEX_URL,
6912        hide_env_values = true,
6913        value_delimiter = ' ',
6914        value_parser = parse_extra_index_url,
6915        help_heading = "Index options"
6916    )]
6917    pub extra_index_url: Option<Vec<Maybe<PipExtraIndex>>>,
6918
6919    /// Locations to search for candidate distributions, in addition to those found in the registry
6920    /// indexes.
6921    ///
6922    /// If a path, the target must be a directory that contains packages as wheel files (`.whl`) or
6923    /// source distributions (e.g., `.tar.gz` or `.zip`) at the top level.
6924    ///
6925    /// If a URL, the page must contain a flat list of links to package files adhering to the
6926    /// formats described above.
6927    #[arg(
6928        long,
6929        short,
6930        env = EnvVars::UV_FIND_LINKS,
6931        hide_env_values = true,
6932        value_delimiter = ',',
6933        value_parser = parse_find_links,
6934        help_heading = "Index options"
6935    )]
6936    pub find_links: Option<Vec<Maybe<PipFindLinks>>>,
6937
6938    /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
6939    /// provided via `--find-links`.
6940    #[arg(long, help_heading = "Index options")]
6941    pub no_index: bool,
6942}
6943
6944/// Arguments that configure the package registry client.
6945#[derive(Args)]
6946#[group(skip)]
6947pub struct RegistryClientArgs {
6948    /// The strategy to use when resolving against multiple index URLs.
6949    ///
6950    /// By default, uv will stop at the first index on which a given package is available, and limit
6951    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6952    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6953    /// to an alternate index.
6954    #[arg(
6955        long,
6956        value_enum,
6957        env = EnvVars::UV_INDEX_STRATEGY,
6958        help_heading = "Index options"
6959    )]
6960    pub index_strategy: Option<IndexStrategy>,
6961
6962    /// Attempt to use `keyring` for authentication for index URLs.
6963    ///
6964    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6965    /// the `keyring` CLI to handle authentication.
6966    ///
6967    /// Defaults to `disabled`.
6968    #[arg(
6969        long,
6970        value_enum,
6971        env = EnvVars::UV_KEYRING_PROVIDER,
6972        help_heading = "Index options"
6973    )]
6974    pub keyring_provider: Option<KeyringProviderType>,
6975}
6976
6977/// Arguments that control dependency sources.
6978#[derive(Args)]
6979#[group(skip)]
6980pub struct SourcesArgs {
6981    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6982    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6983    /// URL, or local path sources.
6984    #[arg(
6985        long,
6986        env = EnvVars::UV_NO_SOURCES,
6987        value_parser = clap::builder::BoolishValueParser::new(),
6988        help_heading = "Resolver options",
6989    )]
6990    no_sources: bool,
6991
6992    /// Don't use sources from the `tool.uv.sources` table for the specified packages [env: `UV_NO_SOURCES_PACKAGE`=]
6993    #[arg(long, help_heading = "Resolver options", value_delimiter = ' ')]
6994    no_sources_package: Vec<PackageName>,
6995}
6996
6997/// Arguments that configure package version selection.
6998#[derive(Args)]
6999#[group(skip)]
7000pub struct VersionSelectionArgs {
7001    /// The strategy to use when selecting between the different compatible versions for a given
7002    /// package requirement.
7003    ///
7004    /// By default, uv will use the latest compatible version of each package (`highest`).
7005    #[arg(
7006        long,
7007        value_enum,
7008        env = EnvVars::UV_RESOLUTION,
7009        help_heading = "Resolver options"
7010    )]
7011    resolution: Option<ResolutionMode>,
7012
7013    /// The strategy to use when considering pre-release versions.
7014    ///
7015    /// By default, uv will prefer stable candidates, falling back to pre-releases only after every
7016    /// stable candidate that satisfies the active constraints is rejected
7017    /// (`if-necessary`).
7018    #[arg(
7019        long,
7020        value_enum,
7021        env = EnvVars::UV_PRERELEASE,
7022        help_heading = "Resolver options"
7023    )]
7024    prerelease: Option<PrereleaseMode>,
7025
7026    #[arg(long, hide = true, help_heading = "Resolver options")]
7027    pre: bool,
7028
7029    /// The strategy to use when selecting multiple versions of a given package across Python
7030    /// versions and platforms.
7031    ///
7032    /// By default, uv will optimize for selecting the latest version of each package for each
7033    /// supported Python version (`requires-python`), while minimizing the number of selected
7034    /// versions across platforms.
7035    ///
7036    /// Under `fewest`, uv will minimize the number of selected versions for each package,
7037    /// preferring older versions that are compatible with a wider range of supported Python
7038    /// versions or platforms.
7039    #[arg(
7040        long,
7041        value_enum,
7042        env = EnvVars::UV_FORK_STRATEGY,
7043        help_heading = "Resolver options"
7044    )]
7045    fork_strategy: Option<ForkStrategy>,
7046}
7047
7048/// Arguments that configure requirement hash checking.
7049#[derive(Args)]
7050#[group(skip)]
7051pub struct HashCheckingArgs {
7052    /// Require a matching hash for each requirement.
7053    ///
7054    /// By default, uv will verify any available hashes in the requirements file, but will not
7055    /// require that all requirements have an associated hash.
7056    ///
7057    /// When `--require-hashes` is enabled, _all_ requirements must include a hash or set of hashes,
7058    /// and _all_ requirements must either be pinned to exact versions (e.g., `==1.0.0`), or be
7059    /// specified via direct URL.
7060    ///
7061    /// Hash-checking mode introduces a number of additional constraints:
7062    ///
7063    /// - Git dependencies are not supported.
7064    /// - Editable installations are not supported.
7065    /// - Local dependencies are not supported, unless they point to a specific wheel (`.whl`) or
7066    ///   source archive (`.zip`, `.tar.gz`), as opposed to a directory.
7067    #[arg(
7068        long,
7069        env = EnvVars::UV_REQUIRE_HASHES,
7070        value_parser = clap::builder::BoolishValueParser::new(),
7071        overrides_with("no_require_hashes"),
7072    )]
7073    pub require_hashes: bool,
7074
7075    #[arg(long, overrides_with("require_hashes"), hide = true)]
7076    pub no_require_hashes: bool,
7077
7078    #[arg(long, overrides_with("no_verify_hashes"), hide = true)]
7079    pub verify_hashes: bool,
7080
7081    /// Disable validation of hashes in the requirements file.
7082    ///
7083    /// By default, uv will verify any available hashes in the requirements file, but will not
7084    /// require that all requirements have an associated hash. To enforce hash validation, use
7085    /// `--require-hashes`.
7086    #[arg(
7087        long,
7088        env = EnvVars::UV_NO_VERIFY_HASHES,
7089        value_parser = clap::builder::BoolishValueParser::new(),
7090        overrides_with("verify_hashes"),
7091    )]
7092    pub no_verify_hashes: bool,
7093}
7094
7095/// Arguments that filter packages by upload date.
7096#[derive(Args)]
7097#[group(skip)]
7098pub struct ExcludeNewerArgs {
7099    /// Limit candidate packages to those that were uploaded prior to the given date.
7100    ///
7101    /// The date is compared against the upload time of each individual distribution artifact
7102    /// (i.e., when each file was uploaded to the package index), not the release date of the
7103    /// package version.
7104    ///
7105    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7106    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7107    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7108    /// `P7D`, `P30D`).
7109    ///
7110    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7111    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7112    /// Calendar units such as months and years are not allowed.
7113    ///
7114    /// Use `false` to disable `exclude-newer`.
7115    #[arg(
7116        long,
7117        env = EnvVars::UV_EXCLUDE_NEWER,
7118        help_heading = "Resolver options",
7119        value_hint = ValueHint::Other,
7120    )]
7121    pub exclude_newer: Option<ExcludeNewerOverride>,
7122}
7123
7124/// Arguments that filter packages by global and package-specific upload dates.
7125#[derive(Args)]
7126#[group(skip)]
7127pub struct PackageExcludeNewerArgs {
7128    #[command(flatten)]
7129    pub exclude_newer: ExcludeNewerArgs,
7130
7131    /// Limit candidate packages for specific packages to those that were uploaded prior to the
7132    /// given date.
7133    ///
7134    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7135    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7136    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7137    /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7138    /// `P30D`).
7139    ///
7140    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7141    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7142    /// Calendar units such as months and years are not allowed.
7143    ///
7144    /// Can be provided multiple times for different packages.
7145    #[arg(long, help_heading = "Resolver options", value_hint = ValueHint::Other)]
7146    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7147}
7148
7149#[derive(Args)]
7150pub struct RefreshArgs {
7151    /// Refresh all cached data.
7152    #[arg(long, overrides_with("no_refresh"), help_heading = "Cache options")]
7153    refresh: bool,
7154
7155    #[arg(
7156        long,
7157        overrides_with("refresh"),
7158        hide = true,
7159        help_heading = "Cache options"
7160    )]
7161    no_refresh: bool,
7162
7163    /// Refresh cached data for a specific package.
7164    #[arg(long, help_heading = "Cache options", value_hint = ValueHint::Other)]
7165    refresh_package: Vec<PackageName>,
7166}
7167
7168#[derive(Args)]
7169pub struct BuildOptionsArgs {
7170    /// Don't build source distributions.
7171    ///
7172    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
7173    /// operations that require building a source distribution will exit with an error. uv may
7174    /// still build editable requirements, and their build backends may run arbitrary Python code.
7175    #[arg(
7176        long,
7177        env = EnvVars::UV_NO_BUILD,
7178        overrides_with("build"),
7179        value_parser = clap::builder::BoolishValueParser::new(),
7180        help_heading = "Build options",
7181    )]
7182    no_build: bool,
7183
7184    #[arg(
7185        long,
7186        overrides_with("no_build"),
7187        hide = true,
7188        help_heading = "Build options"
7189    )]
7190    build: bool,
7191
7192    /// Don't build source distributions for a specific package [env: `UV_NO_BUILD_PACKAGE`=]
7193    #[arg(
7194        long,
7195        help_heading = "Build options",
7196        value_delimiter = ' ',
7197        value_hint = ValueHint::Other,
7198    )]
7199    no_build_package: Vec<PackageName>,
7200
7201    /// Don't install pre-built wheels.
7202    ///
7203    /// The given packages will be built and installed from source. The resolver will still use
7204    /// pre-built wheels to extract package metadata, if available.
7205    #[arg(
7206        long,
7207        env = EnvVars::UV_NO_BINARY,
7208        overrides_with("binary"),
7209        value_parser = clap::builder::BoolishValueParser::new(),
7210        help_heading = "Build options"
7211    )]
7212    no_binary: bool,
7213
7214    #[arg(
7215        long,
7216        overrides_with("no_binary"),
7217        hide = true,
7218        help_heading = "Build options"
7219    )]
7220    binary: bool,
7221
7222    /// Don't install pre-built wheels for a specific package [env: `UV_NO_BINARY_PACKAGE`=]
7223    #[arg(
7224        long,
7225        help_heading = "Build options",
7226        value_delimiter = ' ',
7227        value_hint = ValueHint::Other,
7228    )]
7229    no_binary_package: Vec<PackageName>,
7230}
7231
7232/// Arguments that configure build isolation for source distributions.
7233#[derive(Args)]
7234#[group(skip)]
7235pub struct BuildIsolationArgs {
7236    /// Disable isolation when building source distributions.
7237    ///
7238    /// Assumes that build dependencies specified by PEP 518 are already installed.
7239    #[arg(
7240        long,
7241        overrides_with("build_isolation"),
7242        help_heading = "Build options",
7243        env = EnvVars::UV_NO_BUILD_ISOLATION,
7244        value_parser = clap::builder::BoolishValueParser::new(),
7245    )]
7246    no_build_isolation: bool,
7247
7248    #[arg(
7249        long,
7250        overrides_with("no_build_isolation"),
7251        hide = true,
7252        help_heading = "Build options"
7253    )]
7254    build_isolation: bool,
7255}
7256
7257/// Arguments that configure global and package-specific build isolation.
7258#[derive(Args)]
7259#[group(skip)]
7260pub struct PackageBuildIsolationArgs {
7261    #[command(flatten)]
7262    build_isolation: BuildIsolationArgs,
7263
7264    /// Disable isolation when building source distributions for a specific package.
7265    ///
7266    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7267    #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7268    no_build_isolation_package: Vec<PackageName>,
7269}
7270
7271#[derive(Args)]
7272#[group(skip)]
7273pub struct ReinstallArgs {
7274    /// Reinstall all packages, regardless of whether they're already installed. Implies
7275    /// `--refresh`.
7276    #[arg(
7277        long,
7278        alias = "force-reinstall",
7279        overrides_with("no_reinstall"),
7280        help_heading = "Installer options"
7281    )]
7282    pub reinstall: bool,
7283
7284    #[arg(
7285        long,
7286        overrides_with("reinstall"),
7287        hide = true,
7288        help_heading = "Installer options"
7289    )]
7290    pub no_reinstall: bool,
7291
7292    /// Reinstall a specific package, regardless of whether it's already installed. Implies
7293    /// `--refresh-package`.
7294    #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7295    pub reinstall_package: Vec<PackageName>,
7296}
7297
7298#[derive(Args)]
7299#[group(skip)]
7300pub struct CompileBytecodeArgs {
7301    /// Compile Python files to bytecode after installation.
7302    ///
7303    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7304    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7305    /// in which start time is critical, such as CLI applications and Docker containers, this option
7306    /// can be enabled to trade longer installation times for faster start times.
7307    ///
7308    /// When enabled, install operations (e.g., `uv pip install`) will compile installed or
7309    /// reinstalled Python files. Commands that perform a sync operation (e.g., `uv sync` or `uv
7310    /// run`) will process the entire site-packages directory including packages that are not being
7311    /// modified.
7312    #[arg(
7313        long,
7314        alias = "compile",
7315        overrides_with("no_compile_bytecode"),
7316        help_heading = "Installer options",
7317        env = EnvVars::UV_COMPILE_BYTECODE,
7318        value_parser = clap::builder::BoolishValueParser::new(),
7319    )]
7320    compile_bytecode: bool,
7321
7322    #[arg(
7323        long,
7324        alias = "no-compile",
7325        overrides_with("compile_bytecode"),
7326        hide = true,
7327        help_heading = "Installer options"
7328    )]
7329    no_compile_bytecode: bool,
7330}
7331
7332/// Arguments that are used by commands that need to install (but not resolve) packages.
7333#[derive(Args)]
7334pub struct InstallerArgs {
7335    #[command(flatten)]
7336    index_args: IndexArgs,
7337
7338    #[command(flatten)]
7339    reinstall: ReinstallArgs,
7340
7341    #[command(flatten)]
7342    registry_client: RegistryClientArgs,
7343
7344    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7345    #[arg(
7346        long,
7347        short = 'C',
7348        alias = "config-settings",
7349        help_heading = "Build options"
7350    )]
7351    config_setting: Option<Vec<ConfigSettingEntry>>,
7352
7353    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7354    #[arg(
7355        long,
7356        alias = "config-settings-package",
7357        help_heading = "Build options"
7358    )]
7359    config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7360
7361    #[command(flatten)]
7362    build_isolation: BuildIsolationArgs,
7363
7364    #[command(flatten)]
7365    exclude_newer: PackageExcludeNewerArgs,
7366
7367    /// The method to use when installing packages from the global cache.
7368    ///
7369    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7370    /// Windows.
7371    ///
7372    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7373    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7374    /// will break all installed packages by way of removing the underlying source files. Use
7375    /// symlinks with caution.
7376    #[arg(
7377        long,
7378        value_enum,
7379        env = EnvVars::UV_LINK_MODE,
7380        help_heading = "Installer options"
7381    )]
7382    link_mode: Option<uv_install_wheel::LinkMode>,
7383
7384    #[command(flatten)]
7385    compile_bytecode: CompileBytecodeArgs,
7386
7387    #[command(flatten)]
7388    sources: SourcesArgs,
7389}
7390
7391/// Arguments that are used by commands that need to resolve (but not install) packages.
7392#[derive(Args)]
7393pub struct ResolverArgs {
7394    #[command(flatten)]
7395    index_args: IndexArgs,
7396
7397    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7398    /// `--refresh`.
7399    #[arg(
7400        long,
7401        short = 'U',
7402        overrides_with("no_upgrade"),
7403        help_heading = "Resolver options"
7404    )]
7405    upgrade: bool,
7406
7407    #[arg(
7408        long,
7409        overrides_with("upgrade"),
7410        hide = true,
7411        help_heading = "Resolver options"
7412    )]
7413    no_upgrade: bool,
7414
7415    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
7416    /// file. Implies `--refresh-package`.
7417    #[arg(long, short = 'P', help_heading = "Resolver options")]
7418    upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7419
7420    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7421    /// existing output file.
7422    #[arg(long, help_heading = "Resolver options")]
7423    upgrade_group: Vec<GroupName>,
7424
7425    #[command(flatten)]
7426    registry_client: RegistryClientArgs,
7427
7428    #[command(flatten)]
7429    version_selection: VersionSelectionArgs,
7430
7431    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7432    #[arg(
7433        long,
7434        short = 'C',
7435        alias = "config-settings",
7436        help_heading = "Build options"
7437    )]
7438    config_setting: Option<Vec<ConfigSettingEntry>>,
7439
7440    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7441    #[arg(
7442        long,
7443        alias = "config-settings-package",
7444        help_heading = "Build options"
7445    )]
7446    config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7447
7448    #[command(flatten)]
7449    build_isolation: PackageBuildIsolationArgs,
7450
7451    #[command(flatten)]
7452    exclude_newer: PackageExcludeNewerArgs,
7453
7454    /// The method to use when installing packages from the global cache.
7455    ///
7456    /// This option is only used when building source distributions.
7457    ///
7458    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7459    /// Windows.
7460    ///
7461    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7462    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7463    /// will break all installed packages by way of removing the underlying source files. Use
7464    /// symlinks with caution.
7465    #[arg(
7466        long,
7467        value_enum,
7468        env = EnvVars::UV_LINK_MODE,
7469        help_heading = "Installer options"
7470    )]
7471    link_mode: Option<uv_install_wheel::LinkMode>,
7472
7473    #[command(flatten)]
7474    sources: SourcesArgs,
7475}
7476
7477/// Arguments that are used by commands that need to resolve and install packages.
7478#[derive(Args)]
7479pub struct ResolverInstallerArgs {
7480    #[command(flatten)]
7481    pub index_args: IndexArgs,
7482
7483    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7484    /// `--refresh`.
7485    #[arg(
7486        long,
7487        short = 'U',
7488        overrides_with("no_upgrade"),
7489        help_heading = "Resolver options"
7490    )]
7491    pub upgrade: bool,
7492
7493    #[arg(
7494        long,
7495        overrides_with("upgrade"),
7496        hide = true,
7497        help_heading = "Resolver options"
7498    )]
7499    pub no_upgrade: bool,
7500
7501    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output file.
7502    /// Implies `--refresh-package`.
7503    #[arg(long, short = 'P', help_heading = "Resolver options", value_hint = ValueHint::Other)]
7504    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7505
7506    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7507    /// existing output file.
7508    #[arg(long, help_heading = "Resolver options")]
7509    pub upgrade_group: Vec<GroupName>,
7510
7511    #[command(flatten)]
7512    pub reinstall: ReinstallArgs,
7513
7514    #[command(flatten)]
7515    pub registry_client: RegistryClientArgs,
7516
7517    #[command(flatten)]
7518    pub version_selection: VersionSelectionArgs,
7519
7520    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7521    #[arg(
7522        long,
7523        short = 'C',
7524        alias = "config-settings",
7525        help_heading = "Build options",
7526        value_hint = ValueHint::Other,
7527    )]
7528    pub config_setting: Option<Vec<ConfigSettingEntry>>,
7529
7530    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7531    #[arg(
7532        long,
7533        alias = "config-settings-package",
7534        help_heading = "Build options",
7535        value_hint = ValueHint::Other,
7536    )]
7537    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7538
7539    #[command(flatten)]
7540    pub build_isolation: PackageBuildIsolationArgs,
7541
7542    #[command(flatten)]
7543    pub exclude_newer: PackageExcludeNewerArgs,
7544
7545    /// The method to use when installing packages from the global cache.
7546    ///
7547    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7548    /// Windows.
7549    ///
7550    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7551    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7552    /// will break all installed packages by way of removing the underlying source files. Use
7553    /// symlinks with caution.
7554    #[arg(
7555        long,
7556        value_enum,
7557        env = EnvVars::UV_LINK_MODE,
7558        help_heading = "Installer options"
7559    )]
7560    pub link_mode: Option<uv_install_wheel::LinkMode>,
7561
7562    #[command(flatten)]
7563    pub compile_bytecode: CompileBytecodeArgs,
7564
7565    #[command(flatten)]
7566    pub sources: SourcesArgs,
7567}
7568
7569/// Arguments that are used by commands that need to fetch from the Simple API.
7570#[derive(Args)]
7571pub struct FetchArgs {
7572    #[command(flatten)]
7573    index_args: IndexArgs,
7574
7575    #[command(flatten)]
7576    registry_client: RegistryClientArgs,
7577
7578    #[command(flatten)]
7579    exclude_newer: PackageExcludeNewerArgs,
7580}
7581
7582#[derive(Args)]
7583pub struct DisplayTreeArgs {
7584    /// Maximum display depth of the dependency tree
7585    #[arg(long, short, default_value_t = 255)]
7586    pub depth: u8,
7587
7588    /// Prune the given package from the display of the dependency tree.
7589    #[arg(long, value_hint = ValueHint::Other)]
7590    pub prune: Vec<PackageName>,
7591
7592    /// Display only the specified packages.
7593    #[arg(long, value_hint = ValueHint::Other)]
7594    pub package: Vec<PackageName>,
7595
7596    /// Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its
7597    /// dependencies, further occurrences will not re-display its dependencies, and will include a
7598    /// (*) to indicate it has already been shown. This flag will cause those duplicates to be
7599    /// repeated.
7600    #[arg(long)]
7601    pub no_dedupe: bool,
7602
7603    /// Show the reverse dependencies for the given package. This flag will invert the tree and
7604    /// display the packages that depend on the given package.
7605    #[arg(long, alias = "reverse")]
7606    pub invert: bool,
7607
7608    /// Show the latest available version of each package in the tree.
7609    #[arg(long)]
7610    pub outdated: bool,
7611
7612    /// Show compressed wheel sizes for packages in the tree.
7613    #[arg(long)]
7614    pub show_sizes: bool,
7615}
7616
7617#[derive(Args, Debug)]
7618pub struct PublishArgs {
7619    /// Paths to the files to upload. Accepts glob expressions.
7620    ///
7621    /// Defaults to the `dist` directory. Selects only wheels and source distributions
7622    /// and their attestations, while ignoring other files.
7623    #[arg(default_value = "dist/*", value_hint = ValueHint::FilePath)]
7624    pub files: Vec<String>,
7625
7626    /// The name of an index in the configuration to use for publishing.
7627    ///
7628    /// The index must have a `publish-url` setting, for example:
7629    ///
7630    /// ```toml
7631    /// [[tool.uv.index]]
7632    /// name = "pypi"
7633    /// url = "https://pypi.org/simple"
7634    /// publish-url = "https://upload.pypi.org/legacy/"
7635    /// ```
7636    ///
7637    /// The index `url` will be used to check for existing files to skip duplicate uploads.
7638    ///
7639    /// With these settings, the following two calls are equivalent:
7640    ///
7641    /// ```shell
7642    /// uv publish --index pypi
7643    /// uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pypi.org/simple
7644    /// ```
7645    #[arg(
7646        long,
7647        verbatim_doc_comment,
7648        env = EnvVars::UV_PUBLISH_INDEX,
7649        conflicts_with = "publish_url",
7650        conflicts_with = "check_url",
7651        value_hint = ValueHint::Other,
7652    )]
7653    pub index: Option<String>,
7654
7655    /// The username for the upload.
7656    #[arg(
7657        short,
7658        long,
7659        env = EnvVars::UV_PUBLISH_USERNAME,
7660        hide_env_values = true,
7661        value_hint = ValueHint::Other
7662    )]
7663    pub username: Option<String>,
7664
7665    /// The password for the upload.
7666    #[arg(
7667        short,
7668        long,
7669        env = EnvVars::UV_PUBLISH_PASSWORD,
7670        hide_env_values = true,
7671        value_hint = ValueHint::Other
7672    )]
7673    pub password: Option<String>,
7674
7675    /// The token for the upload.
7676    ///
7677    /// Using a token is equivalent to passing `__token__` as `--username` and the token as
7678    /// `--password` password.
7679    #[arg(
7680        short,
7681        long,
7682        env = EnvVars::UV_PUBLISH_TOKEN,
7683        hide_env_values = true,
7684        conflicts_with = "username",
7685        conflicts_with = "password",
7686        value_hint = ValueHint::Other,
7687    )]
7688    pub token: Option<String>,
7689
7690    /// Configure trusted publishing.
7691    ///
7692    /// By default, uv checks for trusted publishing when running in a supported environment, but
7693    /// ignores it if it isn't configured.
7694    ///
7695    /// uv's supported environments for trusted publishing include GitHub Actions and GitLab CI/CD.
7696    #[arg(long)]
7697    pub trusted_publishing: Option<TrustedPublishing>,
7698
7699    /// Attempt to use `keyring` for authentication for remote requirements files.
7700    ///
7701    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7702    /// the `keyring` CLI to handle authentication.
7703    ///
7704    /// Defaults to `disabled`.
7705    #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
7706    pub keyring_provider: Option<KeyringProviderType>,
7707
7708    /// The URL of the upload endpoint (not the index URL).
7709    ///
7710    /// Note that there are typically different URLs for index access (e.g., `https:://.../simple`)
7711    /// and index upload.
7712    ///
7713    /// Defaults to PyPI's publish URL (<https://upload.pypi.org/legacy/>).
7714    #[arg(long, env = EnvVars::UV_PUBLISH_URL, hide_env_values = true)]
7715    pub publish_url: Option<DisplaySafeUrl>,
7716
7717    /// Check an index URL for existing files to skip duplicate uploads.
7718    ///
7719    /// This option allows retrying publishing that failed after only some, but not all files have
7720    /// been uploaded, and handles errors due to parallel uploads of the same file.
7721    ///
7722    /// Before uploading, the index is checked. If the exact same file already exists in the index,
7723    /// the file will not be uploaded. If an error occurred during the upload, the index is checked
7724    /// again, to handle cases where the identical file was uploaded twice in parallel.
7725    ///
7726    /// The exact behavior will vary based on the index. When uploading to PyPI, uploading the same
7727    /// file succeeds even without `--check-url`, while most other indexes error. When uploading to
7728    /// pyx, the index URL can be inferred automatically from the publish URL.
7729    ///
7730    /// The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).
7731    #[arg(long, env = EnvVars::UV_PUBLISH_CHECK_URL, hide_env_values = true)]
7732    pub check_url: Option<IndexUrl>,
7733
7734    #[arg(long, hide = true)]
7735    pub skip_existing: bool,
7736
7737    /// Perform a dry run without uploading files.
7738    ///
7739    /// When enabled, the command will check for existing files if `--check-url` is provided,
7740    /// and will perform validation against the index if supported, but will not upload any files.
7741    #[arg(long)]
7742    pub dry_run: bool,
7743
7744    /// Do not upload attestations for the published files.
7745    ///
7746    /// By default, uv attempts to upload matching PEP 740 attestations with each distribution
7747    /// that is published.
7748    #[arg(long, env = EnvVars::UV_PUBLISH_NO_ATTESTATIONS)]
7749    pub no_attestations: bool,
7750
7751    /// Use direct upload to the registry.
7752    ///
7753    /// When enabled, the publish command will use a direct two-phase upload protocol
7754    /// that uploads files directly to storage, bypassing the registry's upload endpoint.
7755    #[arg(long, hide = true)]
7756    pub direct: bool,
7757}
7758
7759#[derive(Args)]
7760pub struct WorkspaceNamespace {
7761    #[command(subcommand)]
7762    pub command: WorkspaceCommand,
7763}
7764
7765#[derive(Subcommand)]
7766pub enum WorkspaceCommand {
7767    /// View metadata about the current workspace.
7768    ///
7769    /// The output of this command is not yet stable.
7770    Metadata(Box<MetadataArgs>),
7771    /// Display the path of a workspace member.
7772    ///
7773    /// By default, the path to the workspace root directory is displayed.
7774    /// The `--package` option can be used to display the path to a workspace member instead.
7775    ///
7776    /// If used outside of a workspace, i.e., if a `pyproject.toml` cannot be found, uv will exit with an error.
7777    Dir(WorkspaceDirArgs),
7778    /// List the members of a workspace.
7779    ///
7780    /// Displays newline separated names of workspace members.
7781    List(WorkspaceListArgs),
7782}
7783#[derive(Args)]
7784pub struct MetadataArgs {
7785    /// View metadata for the specified PEP 723 Python script, rather than the current workspace.
7786    ///
7787    /// If provided, uv will resolve the dependencies based on the script's inline metadata table,
7788    /// in adherence with PEP 723.
7789    #[arg(long, value_hint = ValueHint::FilePath)]
7790    pub script: Option<PathBuf>,
7791
7792    /// Check if the lockfile is up-to-date [env: UV_LOCKED=]
7793    ///
7794    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
7795    /// missing or needs to be updated, uv will exit with an error.
7796    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
7797    pub locked: bool,
7798
7799    /// Assert that a `uv.lock` exists without checking if it is up-to-date [env: UV_FROZEN=]
7800    #[arg(long, conflicts_with_all = ["locked"])]
7801    pub frozen: bool,
7802
7803    /// Perform a dry run, without writing the lockfile.
7804    ///
7805    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
7806    /// changes, but will not write the lockfile to disk.
7807    #[arg(
7808        long,
7809        conflicts_with = "frozen",
7810        conflicts_with = "locked",
7811        conflicts_with = "sync"
7812    )]
7813    pub dry_run: bool,
7814
7815    #[command(flatten)]
7816    pub resolver: ResolverArgs,
7817
7818    #[command(flatten)]
7819    pub build: BuildOptionsArgs,
7820
7821    #[command(flatten)]
7822    pub refresh: RefreshArgs,
7823
7824    /// Sync the environment to include module ownership metadata in the output.
7825    ///
7826    /// This adds a mapping from importable module names to references to the package nodes
7827    /// that provide them. To do this, the venv will be synced in inexact mode.
7828    #[arg(long)]
7829    pub sync: bool,
7830
7831    /// Sync dependencies to the active virtual environment.
7832    ///
7833    /// Instead of creating or updating the virtual environment for the project or script, the
7834    /// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
7835    /// set.
7836    #[arg(long)]
7837    pub active: bool,
7838
7839    /// The Python interpreter to use during resolution.
7840    ///
7841    /// A Python interpreter is required for building source distributions to determine package
7842    /// metadata when there are not wheels.
7843    ///
7844    /// The interpreter is also used as the fallback value for the minimum Python version if
7845    /// `requires-python` is not set.
7846    ///
7847    /// See `uv help python` for details on Python discovery and supported request formats.
7848    #[arg(
7849        long,
7850        short,
7851        env = EnvVars::UV_PYTHON,
7852        verbatim_doc_comment,
7853        help_heading = "Python options",
7854        value_parser = parse_maybe_string,
7855        value_hint = ValueHint::Other,
7856    )]
7857    pub python: Option<Maybe<String>>,
7858}
7859
7860#[derive(Args, Debug)]
7861pub struct WorkspaceDirArgs {
7862    /// Display the path to a specific package in the workspace.
7863    #[arg(long, value_hint = ValueHint::Other)]
7864    pub package: Option<PackageName>,
7865}
7866
7867#[derive(Args, Debug)]
7868pub struct WorkspaceListArgs {
7869    /// Show paths instead of names.
7870    #[arg(long)]
7871    pub paths: bool,
7872
7873    /// List all standalone scripts with inline metadata in the workspace.
7874    #[arg(long)]
7875    pub scripts: bool,
7876}
7877
7878/// See [PEP 517](https://peps.python.org/pep-0517/) and
7879/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.
7880#[derive(Subcommand)]
7881pub enum BuildBackendCommand {
7882    /// PEP 517 hook `build_sdist`.
7883    BuildSdist { sdist_directory: PathBuf },
7884    /// PEP 517 hook `build_wheel`.
7885    BuildWheel {
7886        wheel_directory: PathBuf,
7887        #[arg(long)]
7888        metadata_directory: Option<PathBuf>,
7889    },
7890    /// PEP 660 hook `build_editable`.
7891    BuildEditable {
7892        wheel_directory: PathBuf,
7893        #[arg(long)]
7894        metadata_directory: Option<PathBuf>,
7895    },
7896    /// PEP 517 hook `get_requires_for_build_sdist`.
7897    GetRequiresForBuildSdist,
7898    /// PEP 517 hook `get_requires_for_build_wheel`.
7899    GetRequiresForBuildWheel,
7900    /// PEP 517 hook `prepare_metadata_for_build_wheel`.
7901    PrepareMetadataForBuildWheel { wheel_directory: PathBuf },
7902    /// PEP 660 hook `get_requires_for_build_editable`.
7903    GetRequiresForBuildEditable,
7904    /// PEP 660 hook `prepare_metadata_for_build_editable`.
7905    PrepareMetadataForBuildEditable { wheel_directory: PathBuf },
7906}