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