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)]
5039#[group(skip)]
5040pub struct AuditCommonArgs {
5041    /// Select the output format.
5042    #[arg(long, value_enum, default_value_t = AuditOutputFormat::default())]
5043    pub output_format: AuditOutputFormat,
5044
5045    /// Ignore a vulnerability by ID.
5046    ///
5047    /// Vulnerabilities matching any of the provided IDs (including aliases) will be excluded from
5048    /// the audit results.
5049    ///
5050    /// May be provided multiple times.
5051    #[arg(long)]
5052    pub ignore: Vec<String>,
5053
5054    /// Ignore a vulnerability by ID, but only while no fix is available.
5055    ///
5056    /// Vulnerabilities matching any of the provided IDs (including aliases) will be excluded from
5057    /// the audit results as long as they have no known fix versions. Once a fix version becomes
5058    /// available, the vulnerability will be reported again.
5059    ///
5060    /// May be provided multiple times.
5061    #[arg(long)]
5062    pub ignore_until_fixed: Vec<String>,
5063
5064    /// The service format to use for vulnerability lookups.
5065    ///
5066    /// Each service format has a default URL, which can be
5067    /// changed with `--service-url`. The defaults are:
5068    ///
5069    /// * OSV: <https://api.osv.dev/>
5070    #[arg(long, value_enum, default_value = "osv")]
5071    pub service_format: VulnerabilityServiceFormat,
5072
5073    /// The URL to vulnerability service API endpoint.
5074    ///
5075    /// If not provided, the default URL for the selected service will be used.
5076    ///
5077    /// The service needs to use the OSV protocol, unless a different
5078    /// format was requested by `--service-format`.
5079    #[arg(long, value_hint = ValueHint::Url)]
5080    pub service_url: Option<DisplaySafeUrl>,
5081}
5082
5083#[derive(Args)]
5084pub struct AuditArgs {
5085    /// Don't audit the specified optional dependencies.
5086    ///
5087    /// May be provided multiple times.
5088    #[arg(long, value_hint = ValueHint::Other)]
5089    pub no_extra: Vec<ExtraName>,
5090
5091    /// Don't audit the development dependency group [env: UV_NO_DEV=]
5092    ///
5093    /// This option is an alias of `--no-group dev`.
5094    /// See `--no-default-groups` to exclude all default groups instead.
5095    ///
5096    /// This option is only available when running in a project.
5097    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5098    pub no_dev: bool,
5099
5100    /// Don't audit the specified dependency group [env: `UV_NO_GROUP`=]
5101    ///
5102    /// May be provided multiple times.
5103    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
5104    pub no_group: Vec<GroupName>,
5105
5106    /// Don't audit the default dependency groups.
5107    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
5108    pub no_default_groups: bool,
5109
5110    /// Only audit dependencies from the specified dependency group.
5111    ///
5112    /// The project and its dependencies will be omitted.
5113    ///
5114    /// May be provided multiple times. Implies `--no-default-groups`.
5115    #[arg(long, value_hint = ValueHint::Other)]
5116    pub only_group: Vec<GroupName>,
5117
5118    /// Only audit the development dependency group.
5119    ///
5120    /// The project and its dependencies will be omitted.
5121    ///
5122    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
5123    #[arg(long, conflicts_with_all = ["no_dev"])]
5124    pub only_dev: bool,
5125
5126    /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
5127    ///
5128    /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
5129    /// uv will exit with an error.
5130    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
5131    pub locked: bool,
5132
5133    /// Audit the requirements without locking the project [env: UV_FROZEN=]
5134    ///
5135    /// If the lockfile is missing, uv will exit with an error.
5136    #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
5137    pub frozen: bool,
5138
5139    #[command(flatten)]
5140    pub audit: AuditCommonArgs,
5141
5142    #[command(flatten)]
5143    pub build: BuildOptionsArgs,
5144
5145    #[command(flatten)]
5146    pub resolver: ResolverArgs,
5147
5148    /// Audit the specified PEP 723 Python script, rather than the current
5149    /// project.
5150    ///
5151    /// The specified script must be locked, i.e. with `uv lock --script <script>`
5152    /// before it can be audited.
5153    #[arg(long, value_hint = ValueHint::FilePath)]
5154    pub script: Option<PathBuf>,
5155
5156    /// The Python version to use when auditing.
5157    ///
5158    /// For example, pass `--python-version 3.10` to audit the dependencies that would be included
5159    /// when installing on Python 3.10.
5160    ///
5161    /// Defaults to the version of the discovered Python interpreter.
5162    #[arg(long)]
5163    pub python_version: Option<PythonVersion>,
5164
5165    /// The platform to use when auditing.
5166    ///
5167    /// For example, pass `--platform windows` to audit the dependencies that would be included
5168    /// when installing on Windows.
5169    ///
5170    /// Represented as a "target triple", a string that describes the target platform in terms of
5171    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5172    /// `aarch64-apple-darwin`.
5173    #[arg(long)]
5174    pub python_platform: Option<TargetTriple>,
5175}
5176
5177#[derive(Args)]
5178pub struct AuthNamespace {
5179    #[command(subcommand)]
5180    pub command: AuthCommand,
5181}
5182
5183#[derive(Subcommand)]
5184pub enum AuthCommand {
5185    /// Login to a service
5186    Login(AuthLoginArgs),
5187    /// Logout of a service
5188    Logout(AuthLogoutArgs),
5189    /// Show the authentication token for a service
5190    Token(AuthTokenArgs),
5191    /// Show the path to the uv credentials directory.
5192    ///
5193    /// By default, credentials are stored in the uv data directory at
5194    /// `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and
5195    /// `%APPDATA%\uv\data\credentials` on Windows.
5196    ///
5197    /// The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`.
5198    ///
5199    /// Credentials are only stored in this directory when the plaintext backend is used, as
5200    /// opposed to the native backend, which uses the system keyring.
5201    Dir(AuthDirArgs),
5202    /// Act as a credential helper for external tools.
5203    ///
5204    /// Implements the Bazel credential helper protocol to provide credentials
5205    /// to external tools via JSON over stdin/stdout.
5206    ///
5207    /// This command is typically invoked by external tools.
5208    #[command(hide = true)]
5209    Helper(AuthHelperArgs),
5210}
5211
5212#[derive(Args)]
5213pub struct ToolNamespace {
5214    #[command(subcommand)]
5215    pub command: ToolCommand,
5216}
5217
5218#[derive(Subcommand)]
5219pub enum ToolCommand {
5220    /// Run a command provided by a Python package.
5221    ///
5222    /// By default, the package to install is assumed to match the command name.
5223    ///
5224    /// The name of the command can include an exact version in the format `<package>@<version>`,
5225    /// e.g., `uv tool run ruff@0.3.0`. If more complex version specification is desired or if the
5226    /// command is provided by a different package, use `--from`.
5227    ///
5228    /// `uvx` can be used to invoke Python, e.g., with `uvx python` or `uvx python@<version>`. A
5229    /// Python interpreter will be started in an isolated virtual environment.
5230    ///
5231    /// If the tool was previously installed, i.e., via `uv tool install`, the installed version
5232    /// will be used unless a version is requested or the `--isolated` flag is used.
5233    ///
5234    /// `uvx` is provided as a convenient alias for `uv tool run`, their behavior is identical.
5235    ///
5236    /// If no command is provided, the installed tools are displayed.
5237    ///
5238    /// Packages are installed into an ephemeral virtual environment in the uv cache directory.
5239    #[command(
5240        after_help = "Use `uvx` as a shortcut for `uv tool run`.\n\n\
5241        Use `uv help tool run` for more details.",
5242        after_long_help = ""
5243    )]
5244    Run(ToolRunArgs),
5245    /// Hidden alias for `uv tool run` for the `uvx` command
5246    #[command(
5247        hide = true,
5248        override_usage = "uvx [OPTIONS] [COMMAND]",
5249        about = "Run a command provided by a Python package.",
5250        after_help = "Use `uv help tool run` for more details.",
5251        after_long_help = "",
5252        display_name = "uvx",
5253        long_version = crate::version::uv_self_version()
5254    )]
5255    Uvx(UvxArgs),
5256    /// Install commands provided by a Python package.
5257    ///
5258    /// Packages are installed into an isolated virtual environment in the uv tools directory. The
5259    /// executables are linked the tool executable directory, which is determined according to the
5260    /// XDG standard and can be retrieved with `uv tool dir --bin`.
5261    ///
5262    /// If the tool was previously installed, the existing tool will generally be replaced.
5263    Install(ToolInstallArgs),
5264    /// Upgrade installed tools.
5265    ///
5266    /// If a tool was installed with version constraints, they will be respected on upgrade — to
5267    /// upgrade a tool beyond the originally provided constraints, use `uv tool install` again.
5268    ///
5269    /// If a tool was installed with specific settings, they will be respected on upgraded. For
5270    /// example, if `--prereleases allow` was provided during installation, it will continue to be
5271    /// respected in upgrades.
5272    #[command(alias = "update")]
5273    Upgrade(ToolUpgradeArgs),
5274    /// List installed tools.
5275    #[command(alias = "ls")]
5276    List(ToolListArgs),
5277    /// Audit installed tools and their dependencies.
5278    Audit(ToolAuditArgs),
5279    /// Uninstall a tool.
5280    Uninstall(ToolUninstallArgs),
5281    /// Ensure that the tool executable directory is on the `PATH`.
5282    ///
5283    /// If the tool executable directory is not present on the `PATH`, uv will attempt to add it to
5284    /// the relevant shell configuration files.
5285    ///
5286    /// If the shell configuration files already include a blurb to add the executable directory to
5287    /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5288    ///
5289    /// The tool executable directory is determined according to the XDG standard and can be
5290    /// retrieved with `uv tool dir --bin`.
5291    #[command(alias = "ensurepath")]
5292    UpdateShell,
5293    /// Show the path to the uv tools directory.
5294    ///
5295    /// The tools directory is used to store environments and metadata for installed tools.
5296    ///
5297    /// By default, tools are stored in the uv data directory at `$XDG_DATA_HOME/uv/tools` or
5298    /// `$HOME/.local/share/uv/tools` on Unix and `%APPDATA%\uv\data\tools` on Windows.
5299    ///
5300    /// The tool installation directory may be overridden with `$UV_TOOL_DIR`.
5301    ///
5302    /// To instead view the directory uv installs executables into, use the `--bin` flag.
5303    Dir(ToolDirArgs),
5304}
5305
5306#[derive(Args)]
5307pub struct ToolRunArgs {
5308    /// The command to run.
5309    ///
5310    /// WARNING: The documentation for [`Self::command`] is not included in help output
5311    #[command(subcommand)]
5312    pub command: Option<ExternalCommand>,
5313
5314    /// Use the given package to provide the command.
5315    ///
5316    /// By default, the package name is assumed to match the command name.
5317    #[arg(long, value_hint = ValueHint::Other)]
5318    pub from: Option<String>,
5319
5320    /// Run with the given packages installed.
5321    #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5322    pub with: Vec<comma::CommaSeparatedRequirements>,
5323
5324    /// Run with the given packages installed in editable mode
5325    ///
5326    /// When used in a project, these dependencies will be layered on top of the uv tool's
5327    /// environment in a separate, ephemeral environment. These dependencies are allowed to conflict
5328    /// with those specified.
5329    #[arg(long, value_hint = ValueHint::DirPath)]
5330    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5331
5332    /// Run with the packages listed in the given files.
5333    ///
5334    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5335    /// and `pylock.toml`.
5336    #[arg(
5337        long,
5338        value_delimiter = ',',
5339        value_parser = parse_maybe_file_path,
5340        value_hint = ValueHint::FilePath,
5341    )]
5342    pub with_requirements: Vec<Maybe<PathBuf>>,
5343
5344    /// Constrain versions using the given requirements files.
5345    ///
5346    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5347    /// requirement that's installed. However, including a package in a constraints file will _not_
5348    /// trigger the installation of that package.
5349    ///
5350    /// This is equivalent to pip's `--constraint` option.
5351    #[arg(
5352        long,
5353        short,
5354        alias = "constraint",
5355        env = EnvVars::UV_CONSTRAINT,
5356        value_delimiter = ' ',
5357        value_parser = parse_maybe_file_path,
5358        value_hint = ValueHint::FilePath,
5359    )]
5360    pub constraints: Vec<Maybe<PathBuf>>,
5361
5362    /// Constrain build dependencies using the given requirements files when building source
5363    /// distributions.
5364    ///
5365    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5366    /// requirement that's installed. However, including a package in a constraints file will _not_
5367    /// trigger the installation of that package.
5368    #[arg(
5369        long,
5370        short,
5371        alias = "build-constraint",
5372        env = EnvVars::UV_BUILD_CONSTRAINT,
5373        value_delimiter = ' ',
5374        value_parser = parse_maybe_file_path,
5375        value_hint = ValueHint::FilePath,
5376    )]
5377    pub build_constraints: Vec<Maybe<PathBuf>>,
5378
5379    /// Override versions using the given requirements files.
5380    ///
5381    /// Overrides files are `requirements.txt`-like files that force a specific version of a
5382    /// requirement to be installed, regardless of the requirements declared by any constituent
5383    /// package, and regardless of whether this would be considered an invalid resolution.
5384    ///
5385    /// While constraints are _additive_, in that they're combined with the requirements of the
5386    /// constituent packages, overrides are _absolute_, in that they completely replace the
5387    /// requirements of the constituent packages.
5388    #[arg(
5389        long,
5390        alias = "override",
5391        env = EnvVars::UV_OVERRIDE,
5392        value_delimiter = ' ',
5393        value_parser = parse_maybe_file_path,
5394        value_hint = ValueHint::FilePath,
5395    )]
5396    pub overrides: Vec<Maybe<PathBuf>>,
5397
5398    /// Run the tool in an isolated virtual environment, ignoring any already-installed tools [env:
5399    /// UV_ISOLATED=]
5400    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5401    pub isolated: bool,
5402
5403    /// Load environment variables from a `.env` file.
5404    ///
5405    /// Can be provided multiple times, with subsequent files overriding values defined in previous
5406    /// files.
5407    #[arg(long, value_delimiter = ' ', env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
5408    pub env_file: Vec<PathBuf>,
5409
5410    /// Avoid reading environment variables from a `.env` file [env: UV_NO_ENV_FILE=]
5411    #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5412    pub no_env_file: bool,
5413
5414    #[command(flatten)]
5415    pub installer: ResolverInstallerArgs,
5416
5417    #[command(flatten)]
5418    pub build: BuildOptionsArgs,
5419
5420    #[command(flatten)]
5421    pub refresh: RefreshArgs,
5422
5423    /// Whether to use Git LFS when adding a dependency from Git.
5424    #[arg(long)]
5425    pub lfs: bool,
5426
5427    /// The Python interpreter to use to build the run environment.
5428    ///
5429    /// See `uv help python` for details on Python discovery and supported request formats.
5430    #[arg(
5431        long,
5432        short,
5433        env = EnvVars::UV_PYTHON,
5434        verbatim_doc_comment,
5435        help_heading = "Python options",
5436        value_parser = parse_maybe_string,
5437        value_hint = ValueHint::Other,
5438    )]
5439    pub python: Option<Maybe<String>>,
5440
5441    /// Whether to show resolver and installer output from any environment modifications [env:
5442    /// UV_SHOW_RESOLUTION=]
5443    ///
5444    /// By default, environment modifications are omitted, but enabled under `--verbose`.
5445    #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
5446    pub show_resolution: bool,
5447
5448    /// The platform for which requirements should be installed.
5449    ///
5450    /// Represented as a "target triple", a string that describes the target platform in terms of
5451    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5452    /// `aarch64-apple-darwin`.
5453    ///
5454    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5455    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5456    ///
5457    /// When targeting iOS, the default minimum version is `13.0`. Use
5458    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5459    ///
5460    /// When targeting Android, the default minimum Android API level is `24`. Use
5461    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5462    ///
5463    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5464    /// platform; as a result, the installed distributions may not be compatible with the _current_
5465    /// platform. Conversely, any distributions that are built from source may be incompatible with
5466    /// the _target_ platform, as they will be built for the _current_ platform. The
5467    /// `--python-platform` option is intended for advanced use cases.
5468    #[arg(long)]
5469    pub python_platform: Option<TargetTriple>,
5470
5471    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5472    ///
5473    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5474    /// and will instead use the defined backend.
5475    ///
5476    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5477    /// uv will use the PyTorch index for CUDA 12.6.
5478    ///
5479    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5480    /// installed CUDA drivers.
5481    ///
5482    /// This option is in preview and may change in any future release.
5483    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5484    pub torch_backend: Option<TorchMode>,
5485
5486    #[arg(long, hide = true)]
5487    pub generate_shell_completion: Option<clap_complete_command::Shell>,
5488}
5489
5490#[derive(Args)]
5491pub struct UvxArgs {
5492    #[command(flatten)]
5493    pub tool_run: ToolRunArgs,
5494
5495    /// Display the uvx version.
5496    #[arg(short = 'V', long, action = clap::ArgAction::Version)]
5497    pub version: Option<bool>,
5498}
5499
5500#[derive(Args)]
5501pub struct ToolInstallArgs {
5502    /// The package to install commands from.
5503    #[arg(value_hint = ValueHint::Other)]
5504    pub package: String,
5505
5506    /// The package to install commands from.
5507    ///
5508    /// This option is provided for parity with `uv tool run`, but is redundant with `package`.
5509    #[arg(long, hide = true, value_hint = ValueHint::Other)]
5510    pub from: Option<String>,
5511
5512    /// Include the following additional requirements.
5513    #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5514    pub with: Vec<comma::CommaSeparatedRequirements>,
5515
5516    /// Run with the packages listed in the given files.
5517    ///
5518    /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5519    /// and `pylock.toml`.
5520    #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
5521    pub with_requirements: Vec<Maybe<PathBuf>>,
5522
5523    /// Install the target package in editable mode, such that changes in the package's source
5524    /// directory are reflected without reinstallation.
5525    #[arg(short, long)]
5526    pub editable: bool,
5527
5528    /// Include the given packages in editable mode.
5529    #[arg(long, value_hint = ValueHint::DirPath)]
5530    pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5531
5532    /// Install executables from the following packages.
5533    #[arg(long, value_hint = ValueHint::Other)]
5534    pub with_executables_from: Vec<comma::CommaSeparatedRequirements>,
5535
5536    /// Constrain versions using the given requirements files.
5537    ///
5538    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5539    /// requirement that's installed. However, including a package in a constraints file will _not_
5540    /// trigger the installation of that package.
5541    ///
5542    /// This is equivalent to pip's `--constraint` option.
5543    #[arg(
5544        long,
5545        short,
5546        alias = "constraint",
5547        env = EnvVars::UV_CONSTRAINT,
5548        value_delimiter = ' ',
5549        value_parser = parse_maybe_file_path,
5550        value_hint = ValueHint::FilePath,
5551    )]
5552    pub constraints: Vec<Maybe<PathBuf>>,
5553
5554    /// Override versions using the given requirements files.
5555    ///
5556    /// Overrides files are `requirements.txt`-like files that force a specific version of a
5557    /// requirement to be installed, regardless of the requirements declared by any constituent
5558    /// package, and regardless of whether this would be considered an invalid resolution.
5559    ///
5560    /// While constraints are _additive_, in that they're combined with the requirements of the
5561    /// constituent packages, overrides are _absolute_, in that they completely replace the
5562    /// requirements of the constituent packages.
5563    #[arg(
5564        long,
5565        alias = "override",
5566        env = EnvVars::UV_OVERRIDE,
5567        value_delimiter = ' ',
5568        value_parser = parse_maybe_file_path,
5569        value_hint = ValueHint::FilePath,
5570    )]
5571    pub overrides: Vec<Maybe<PathBuf>>,
5572
5573    /// Exclude packages from resolution using the given requirements files.
5574    ///
5575    /// Excludes files are `requirements.txt`-like files that specify packages to exclude
5576    /// from the resolution. When a package is excluded, it will be omitted from the
5577    /// dependency list entirely and its own dependencies will be ignored during the resolution
5578    /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
5579    /// any package listed in the provided file will be omitted from all resolved environments.
5580    #[arg(
5581        long,
5582        alias = "exclude",
5583        env = EnvVars::UV_EXCLUDE,
5584        value_delimiter = ' ',
5585        value_parser = parse_maybe_file_path,
5586        value_hint = ValueHint::FilePath,
5587    )]
5588    pub excludes: Vec<Maybe<PathBuf>>,
5589
5590    /// Constrain build dependencies using the given requirements files when building source
5591    /// distributions.
5592    ///
5593    /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5594    /// requirement that's installed. However, including a package in a constraints file will _not_
5595    /// trigger the installation of that package.
5596    #[arg(
5597        long,
5598        short,
5599        alias = "build-constraint",
5600        env = EnvVars::UV_BUILD_CONSTRAINT,
5601        value_delimiter = ' ',
5602        value_parser = parse_maybe_file_path,
5603        value_hint = ValueHint::FilePath,
5604    )]
5605    pub build_constraints: Vec<Maybe<PathBuf>>,
5606
5607    #[command(flatten)]
5608    pub installer: ResolverInstallerArgs,
5609
5610    #[command(flatten)]
5611    pub build: BuildOptionsArgs,
5612
5613    #[command(flatten)]
5614    pub refresh: RefreshArgs,
5615
5616    /// Force installation of the tool.
5617    ///
5618    /// Will recreate any existing environment for the tool and replace any existing entry points
5619    /// with the same name in the executable directory.
5620    #[arg(long)]
5621    pub force: bool,
5622
5623    /// Whether to use Git LFS when adding a dependency from Git.
5624    #[arg(long)]
5625    pub lfs: bool,
5626
5627    /// The Python interpreter to use to build the tool environment.
5628    ///
5629    /// See `uv help python` for details on Python discovery and supported request formats.
5630    #[arg(
5631        long,
5632        short,
5633        env = EnvVars::UV_PYTHON,
5634        verbatim_doc_comment,
5635        help_heading = "Python options",
5636        value_parser = parse_maybe_string,
5637        value_hint = ValueHint::Other,
5638    )]
5639    pub python: Option<Maybe<String>>,
5640
5641    /// The platform for which requirements should be installed.
5642    ///
5643    /// Represented as a "target triple", a string that describes the target platform in terms of
5644    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5645    /// `aarch64-apple-darwin`.
5646    ///
5647    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5648    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5649    ///
5650    /// When targeting iOS, the default minimum version is `13.0`. Use
5651    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5652    ///
5653    /// When targeting Android, the default minimum Android API level is `24`. Use
5654    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5655    ///
5656    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5657    /// platform; as a result, the installed distributions may not be compatible with the _current_
5658    /// platform. Conversely, any distributions that are built from source may be incompatible with
5659    /// the _target_ platform, as they will be built for the _current_ platform. The
5660    /// `--python-platform` option is intended for advanced use cases.
5661    #[arg(long)]
5662    pub python_platform: Option<TargetTriple>,
5663
5664    /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5665    ///
5666    /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5667    /// and will instead use the defined backend.
5668    ///
5669    /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5670    /// uv will use the PyTorch index for CUDA 12.6.
5671    ///
5672    /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5673    /// installed CUDA drivers.
5674    ///
5675    /// This option is in preview and may change in any future release.
5676    #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5677    pub torch_backend: Option<TorchMode>,
5678}
5679
5680#[derive(Args)]
5681pub struct ToolListArgs {
5682    /// Whether to display the path to each tool environment and installed executable.
5683    #[arg(long)]
5684    pub show_paths: bool,
5685
5686    /// Whether to display the version specifier(s) used to install each tool.
5687    #[arg(long)]
5688    pub show_version_specifiers: bool,
5689
5690    /// Whether to display the additional requirements installed with each tool.
5691    #[arg(long)]
5692    pub show_with: bool,
5693
5694    /// Whether to display the extra requirements installed with each tool.
5695    #[arg(long)]
5696    pub show_extras: bool,
5697
5698    /// Whether to display the Python version associated with each tool.
5699    #[arg(long)]
5700    pub show_python: bool,
5701
5702    /// List outdated tools.
5703    ///
5704    /// The latest version of each tool will be shown alongside the installed version. Up-to-date
5705    /// tools will be omitted from the output.
5706    #[arg(long, overrides_with("no_outdated"))]
5707    pub outdated: bool,
5708
5709    #[arg(long, overrides_with("outdated"), hide = true)]
5710    pub no_outdated: bool,
5711
5712    #[command(flatten)]
5713    pub exclude_newer: PackageExcludeNewerArgs,
5714
5715    // Hide unused global Python options.
5716    #[arg(long, hide = true)]
5717    pub python_preference: Option<PythonPreference>,
5718
5719    #[arg(long, hide = true)]
5720    pub no_python_downloads: bool,
5721}
5722
5723#[derive(Args)]
5724pub struct ToolAuditArgs {
5725    /// The names of the installed tools to audit.
5726    #[arg(required = true, value_hint = ValueHint::Other)]
5727    pub name: Vec<PackageName>,
5728
5729    /// Audit all installed tools.
5730    #[arg(long, conflicts_with("name"))]
5731    pub all: bool,
5732
5733    #[command(flatten)]
5734    pub audit: AuditCommonArgs,
5735}
5736
5737#[derive(Args)]
5738pub struct ToolDirArgs {
5739    /// Show the directory into which `uv tool` will install executables.
5740    ///
5741    /// By default, `uv tool dir` shows the directory into which the tool Python environments
5742    /// themselves are installed, rather than the directory containing the linked executables.
5743    ///
5744    /// The tool executable directory is determined according to the XDG standard and is derived
5745    /// from the following environment variables, in order of preference:
5746    ///
5747    /// - `$UV_TOOL_BIN_DIR`
5748    /// - `$XDG_BIN_HOME`
5749    /// - `$XDG_DATA_HOME/../bin`
5750    /// - `$HOME/.local/bin`
5751    #[arg(long, verbatim_doc_comment)]
5752    pub bin: bool,
5753}
5754
5755#[derive(Args)]
5756pub struct ToolUninstallArgs {
5757    /// The name of the tool to uninstall.
5758    #[arg(required = true, value_hint = ValueHint::Other)]
5759    pub name: Vec<PackageName>,
5760
5761    /// Uninstall all tools.
5762    #[arg(long, conflicts_with("name"))]
5763    pub all: bool,
5764}
5765
5766#[derive(Args)]
5767pub struct ToolUpgradeArgs {
5768    /// The name of the tool to upgrade, along with an optional version specifier.
5769    #[arg(required = true, value_hint = ValueHint::Other)]
5770    pub name: Vec<String>,
5771
5772    /// Upgrade all tools.
5773    #[arg(long, conflicts_with("name"))]
5774    pub all: bool,
5775
5776    /// Upgrade a tool, and specify it to use the given Python interpreter to build its environment.
5777    /// Use with `--all` to apply to all tools.
5778    ///
5779    /// See `uv help python` for details on Python discovery and supported request formats.
5780    #[arg(
5781        long,
5782        short,
5783        env = EnvVars::UV_PYTHON,
5784        verbatim_doc_comment,
5785        help_heading = "Python options",
5786        value_parser = parse_maybe_string,
5787        value_hint = ValueHint::Other,
5788    )]
5789    pub python: Option<Maybe<String>>,
5790
5791    /// The platform for which requirements should be installed.
5792    ///
5793    /// Represented as a "target triple", a string that describes the target platform in terms of
5794    /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5795    /// `aarch64-apple-darwin`.
5796    ///
5797    /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5798    /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5799    ///
5800    /// When targeting iOS, the default minimum version is `13.0`. Use
5801    /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5802    ///
5803    /// When targeting Android, the default minimum Android API level is `24`. Use
5804    /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5805    ///
5806    /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5807    /// platform; as a result, the installed distributions may not be compatible with the _current_
5808    /// platform. Conversely, any distributions that are built from source may be incompatible with
5809    /// the _target_ platform, as they will be built for the _current_ platform. The
5810    /// `--python-platform` option is intended for advanced use cases.
5811    #[arg(long)]
5812    pub python_platform: Option<TargetTriple>,
5813
5814    // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`,
5815    // `--upgrade-package`, and `--upgrade-group` options hidden, and the `--no-upgrade` option
5816    // removed.
5817    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
5818    /// `--refresh`.
5819    #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")]
5820    pub upgrade: bool,
5821
5822    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
5823    /// file. Implies `--refresh-package`.
5824    #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")]
5825    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
5826
5827    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
5828    /// existing output file.
5829    #[arg(hide = true, long, help_heading = "Resolver options")]
5830    pub upgrade_group: Vec<GroupName>,
5831
5832    #[command(flatten)]
5833    pub index_args: IndexArgs,
5834
5835    #[command(flatten)]
5836    pub reinstall: ReinstallArgs,
5837
5838    #[command(flatten)]
5839    pub registry_client: RegistryClientArgs,
5840
5841    #[command(flatten)]
5842    pub version_selection: VersionSelectionArgs,
5843
5844    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
5845    #[arg(
5846        long,
5847        short = 'C',
5848        alias = "config-settings",
5849        help_heading = "Build options"
5850    )]
5851    pub config_setting: Option<Vec<ConfigSettingEntry>>,
5852
5853    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
5854    #[arg(
5855        long,
5856        alias = "config-settings-package",
5857        help_heading = "Build options"
5858    )]
5859    pub config_setting_package: Option<Vec<ConfigSettingPackageEntry>>,
5860
5861    #[command(flatten)]
5862    pub build_isolation: PackageBuildIsolationArgs,
5863
5864    #[command(flatten)]
5865    pub exclude_newer: PackageExcludeNewerArgs,
5866
5867    /// The method to use when installing packages from the global cache.
5868    ///
5869    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
5870    /// Windows.
5871    ///
5872    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
5873    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
5874    /// will break all installed packages by way of removing the underlying source files. Use
5875    /// symlinks with caution.
5876    #[arg(
5877        long,
5878        value_enum,
5879        env = EnvVars::UV_LINK_MODE,
5880        help_heading = "Installer options"
5881    )]
5882    pub link_mode: Option<uv_install_wheel::LinkMode>,
5883
5884    #[command(flatten)]
5885    pub compile_bytecode: CompileBytecodeArgs,
5886
5887    #[command(flatten)]
5888    pub sources: SourcesArgs,
5889
5890    #[command(flatten)]
5891    pub build: BuildOptionsArgs,
5892}
5893
5894#[derive(Args)]
5895pub struct PythonNamespace {
5896    #[command(subcommand)]
5897    pub command: PythonCommand,
5898}
5899
5900#[derive(Subcommand)]
5901pub enum PythonCommand {
5902    /// List the available Python installations.
5903    ///
5904    /// By default, installed Python versions and the downloads for latest available patch version
5905    /// of each supported Python major version are shown.
5906    ///
5907    /// Use `--managed-python` to view only managed Python versions.
5908    ///
5909    /// Use `--no-managed-python` to omit managed Python versions.
5910    ///
5911    /// Use `--all-versions` to view all available patch versions.
5912    ///
5913    /// Use `--only-installed` to omit available downloads.
5914    #[command(alias = "ls")]
5915    List(PythonListArgs),
5916
5917    /// Download and install Python versions.
5918    ///
5919    /// Supports CPython and PyPy. CPython distributions are downloaded from the Astral
5920    /// `python-build-standalone` project. PyPy distributions are downloaded from `python.org`. The
5921    /// available Python versions are bundled with each uv release. To install new Python versions,
5922    /// you may need upgrade uv.
5923    ///
5924    /// Python versions are installed into the uv Python directory, which can be retrieved with `uv
5925    /// python dir`.
5926    ///
5927    /// By default, Python executables are added to a directory on the path with a minor version
5928    /// suffix, e.g., `python3.13`. To install `python3` and `python`, use the `--default` flag. Use
5929    /// `uv python dir --bin` to see the target directory.
5930    ///
5931    /// Multiple Python versions may be requested.
5932    ///
5933    /// See `uv help python` to view supported request formats.
5934    Install(PythonInstallArgs),
5935
5936    /// Upgrade installed Python versions.
5937    ///
5938    /// Upgrades versions to the latest supported patch release.
5939    ///
5940    /// A target Python minor version to upgrade may be provided, e.g., `3.13`. Multiple versions
5941    /// may be provided to perform more than one upgrade.
5942    ///
5943    /// If no target version is provided, then uv will upgrade all managed CPython versions.
5944    ///
5945    /// During an upgrade, uv will not uninstall outdated patch versions.
5946    ///
5947    /// When an upgrade is performed, virtual environments created by uv will automatically
5948    /// use the new version. However, if the virtual environment was created before the
5949    /// upgrade functionality was added, it will continue to use the old Python version; to enable
5950    /// upgrades, the environment must be recreated.
5951    ///
5952    /// Upgrades are not yet supported for alternative implementations, like PyPy.
5953    Upgrade(PythonUpgradeArgs),
5954
5955    /// Search for a Python installation.
5956    ///
5957    /// Displays the path to the Python executable.
5958    ///
5959    /// See `uv help python` to view supported request formats and details on discovery behavior.
5960    Find(PythonFindArgs),
5961
5962    /// Pin to a specific Python version.
5963    ///
5964    /// Writes the pinned Python version to a `.python-version` file, which is used by other uv
5965    /// commands to determine the required Python version.
5966    ///
5967    /// If no version is provided, uv will look for an existing `.python-version` file and display
5968    /// the currently pinned version. If no `.python-version` file is found, uv will exit with an
5969    /// error.
5970    ///
5971    /// See `uv help python` to view supported request formats.
5972    Pin(PythonPinArgs),
5973
5974    /// Show the uv Python installation directory.
5975    ///
5976    /// By default, Python installations are stored in the uv data directory at
5977    /// `$XDG_DATA_HOME/uv/python` or `$HOME/.local/share/uv/python` on Unix and
5978    /// `%APPDATA%\uv\data\python` on Windows.
5979    ///
5980    /// The Python installation directory may be overridden with `$UV_PYTHON_INSTALL_DIR`.
5981    ///
5982    /// To view the directory where uv installs Python executables instead, use the `--bin` flag.
5983    /// The Python executable directory may be overridden with `$UV_PYTHON_BIN_DIR`.
5984    Dir(PythonDirArgs),
5985
5986    /// Uninstall Python versions.
5987    Uninstall(PythonUninstallArgs),
5988
5989    /// Ensure that the Python executable directory is on the `PATH`.
5990    ///
5991    /// If the Python executable directory is not present on the `PATH`, uv will attempt to add it to
5992    /// the relevant shell configuration files.
5993    ///
5994    /// If the shell configuration files already include a blurb to add the executable directory to
5995    /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5996    ///
5997    /// The Python executable directory is determined according to the XDG standard and can be
5998    /// retrieved with `uv python dir --bin`.
5999    #[command(alias = "ensurepath")]
6000    UpdateShell,
6001}
6002
6003#[derive(Args)]
6004pub struct PythonListArgs {
6005    /// A Python request to filter by.
6006    ///
6007    /// See `uv help python` to view supported request formats.
6008    pub request: Option<String>,
6009
6010    /// List all Python versions, including old patch versions.
6011    ///
6012    /// By default, only the latest patch version is shown for each minor version.
6013    #[arg(long)]
6014    pub all_versions: bool,
6015
6016    /// List Python downloads for all platforms.
6017    ///
6018    /// By default, only downloads for the current platform are shown.
6019    #[arg(long)]
6020    pub all_platforms: bool,
6021
6022    /// List Python downloads for all architectures.
6023    ///
6024    /// By default, only downloads for the current architecture are shown.
6025    #[arg(long, alias = "all_architectures")]
6026    pub all_arches: bool,
6027
6028    /// Only show installed Python versions.
6029    ///
6030    /// By default, installed distributions and available downloads for the current platform are shown.
6031    #[arg(long, conflicts_with("only_downloads"))]
6032    pub only_installed: bool,
6033
6034    /// Only show available Python downloads.
6035    ///
6036    /// By default, installed distributions and available downloads for the current platform are shown.
6037    #[arg(long, conflicts_with("only_installed"))]
6038    pub only_downloads: bool,
6039
6040    /// Show the URLs of available Python downloads.
6041    ///
6042    /// By default, these display as `<download available>`.
6043    #[arg(long)]
6044    pub show_urls: bool,
6045
6046    /// Select the output format.
6047    #[arg(long, value_enum, default_value_t = PythonListFormat::default())]
6048    pub output_format: PythonListFormat,
6049
6050    /// URL pointing to JSON of custom Python installations.
6051    #[arg(long, value_hint = ValueHint::Other)]
6052    pub python_downloads_json_url: Option<String>,
6053}
6054
6055#[derive(Args)]
6056pub struct PythonDirArgs {
6057    /// Show the directory into which `uv python` will install Python executables.
6058    ///
6059    /// The Python executable directory is determined according to the XDG standard and is derived
6060    /// from the following environment variables, in order of preference:
6061    ///
6062    /// - `$UV_PYTHON_BIN_DIR`
6063    /// - `$XDG_BIN_HOME`
6064    /// - `$XDG_DATA_HOME/../bin`
6065    /// - `$HOME/.local/bin`
6066    #[arg(long, verbatim_doc_comment)]
6067    pub bin: bool,
6068}
6069
6070#[derive(Args)]
6071pub struct PythonInstallCompileBytecodeArgs {
6072    /// Compile Python's standard library to bytecode after installation.
6073    ///
6074    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6075    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6076    /// in which start time is important, such as CLI applications and Docker containers, this
6077    /// option can be enabled to trade longer installation times and some additional disk space for
6078    /// faster start times.
6079    ///
6080    /// When enabled, uv will process the Python version's `stdlib` directory. It will ignore any
6081    /// compilation errors.
6082    #[arg(
6083        long,
6084        alias = "compile",
6085        overrides_with("no_compile_bytecode"),
6086        env = EnvVars::UV_COMPILE_BYTECODE,
6087        value_parser = clap::builder::BoolishValueParser::new(),
6088    )]
6089    pub compile_bytecode: bool,
6090
6091    #[arg(
6092        long,
6093        alias = "no-compile",
6094        overrides_with("compile_bytecode"),
6095        hide = true
6096    )]
6097    pub no_compile_bytecode: bool,
6098}
6099
6100#[derive(Args)]
6101pub struct PythonInstallArgs {
6102    /// The directory to store the Python installation in.
6103    ///
6104    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6105    /// discover the Python installation.
6106    ///
6107    /// See `uv python dir` to view the current Python installation directory. Defaults to
6108    /// `~/.local/share/uv/python`.
6109    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6110    pub install_dir: Option<PathBuf>,
6111
6112    /// Install a Python executable into the `bin` directory.
6113    ///
6114    /// This is the default behavior. If this flag is provided explicitly, uv will error if the
6115    /// executable cannot be installed.
6116    ///
6117    /// This can also be set with `UV_PYTHON_INSTALL_BIN=1`.
6118    ///
6119    /// See `UV_PYTHON_BIN_DIR` to customize the target directory.
6120    #[arg(long, overrides_with("no_bin"), hide = true)]
6121    pub bin: bool,
6122
6123    /// Do not install a Python executable into the `bin` directory.
6124    ///
6125    /// This can also be set with `UV_PYTHON_INSTALL_BIN=0`.
6126    #[arg(long, overrides_with("bin"), conflicts_with("default"))]
6127    pub no_bin: bool,
6128
6129    /// Register the Python installation in the Windows registry.
6130    ///
6131    /// This is the default behavior on Windows. If this flag is provided explicitly, uv will error if the
6132    /// registry entry cannot be created.
6133    ///
6134    /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=1`.
6135    #[arg(long, overrides_with("no_registry"), hide = true)]
6136    pub registry: bool,
6137
6138    /// Do not register the Python installation in the Windows registry.
6139    ///
6140    /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=0`.
6141    #[arg(long, overrides_with("registry"))]
6142    pub no_registry: bool,
6143
6144    /// The Python version(s) to install.
6145    ///
6146    /// If not provided, the requested Python version(s) will be read from the `UV_PYTHON`
6147    /// environment variable then `.python-versions` or `.python-version` files. If none of the
6148    /// above are present, uv will check if it has installed any Python versions. If not, it will
6149    /// install the latest stable version of Python.
6150    ///
6151    /// See `uv help python` to view supported request formats.
6152    #[arg(env = EnvVars::UV_PYTHON)]
6153    pub targets: Vec<String>,
6154
6155    /// Set the URL to use as the source for downloading Python installations.
6156    ///
6157    /// The provided URL will replace
6158    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6159    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6160    ///
6161    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6162    #[arg(long, value_hint = ValueHint::Url)]
6163    pub mirror: Option<String>,
6164
6165    /// Set the URL to use as the source for downloading PyPy installations.
6166    ///
6167    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6168    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6169    ///
6170    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6171    #[arg(long, value_hint = ValueHint::Url)]
6172    pub pypy_mirror: Option<String>,
6173
6174    /// URL pointing to JSON of custom Python installations.
6175    #[arg(long, value_hint = ValueHint::Other)]
6176    pub python_downloads_json_url: Option<String>,
6177
6178    /// Reinstall the requested Python version, if it's already installed.
6179    ///
6180    /// If a minor version is requested, all matching installed patch versions are reinstalled.
6181    ///
6182    /// By default, uv will exit successfully if the version is already
6183    /// installed.
6184    #[arg(long, short)]
6185    pub reinstall: bool,
6186
6187    /// Replace existing Python executables during installation.
6188    ///
6189    /// By default, uv will refuse to replace executables that it does not manage.
6190    ///
6191    /// Implies `--reinstall`.
6192    #[arg(long, short)]
6193    pub force: bool,
6194
6195    /// Upgrade existing Python installations to the latest patch version.
6196    ///
6197    /// By default, uv will not upgrade already-installed Python versions to newer patch releases.
6198    /// With `--upgrade`, uv will upgrade to the latest available patch version for the specified
6199    /// minor version(s).
6200    ///
6201    /// If the requested versions are not yet installed, uv will install them.
6202    ///
6203    /// This option is only supported for minor version requests, e.g., `3.12`; uv will exit with an
6204    /// error if a patch version, e.g., `3.12.2`, is requested.
6205    #[arg(long, short = 'U')]
6206    pub upgrade: bool,
6207
6208    /// Use as the default Python version.
6209    ///
6210    /// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
6211    /// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
6212    /// also installed.
6213    ///
6214    /// Alternative Python variants will still include their tag. For example, installing
6215    /// 3.13+freethreaded with `--default` will include `python3t` and `pythont` instead of
6216    /// `python3` and `python`.
6217    ///
6218    /// If multiple Python versions are requested, uv will exit with an error.
6219    #[arg(long, conflicts_with("no_bin"))]
6220    pub default: bool,
6221
6222    #[command(flatten)]
6223    pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6224}
6225
6226impl PythonInstallArgs {
6227    #[must_use]
6228    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6229        PythonInstallMirrors {
6230            python_install_mirror: self.mirror.clone(),
6231            pypy_install_mirror: self.pypy_mirror.clone(),
6232            python_downloads_json_url: self.python_downloads_json_url.clone(),
6233        }
6234    }
6235}
6236
6237#[derive(Args)]
6238pub struct PythonUpgradeArgs {
6239    /// The directory Python installations are stored in.
6240    ///
6241    /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6242    /// discover the Python installation.
6243    ///
6244    /// See `uv python dir` to view the current Python installation directory. Defaults to
6245    /// `~/.local/share/uv/python`.
6246    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6247    pub install_dir: Option<PathBuf>,
6248
6249    /// The Python minor version(s) to upgrade.
6250    ///
6251    /// If no target version is provided, then uv will upgrade all managed CPython versions.
6252    #[arg(env = EnvVars::UV_PYTHON)]
6253    pub targets: Vec<String>,
6254
6255    /// Set the URL to use as the source for downloading Python installations.
6256    ///
6257    /// The provided URL will replace
6258    /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6259    /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6260    ///
6261    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6262    #[arg(long, value_hint = ValueHint::Url)]
6263    pub mirror: Option<String>,
6264
6265    /// Set the URL to use as the source for downloading PyPy installations.
6266    ///
6267    /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6268    /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6269    ///
6270    /// Distributions can be read from a local directory by using the `file://` URL scheme.
6271    #[arg(long, value_hint = ValueHint::Url)]
6272    pub pypy_mirror: Option<String>,
6273
6274    /// Reinstall the latest Python patch, if it's already installed.
6275    ///
6276    /// By default, uv will exit successfully if the latest patch is already
6277    /// installed.
6278    #[arg(long, short)]
6279    pub reinstall: bool,
6280
6281    /// URL pointing to JSON of custom Python installations.
6282    #[arg(long, value_hint = ValueHint::Other)]
6283    pub python_downloads_json_url: Option<String>,
6284
6285    #[command(flatten)]
6286    pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6287}
6288
6289impl PythonUpgradeArgs {
6290    #[must_use]
6291    pub fn install_mirrors(&self) -> PythonInstallMirrors {
6292        PythonInstallMirrors {
6293            python_install_mirror: self.mirror.clone(),
6294            pypy_install_mirror: self.pypy_mirror.clone(),
6295            python_downloads_json_url: self.python_downloads_json_url.clone(),
6296        }
6297    }
6298}
6299
6300#[derive(Args)]
6301pub struct PythonUninstallArgs {
6302    /// The directory where the Python was installed.
6303    #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6304    pub install_dir: Option<PathBuf>,
6305
6306    /// The Python version(s) to uninstall.
6307    ///
6308    /// See `uv help python` to view supported request formats.
6309    #[arg(required = true)]
6310    pub targets: Vec<String>,
6311
6312    /// Uninstall all managed Python versions.
6313    #[arg(long, conflicts_with("targets"))]
6314    pub all: bool,
6315}
6316
6317#[derive(Args)]
6318pub struct PythonFindArgs {
6319    /// The Python request.
6320    ///
6321    /// See `uv help python` to view supported request formats.
6322    pub request: Option<String>,
6323
6324    /// Avoid discovering a project or workspace.
6325    ///
6326    /// Otherwise, when no request is provided, the Python requirement of a project in the current
6327    /// directory or parent directories will be used.
6328    #[arg(
6329        long,
6330        alias = "no_workspace",
6331        env = EnvVars::UV_NO_PROJECT,
6332        value_parser = clap::builder::BoolishValueParser::new()
6333    )]
6334    pub no_project: bool,
6335
6336    /// Only find system Python interpreters.
6337    ///
6338    /// By default, uv will report the first Python interpreter it would use, including those in an
6339    /// active virtual environment or a virtual environment in the current working directory or any
6340    /// parent directory.
6341    ///
6342    /// The `--system` option instructs uv to skip virtual environment Python interpreters and
6343    /// restrict its search to the system path.
6344    #[arg(
6345        long,
6346        env = EnvVars::UV_SYSTEM_PYTHON,
6347        value_parser = clap::builder::BoolishValueParser::new(),
6348        overrides_with("no_system")
6349    )]
6350    pub system: bool,
6351
6352    #[arg(long, overrides_with("system"), hide = true)]
6353    pub no_system: bool,
6354
6355    /// Find the environment for a Python script, rather than the current project.
6356    #[arg(
6357        long,
6358        conflicts_with = "request",
6359        conflicts_with = "no_project",
6360        conflicts_with = "system",
6361        conflicts_with = "no_system",
6362        value_hint = ValueHint::FilePath,
6363    )]
6364    pub script: Option<PathBuf>,
6365
6366    /// Show the Python version that would be used instead of the path to the interpreter.
6367    #[arg(long)]
6368    pub show_version: bool,
6369
6370    /// Resolve symlinks in the output path.
6371    ///
6372    /// When enabled, the output path will be canonicalized, resolving any symlinks.
6373    #[arg(long)]
6374    pub resolve_links: bool,
6375
6376    /// URL pointing to JSON of custom Python installations.
6377    #[arg(long, value_hint = ValueHint::Other)]
6378    pub python_downloads_json_url: Option<String>,
6379}
6380
6381#[derive(Args)]
6382pub struct PythonPinArgs {
6383    /// The Python version request.
6384    ///
6385    /// uv supports more formats than other tools that read `.python-version` files, i.e., `pyenv`.
6386    /// If compatibility with those tools is needed, only use version numbers instead of complex
6387    /// requests such as `cpython@3.10`.
6388    ///
6389    /// If no request is provided, the currently pinned version will be shown.
6390    ///
6391    /// See `uv help python` to view supported request formats.
6392    pub request: Option<String>,
6393
6394    /// Write the resolved Python interpreter path instead of the request.
6395    ///
6396    /// Ensures that the exact same interpreter is used.
6397    ///
6398    /// This option is usually not safe to use when committing the `.python-version` file to version
6399    /// control.
6400    #[arg(long, overrides_with("resolved"))]
6401    pub resolved: bool,
6402
6403    #[arg(long, overrides_with("no_resolved"), hide = true)]
6404    pub no_resolved: bool,
6405
6406    /// Avoid validating the Python pin is compatible with the project or workspace.
6407    ///
6408    /// By default, a project or workspace is discovered in the current directory or any parent
6409    /// directory. If a workspace is found, the Python pin is validated against the workspace's
6410    /// `requires-python` constraint.
6411    #[arg(
6412        long,
6413        alias = "no-workspace",
6414        env = EnvVars::UV_NO_PROJECT,
6415        value_parser = clap::builder::BoolishValueParser::new()
6416    )]
6417    pub no_project: bool,
6418
6419    /// Update the global Python version pin.
6420    ///
6421    /// Writes the pinned Python version to a `.python-version` file in the uv user configuration
6422    /// directory: `XDG_CONFIG_HOME/uv` on Linux/macOS and `%APPDATA%/uv` on Windows.
6423    ///
6424    /// When a local Python version pin is not found in the working directory or an ancestor
6425    /// directory, this version will be used instead.
6426    #[arg(long)]
6427    pub global: bool,
6428
6429    /// Remove the Python version pin.
6430    #[arg(long, conflicts_with = "request", conflicts_with = "resolved")]
6431    pub rm: bool,
6432
6433    /// URL pointing to JSON of custom Python installations.
6434    #[arg(long, value_hint = ValueHint::Other)]
6435    pub python_downloads_json_url: Option<String>,
6436}
6437
6438#[derive(Args)]
6439pub struct AuthLogoutArgs {
6440    /// The domain or URL of the service to logout from.
6441    pub service: Service,
6442
6443    /// The username to logout.
6444    #[arg(long, short, value_hint = ValueHint::Other)]
6445    pub username: Option<String>,
6446
6447    /// The keyring provider to use for storage of credentials.
6448    ///
6449    /// Only `--keyring-provider native` is supported for `logout`, which uses the system keyring
6450    /// via an integration built into uv.
6451    #[arg(
6452        long,
6453        value_enum,
6454        env = EnvVars::UV_KEYRING_PROVIDER,
6455    )]
6456    pub keyring_provider: Option<KeyringProviderType>,
6457}
6458
6459#[derive(Args)]
6460pub struct AuthLoginArgs {
6461    /// The domain or URL of the service to log into.
6462    #[arg(value_hint = ValueHint::Url)]
6463    pub service: Service,
6464
6465    /// The username to use for the service.
6466    #[arg(long, short, conflicts_with = "token", value_hint = ValueHint::Other)]
6467    pub username: Option<String>,
6468
6469    /// The password to use for the service.
6470    ///
6471    /// Use `-` to read the password from stdin.
6472    #[arg(long, conflicts_with = "token", value_hint = ValueHint::Other)]
6473    pub password: Option<String>,
6474
6475    /// The token to use for the service.
6476    ///
6477    /// The username will be set to `__token__`.
6478    ///
6479    /// Use `-` to read the token from stdin.
6480    #[arg(long, short, conflicts_with = "username", conflicts_with = "password", value_hint = ValueHint::Other)]
6481    pub token: Option<String>,
6482
6483    /// The keyring provider to use for storage of credentials.
6484    ///
6485    /// Only `--keyring-provider native` is supported for `login`, which uses the system keyring via
6486    /// an integration built into uv.
6487    #[arg(
6488        long,
6489        value_enum,
6490        env = EnvVars::UV_KEYRING_PROVIDER,
6491    )]
6492    pub keyring_provider: Option<KeyringProviderType>,
6493}
6494
6495#[derive(Args)]
6496pub struct AuthTokenArgs {
6497    /// The domain or URL of the service to lookup.
6498    #[arg(value_hint = ValueHint::Url)]
6499    pub service: Service,
6500
6501    /// The username to lookup.
6502    #[arg(long, short, value_hint = ValueHint::Other)]
6503    pub username: Option<String>,
6504
6505    /// The keyring provider to use for reading credentials.
6506    #[arg(
6507        long,
6508        value_enum,
6509        env = EnvVars::UV_KEYRING_PROVIDER,
6510    )]
6511    pub keyring_provider: Option<KeyringProviderType>,
6512}
6513
6514#[derive(Args)]
6515pub struct AuthDirArgs {
6516    /// The domain or URL of the service to lookup.
6517    #[arg(value_hint = ValueHint::Url)]
6518    pub service: Option<Service>,
6519}
6520
6521#[derive(Args)]
6522pub struct AuthHelperArgs {
6523    #[command(subcommand)]
6524    pub command: AuthHelperCommand,
6525
6526    /// The credential helper protocol to use
6527    #[arg(long, value_enum, required = true)]
6528    pub protocol: AuthHelperProtocol,
6529}
6530
6531/// Credential helper protocols supported by uv
6532#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
6533pub enum AuthHelperProtocol {
6534    /// Bazel credential helper protocol as described in [the
6535    /// spec](https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md)
6536    Bazel,
6537}
6538
6539#[derive(Subcommand)]
6540pub enum AuthHelperCommand {
6541    /// Retrieve credentials for a URI
6542    Get,
6543}
6544
6545#[derive(Args)]
6546pub struct GenerateShellCompletionArgs {
6547    /// The shell to generate the completion script for
6548    pub shell: clap_complete_command::Shell,
6549
6550    // Hide unused global options.
6551    #[arg(long, short, hide = true)]
6552    pub no_cache: bool,
6553    #[arg(long, hide = true)]
6554    pub cache_dir: Option<PathBuf>,
6555
6556    #[arg(long, hide = true)]
6557    pub python_preference: Option<PythonPreference>,
6558    #[arg(long, hide = true)]
6559    pub no_python_downloads: bool,
6560
6561    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
6562    pub quiet: u8,
6563    #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
6564    pub verbose: u8,
6565    #[arg(long, conflicts_with = "no_color", hide = true)]
6566    pub color: Option<ColorChoice>,
6567    #[arg(long, hide = true)]
6568    pub native_tls: bool,
6569    #[arg(long, hide = true)]
6570    pub offline: bool,
6571    #[arg(long, hide = true)]
6572    pub no_progress: bool,
6573    #[arg(long, hide = true)]
6574    pub config_file: Option<PathBuf>,
6575    #[arg(long, hide = true)]
6576    pub no_config: bool,
6577    #[arg(long, short, action = clap::ArgAction::HelpShort, hide = true)]
6578    pub help: Option<bool>,
6579    #[arg(short = 'V', long, hide = true)]
6580    pub version: bool,
6581}
6582
6583#[derive(Args)]
6584pub struct IndexArgs {
6585    /// The URLs to use when resolving dependencies, in addition to the default index.
6586    ///
6587    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6588    /// directory laid out in the same format.
6589    ///
6590    /// All indexes provided via this flag take priority over the index specified by
6591    /// `--default-index` (which defaults to PyPI). When multiple `--index` flags are provided,
6592    /// earlier values take priority.
6593    ///
6594    /// Index names are not supported as values. Relative paths must be disambiguated from index
6595    /// names with `./` or `../` on Unix or `.\\`, `..\\`, `./` or `../` on Windows.
6596    //
6597    // The nested Vec structure (`Vec<Vec<Maybe<Index>>>`) is required for clap's
6598    // value parsing mechanism, which processes one value at a time, in order to handle
6599    // `UV_INDEX` the same way pip handles `PIP_EXTRA_INDEX_URL`.
6600    #[arg(
6601        long,
6602        env = EnvVars::UV_INDEX,
6603        hide_env_values = true,
6604        value_parser = parse_indices,
6605        help_heading = "Index options"
6606    )]
6607    pub index: Option<Vec<Vec<Maybe<Index>>>>,
6608
6609    /// The URL of the default package index (by default: <https://pypi.org/simple>).
6610    ///
6611    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6612    /// directory laid out in the same format.
6613    ///
6614    /// The index given by this flag is given lower priority than all other indexes specified via
6615    /// the `--index` flag.
6616    #[arg(
6617        long,
6618        env = EnvVars::UV_DEFAULT_INDEX,
6619        hide_env_values = true,
6620        value_parser = parse_default_index,
6621        help_heading = "Index options"
6622    )]
6623    pub default_index: Option<Maybe<Index>>,
6624
6625    /// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default:
6626    /// <https://pypi.org/simple>).
6627    ///
6628    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6629    /// directory laid out in the same format.
6630    ///
6631    /// The index given by this flag is given lower priority than all other indexes specified via
6632    /// the `--extra-index-url` flag.
6633    #[arg(
6634        long,
6635        short,
6636        env = EnvVars::UV_INDEX_URL,
6637        hide_env_values = true,
6638        value_parser = parse_index_url,
6639        help_heading = "Index options"
6640    )]
6641    pub index_url: Option<Maybe<PipIndex>>,
6642
6643    /// (Deprecated: use `--index` instead) Extra URLs of package indexes to use, in addition to
6644    /// `--index-url`.
6645    ///
6646    /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
6647    /// directory laid out in the same format.
6648    ///
6649    /// All indexes provided via this flag take priority over the index specified by `--index-url`
6650    /// (which defaults to PyPI). When multiple `--extra-index-url` flags are provided, earlier
6651    /// values take priority.
6652    #[arg(
6653        long,
6654        env = EnvVars::UV_EXTRA_INDEX_URL,
6655        hide_env_values = true,
6656        value_delimiter = ' ',
6657        value_parser = parse_extra_index_url,
6658        help_heading = "Index options"
6659    )]
6660    pub extra_index_url: Option<Vec<Maybe<PipExtraIndex>>>,
6661
6662    /// Locations to search for candidate distributions, in addition to those found in the registry
6663    /// indexes.
6664    ///
6665    /// If a path, the target must be a directory that contains packages as wheel files (`.whl`) or
6666    /// source distributions (e.g., `.tar.gz` or `.zip`) at the top level.
6667    ///
6668    /// If a URL, the page must contain a flat list of links to package files adhering to the
6669    /// formats described above.
6670    #[arg(
6671        long,
6672        short,
6673        env = EnvVars::UV_FIND_LINKS,
6674        hide_env_values = true,
6675        value_delimiter = ',',
6676        value_parser = parse_find_links,
6677        help_heading = "Index options"
6678    )]
6679    pub find_links: Option<Vec<Maybe<PipFindLinks>>>,
6680
6681    /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
6682    /// provided via `--find-links`.
6683    #[arg(long, help_heading = "Index options")]
6684    pub no_index: bool,
6685}
6686
6687/// Arguments that configure the package registry client.
6688#[derive(Args)]
6689#[group(skip)]
6690pub struct RegistryClientArgs {
6691    /// The strategy to use when resolving against multiple index URLs.
6692    ///
6693    /// By default, uv will stop at the first index on which a given package is available, and limit
6694    /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6695    /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6696    /// to an alternate index.
6697    #[arg(
6698        long,
6699        value_enum,
6700        env = EnvVars::UV_INDEX_STRATEGY,
6701        help_heading = "Index options"
6702    )]
6703    pub index_strategy: Option<IndexStrategy>,
6704
6705    /// Attempt to use `keyring` for authentication for index URLs.
6706    ///
6707    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6708    /// the `keyring` CLI to handle authentication.
6709    ///
6710    /// Defaults to `disabled`.
6711    #[arg(
6712        long,
6713        value_enum,
6714        env = EnvVars::UV_KEYRING_PROVIDER,
6715        help_heading = "Index options"
6716    )]
6717    pub keyring_provider: Option<KeyringProviderType>,
6718}
6719
6720/// Arguments that control dependency sources.
6721#[derive(Args)]
6722#[group(skip)]
6723pub struct SourcesArgs {
6724    /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6725    /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6726    /// URL, or local path sources.
6727    #[arg(
6728        long,
6729        env = EnvVars::UV_NO_SOURCES,
6730        value_parser = clap::builder::BoolishValueParser::new(),
6731        help_heading = "Resolver options",
6732    )]
6733    no_sources: bool,
6734
6735    /// Don't use sources from the `tool.uv.sources` table for the specified packages [env: `UV_NO_SOURCES_PACKAGE`=]
6736    #[arg(long, help_heading = "Resolver options", value_delimiter = ' ')]
6737    no_sources_package: Vec<PackageName>,
6738}
6739
6740/// Arguments that configure package version selection.
6741#[derive(Args)]
6742#[group(skip)]
6743pub struct VersionSelectionArgs {
6744    /// The strategy to use when selecting between the different compatible versions for a given
6745    /// package requirement.
6746    ///
6747    /// By default, uv will use the latest compatible version of each package (`highest`).
6748    #[arg(
6749        long,
6750        value_enum,
6751        env = EnvVars::UV_RESOLUTION,
6752        help_heading = "Resolver options"
6753    )]
6754    resolution: Option<ResolutionMode>,
6755
6756    /// The strategy to use when considering pre-release versions.
6757    ///
6758    /// By default, uv will prefer stable candidates, falling back to pre-releases only after every
6759    /// stable candidate that satisfies the active constraints is rejected
6760    /// (`if-necessary`).
6761    #[arg(
6762        long,
6763        value_enum,
6764        env = EnvVars::UV_PRERELEASE,
6765        help_heading = "Resolver options"
6766    )]
6767    prerelease: Option<PrereleaseMode>,
6768
6769    /// The strategy to use when considering pre-release versions for a specific package.
6770    ///
6771    /// Accepts package-mode pairs in the format `PACKAGE=MODE`, where `MODE` is any value
6772    /// accepted by `--prerelease`.
6773    ///
6774    /// May be provided multiple times for different packages.
6775    #[arg(long, help_heading = "Resolver options", value_hint = ValueHint::Other)]
6776    prerelease_package: Option<Vec<PrereleasePackageEntry>>,
6777
6778    #[arg(long, hide = true, help_heading = "Resolver options")]
6779    pre: bool,
6780
6781    /// The strategy to use when selecting multiple versions of a given package across Python
6782    /// versions and platforms.
6783    ///
6784    /// By default, uv will optimize for selecting the latest version of each package for each
6785    /// supported Python version (`requires-python`), while minimizing the number of selected
6786    /// versions across platforms.
6787    ///
6788    /// Under `fewest`, uv will minimize the number of selected versions for each package,
6789    /// preferring older versions that are compatible with a wider range of supported Python
6790    /// versions or platforms.
6791    #[arg(
6792        long,
6793        value_enum,
6794        env = EnvVars::UV_FORK_STRATEGY,
6795        help_heading = "Resolver options"
6796    )]
6797    fork_strategy: Option<ForkStrategy>,
6798}
6799
6800/// Arguments that select dependency groups in a project or workspace.
6801#[derive(Args)]
6802#[group(skip)]
6803pub struct ProjectDependencyGroupsArgs<const CHECKS_CONFLICTS: bool = false> {
6804    /// Include the development dependency group [env: UV_DEV=]
6805    ///
6806    /// Development dependencies are defined via `dependency-groups.dev` or
6807    /// `tool.uv.dev-dependencies` in a `pyproject.toml`.
6808    ///
6809    /// This option is an alias for `--group dev`.
6810    ///
6811    /// This option is only available when running in a project.
6812    #[arg(long, overrides_with("no_dev"), hide = true, value_parser = clap::builder::BoolishValueParser::new())]
6813    pub dev: bool,
6814
6815    /// Disable the development dependency group [env: UV_NO_DEV=]
6816    ///
6817    /// This option is an alias of `--no-group dev`.
6818    /// See `--no-default-groups` to disable all default groups instead.
6819    ///
6820    /// This option is only available when running in a project.
6821    #[arg(long, overrides_with("dev"), value_parser = clap::builder::BoolishValueParser::new())]
6822    pub no_dev: bool,
6823
6824    /// Only include the development dependency group.
6825    ///
6826    /// The project and its dependencies will be omitted.
6827    ///
6828    /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
6829    #[arg(long, conflicts_with_all = ["group", "all_groups", "no_dev"])]
6830    pub only_dev: bool,
6831
6832    /// Include dependencies from the specified dependency group.
6833    ///
6834    /// May be provided multiple times.
6835    #[arg(
6836        long,
6837        conflicts_with_all = ["only_group", "only_dev"],
6838        value_hint = ValueHint::Other,
6839        long_help = if CHECKS_CONFLICTS {
6840            concat!(
6841                "Include dependencies from the specified dependency group.\n\n",
6842                "When multiple extras or groups are specified that appear in ",
6843                "`tool.uv.conflicts`, uv will report an error.\n\n",
6844                "May be provided multiple times."
6845            )
6846        } else {
6847            concat!(
6848                "Include dependencies from the specified dependency group.\n\n",
6849                "May be provided multiple times."
6850            )
6851        }
6852    )]
6853    pub group: Vec<GroupName>,
6854
6855    /// Disable the specified dependency group [env: `UV_NO_GROUP`=]
6856    ///
6857    /// This option always takes precedence over default groups,
6858    /// `--all-groups`, and `--group`.
6859    ///
6860    /// May be provided multiple times.
6861    #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
6862    pub no_group: Vec<GroupName>,
6863
6864    /// Ignore the default dependency groups.
6865    ///
6866    /// uv includes the groups defined in `tool.uv.default-groups` by default.
6867    /// This disables that option, however, specific groups can still be included with `--group`.
6868    #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
6869    pub no_default_groups: bool,
6870
6871    /// Only include dependencies from the specified dependency group.
6872    ///
6873    /// The project and its dependencies will be omitted.
6874    ///
6875    /// May be provided multiple times. Implies `--no-default-groups`.
6876    #[arg(long, conflicts_with_all = ["group", "dev", "all_groups"], value_hint = ValueHint::Other)]
6877    pub only_group: Vec<GroupName>,
6878
6879    /// Include dependencies from all dependency groups.
6880    ///
6881    /// `--no-group` can be used to exclude specific groups.
6882    #[arg(long, conflicts_with_all = ["only_group", "only_dev"])]
6883    pub all_groups: bool,
6884}
6885
6886/// Dependency-group arguments for commands that reject conflicting extras or groups.
6887pub type ConflictCheckedDependencyGroupsArgs = ProjectDependencyGroupsArgs<true>;
6888
6889/// Arguments that configure requirement hash checking.
6890#[derive(Args)]
6891#[group(skip)]
6892pub struct HashCheckingArgs {
6893    /// Require a matching hash for each requirement.
6894    ///
6895    /// By default, uv will verify any available hashes in the requirements file, but will not
6896    /// require that all requirements have an associated hash.
6897    ///
6898    /// When `--require-hashes` is enabled, _all_ requirements must include a hash or set of hashes,
6899    /// and _all_ requirements must either be pinned to exact versions (e.g., `==1.0.0`), or be
6900    /// specified via direct URL.
6901    ///
6902    /// Hash-checking mode introduces a number of additional constraints:
6903    ///
6904    /// - Git dependencies are not supported.
6905    /// - Editable installations are not supported.
6906    /// - Local dependencies are not supported, unless they point to a specific wheel (`.whl`) or
6907    ///   source archive (`.zip`, `.tar.gz`), as opposed to a directory.
6908    #[arg(
6909        long,
6910        env = EnvVars::UV_REQUIRE_HASHES,
6911        value_parser = clap::builder::BoolishValueParser::new(),
6912        overrides_with("no_require_hashes"),
6913    )]
6914    pub require_hashes: bool,
6915
6916    #[arg(long, overrides_with("require_hashes"), hide = true)]
6917    pub no_require_hashes: bool,
6918
6919    #[arg(long, overrides_with("no_verify_hashes"), hide = true)]
6920    pub verify_hashes: bool,
6921
6922    /// Disable validation of hashes in the requirements file.
6923    ///
6924    /// By default, uv will verify any available hashes in the requirements file, but will not
6925    /// require that all requirements have an associated hash. To enforce hash validation, use
6926    /// `--require-hashes`.
6927    #[arg(
6928        long,
6929        env = EnvVars::UV_NO_VERIFY_HASHES,
6930        value_parser = clap::builder::BoolishValueParser::new(),
6931        overrides_with("verify_hashes"),
6932    )]
6933    pub no_verify_hashes: bool,
6934}
6935
6936/// Arguments that filter packages by upload date.
6937#[derive(Args)]
6938#[group(skip)]
6939pub struct ExcludeNewerArgs {
6940    /// Limit candidate packages to those that were uploaded prior to the given date.
6941    ///
6942    /// The date is compared against the upload time of each individual distribution artifact
6943    /// (i.e., when each file was uploaded to the package index), not the release date of the
6944    /// package version.
6945    ///
6946    /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
6947    /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
6948    /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
6949    /// `P7D`, `P30D`).
6950    ///
6951    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6952    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6953    /// Calendar units such as months and years are not allowed.
6954    ///
6955    /// Use `false` to disable `exclude-newer`.
6956    #[arg(
6957        long,
6958        env = EnvVars::UV_EXCLUDE_NEWER,
6959        help_heading = "Resolver options",
6960        value_hint = ValueHint::Other,
6961    )]
6962    pub exclude_newer: Option<ExcludeNewerOverride>,
6963}
6964
6965/// Arguments that filter packages by global and package-specific upload dates.
6966#[derive(Args)]
6967#[group(skip)]
6968pub struct PackageExcludeNewerArgs {
6969    #[command(flatten)]
6970    pub exclude_newer: ExcludeNewerArgs,
6971
6972    /// Limit candidate packages for specific packages to those that were uploaded prior to the
6973    /// given date.
6974    ///
6975    /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
6976    /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
6977    /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
6978    /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
6979    /// `P30D`).
6980    ///
6981    /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6982    /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6983    /// Calendar units such as months and years are not allowed.
6984    ///
6985    /// Can be provided multiple times for different packages.
6986    #[arg(long, help_heading = "Resolver options", value_hint = ValueHint::Other)]
6987    pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6988}
6989
6990#[derive(Args)]
6991pub struct RefreshArgs {
6992    /// Refresh all cached data.
6993    #[arg(long, overrides_with("no_refresh"), help_heading = "Cache options")]
6994    refresh: bool,
6995
6996    #[arg(
6997        long,
6998        overrides_with("refresh"),
6999        hide = true,
7000        help_heading = "Cache options"
7001    )]
7002    no_refresh: bool,
7003
7004    /// Refresh cached data for a specific package.
7005    #[arg(long, help_heading = "Cache options", value_hint = ValueHint::Other)]
7006    refresh_package: Vec<PackageName>,
7007}
7008
7009#[derive(Args)]
7010pub struct BuildOptionsArgs {
7011    /// Don't build source distributions.
7012    ///
7013    /// When enabled, uv will reuse cached wheels from previously built source distributions, but
7014    /// operations that require building a source distribution will exit with an error. uv may
7015    /// still build editable requirements, and their build backends may run arbitrary Python code.
7016    #[arg(
7017        long,
7018        env = EnvVars::UV_NO_BUILD,
7019        overrides_with("build"),
7020        value_parser = clap::builder::BoolishValueParser::new(),
7021        help_heading = "Build options",
7022    )]
7023    no_build: bool,
7024
7025    #[arg(
7026        long,
7027        overrides_with("no_build"),
7028        hide = true,
7029        help_heading = "Build options"
7030    )]
7031    build: bool,
7032
7033    /// Don't build source distributions for a specific package [env: `UV_NO_BUILD_PACKAGE`=]
7034    #[arg(
7035        long,
7036        help_heading = "Build options",
7037        value_delimiter = ' ',
7038        value_hint = ValueHint::Other,
7039    )]
7040    no_build_package: Vec<PackageName>,
7041
7042    /// Don't install pre-built wheels.
7043    ///
7044    /// The given packages will be built and installed from source. The resolver will still use
7045    /// pre-built wheels to extract package metadata, if available.
7046    #[arg(
7047        long,
7048        env = EnvVars::UV_NO_BINARY,
7049        overrides_with("binary"),
7050        value_parser = clap::builder::BoolishValueParser::new(),
7051        help_heading = "Build options"
7052    )]
7053    no_binary: bool,
7054
7055    #[arg(
7056        long,
7057        overrides_with("no_binary"),
7058        hide = true,
7059        help_heading = "Build options"
7060    )]
7061    binary: bool,
7062
7063    /// Don't install pre-built wheels for a specific package [env: `UV_NO_BINARY_PACKAGE`=]
7064    #[arg(
7065        long,
7066        help_heading = "Build options",
7067        value_delimiter = ' ',
7068        value_hint = ValueHint::Other,
7069    )]
7070    no_binary_package: Vec<PackageName>,
7071}
7072
7073/// Arguments that configure build isolation for source distributions.
7074#[derive(Args)]
7075#[group(skip)]
7076pub struct BuildIsolationArgs {
7077    /// Disable isolation when building source distributions.
7078    ///
7079    /// Assumes that build dependencies specified by PEP 518 are already installed.
7080    #[arg(
7081        long,
7082        overrides_with("build_isolation"),
7083        help_heading = "Build options",
7084        env = EnvVars::UV_NO_BUILD_ISOLATION,
7085        value_parser = clap::builder::BoolishValueParser::new(),
7086    )]
7087    no_build_isolation: bool,
7088
7089    #[arg(
7090        long,
7091        overrides_with("no_build_isolation"),
7092        hide = true,
7093        help_heading = "Build options"
7094    )]
7095    build_isolation: bool,
7096}
7097
7098/// Arguments that configure global and package-specific build isolation.
7099#[derive(Args)]
7100#[group(skip)]
7101pub struct PackageBuildIsolationArgs {
7102    #[command(flatten)]
7103    build_isolation: BuildIsolationArgs,
7104
7105    /// Disable isolation when building source distributions for a specific package.
7106    ///
7107    /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7108    #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7109    no_build_isolation_package: Vec<PackageName>,
7110}
7111
7112#[derive(Args)]
7113#[group(skip)]
7114pub struct ReinstallArgs {
7115    /// Reinstall all packages, regardless of whether they're already installed. Implies
7116    /// `--refresh`.
7117    #[arg(
7118        long,
7119        alias = "force-reinstall",
7120        overrides_with("no_reinstall"),
7121        help_heading = "Installer options"
7122    )]
7123    pub reinstall: bool,
7124
7125    #[arg(
7126        long,
7127        overrides_with("reinstall"),
7128        hide = true,
7129        help_heading = "Installer options"
7130    )]
7131    pub no_reinstall: bool,
7132
7133    /// Reinstall a specific package, regardless of whether it's already installed. Implies
7134    /// `--refresh-package`.
7135    #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7136    pub reinstall_package: Vec<PackageName>,
7137}
7138
7139#[derive(Args)]
7140#[group(skip)]
7141pub struct CompileBytecodeArgs {
7142    /// Compile Python files to bytecode after installation.
7143    ///
7144    /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7145    /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7146    /// in which start time is critical, such as CLI applications and Docker containers, this option
7147    /// can be enabled to trade longer installation times for faster start times.
7148    ///
7149    /// When enabled, install operations (e.g., `uv pip install`) will compile installed or
7150    /// reinstalled Python files. Commands that perform a sync operation (e.g., `uv sync` or `uv
7151    /// run`) will process the entire site-packages directory including packages that are not being
7152    /// modified.
7153    #[arg(
7154        long,
7155        alias = "compile",
7156        overrides_with("no_compile_bytecode"),
7157        help_heading = "Installer options",
7158        env = EnvVars::UV_COMPILE_BYTECODE,
7159        value_parser = clap::builder::BoolishValueParser::new(),
7160    )]
7161    compile_bytecode: bool,
7162
7163    #[arg(
7164        long,
7165        alias = "no-compile",
7166        overrides_with("compile_bytecode"),
7167        hide = true,
7168        help_heading = "Installer options"
7169    )]
7170    no_compile_bytecode: bool,
7171}
7172
7173/// Arguments that are used by commands that need to install (but not resolve) packages.
7174#[derive(Args)]
7175pub struct InstallerArgs {
7176    #[command(flatten)]
7177    index_args: IndexArgs,
7178
7179    #[command(flatten)]
7180    reinstall: ReinstallArgs,
7181
7182    #[command(flatten)]
7183    registry_client: RegistryClientArgs,
7184
7185    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7186    #[arg(
7187        long,
7188        short = 'C',
7189        alias = "config-settings",
7190        help_heading = "Build options"
7191    )]
7192    config_setting: Option<Vec<ConfigSettingEntry>>,
7193
7194    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7195    #[arg(
7196        long,
7197        alias = "config-settings-package",
7198        help_heading = "Build options"
7199    )]
7200    config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7201
7202    #[command(flatten)]
7203    build_isolation: BuildIsolationArgs,
7204
7205    #[command(flatten)]
7206    exclude_newer: PackageExcludeNewerArgs,
7207
7208    /// The method to use when installing packages from the global cache.
7209    ///
7210    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7211    /// Windows.
7212    ///
7213    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7214    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7215    /// will break all installed packages by way of removing the underlying source files. Use
7216    /// symlinks with caution.
7217    #[arg(
7218        long,
7219        value_enum,
7220        env = EnvVars::UV_LINK_MODE,
7221        help_heading = "Installer options"
7222    )]
7223    link_mode: Option<uv_install_wheel::LinkMode>,
7224
7225    #[command(flatten)]
7226    compile_bytecode: CompileBytecodeArgs,
7227
7228    #[command(flatten)]
7229    sources: SourcesArgs,
7230}
7231
7232/// Arguments that are used by commands that need to resolve (but not install) packages.
7233#[derive(Args)]
7234pub struct ResolverArgs {
7235    #[command(flatten)]
7236    index_args: IndexArgs,
7237
7238    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7239    /// `--refresh`.
7240    #[arg(
7241        long,
7242        short = 'U',
7243        overrides_with("no_upgrade"),
7244        help_heading = "Resolver options"
7245    )]
7246    upgrade: bool,
7247
7248    #[arg(
7249        long,
7250        overrides_with("upgrade"),
7251        hide = true,
7252        help_heading = "Resolver options"
7253    )]
7254    no_upgrade: bool,
7255
7256    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
7257    /// file. Implies `--refresh-package`.
7258    #[arg(long, short = 'P', help_heading = "Resolver options")]
7259    upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7260
7261    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7262    /// existing output file.
7263    #[arg(long, help_heading = "Resolver options")]
7264    upgrade_group: Vec<GroupName>,
7265
7266    #[command(flatten)]
7267    registry_client: RegistryClientArgs,
7268
7269    #[command(flatten)]
7270    version_selection: VersionSelectionArgs,
7271
7272    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7273    #[arg(
7274        long,
7275        short = 'C',
7276        alias = "config-settings",
7277        help_heading = "Build options"
7278    )]
7279    config_setting: Option<Vec<ConfigSettingEntry>>,
7280
7281    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7282    #[arg(
7283        long,
7284        alias = "config-settings-package",
7285        help_heading = "Build options"
7286    )]
7287    config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7288
7289    #[command(flatten)]
7290    build_isolation: PackageBuildIsolationArgs,
7291
7292    #[command(flatten)]
7293    exclude_newer: PackageExcludeNewerArgs,
7294
7295    /// The method to use when installing packages from the global cache.
7296    ///
7297    /// This option is only used when building source distributions.
7298    ///
7299    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7300    /// Windows.
7301    ///
7302    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7303    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7304    /// will break all installed packages by way of removing the underlying source files. Use
7305    /// symlinks with caution.
7306    #[arg(
7307        long,
7308        value_enum,
7309        env = EnvVars::UV_LINK_MODE,
7310        help_heading = "Installer options"
7311    )]
7312    link_mode: Option<uv_install_wheel::LinkMode>,
7313
7314    #[command(flatten)]
7315    sources: SourcesArgs,
7316}
7317
7318/// Arguments that are used by commands that need to resolve and install packages.
7319#[derive(Args)]
7320pub struct ResolverInstallerArgs {
7321    #[command(flatten)]
7322    pub index_args: IndexArgs,
7323
7324    /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7325    /// `--refresh`.
7326    #[arg(
7327        long,
7328        short = 'U',
7329        overrides_with("no_upgrade"),
7330        help_heading = "Resolver options"
7331    )]
7332    pub upgrade: bool,
7333
7334    #[arg(
7335        long,
7336        overrides_with("upgrade"),
7337        hide = true,
7338        help_heading = "Resolver options"
7339    )]
7340    pub no_upgrade: bool,
7341
7342    /// Allow upgrades for a specific package, ignoring pinned versions in any existing output file.
7343    /// Implies `--refresh-package`.
7344    #[arg(long, short = 'P', help_heading = "Resolver options", value_hint = ValueHint::Other)]
7345    pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7346
7347    /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7348    /// existing output file.
7349    #[arg(long, help_heading = "Resolver options")]
7350    pub upgrade_group: Vec<GroupName>,
7351
7352    #[command(flatten)]
7353    pub reinstall: ReinstallArgs,
7354
7355    #[command(flatten)]
7356    pub registry_client: RegistryClientArgs,
7357
7358    #[command(flatten)]
7359    pub version_selection: VersionSelectionArgs,
7360
7361    /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7362    #[arg(
7363        long,
7364        short = 'C',
7365        alias = "config-settings",
7366        help_heading = "Build options",
7367        value_hint = ValueHint::Other,
7368    )]
7369    pub config_setting: Option<Vec<ConfigSettingEntry>>,
7370
7371    /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7372    #[arg(
7373        long,
7374        alias = "config-settings-package",
7375        help_heading = "Build options",
7376        value_hint = ValueHint::Other,
7377    )]
7378    pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7379
7380    #[command(flatten)]
7381    pub build_isolation: PackageBuildIsolationArgs,
7382
7383    #[command(flatten)]
7384    pub exclude_newer: PackageExcludeNewerArgs,
7385
7386    /// The method to use when installing packages from the global cache.
7387    ///
7388    /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7389    /// Windows.
7390    ///
7391    /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7392    /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7393    /// will break all installed packages by way of removing the underlying source files. Use
7394    /// symlinks with caution.
7395    #[arg(
7396        long,
7397        value_enum,
7398        env = EnvVars::UV_LINK_MODE,
7399        help_heading = "Installer options"
7400    )]
7401    pub link_mode: Option<uv_install_wheel::LinkMode>,
7402
7403    #[command(flatten)]
7404    pub compile_bytecode: CompileBytecodeArgs,
7405
7406    #[command(flatten)]
7407    pub sources: SourcesArgs,
7408}
7409
7410/// Arguments that are used by commands that need to fetch from the Simple API.
7411#[derive(Args)]
7412pub struct FetchArgs {
7413    #[command(flatten)]
7414    index_args: IndexArgs,
7415
7416    #[command(flatten)]
7417    registry_client: RegistryClientArgs,
7418
7419    #[command(flatten)]
7420    exclude_newer: PackageExcludeNewerArgs,
7421}
7422
7423#[derive(Args)]
7424pub struct DisplayTreeArgs {
7425    /// Maximum display depth of the dependency tree
7426    #[arg(long, short, default_value_t = 255)]
7427    pub depth: u8,
7428
7429    /// Prune the given package from the display of the dependency tree.
7430    #[arg(long, value_hint = ValueHint::Other)]
7431    pub prune: Vec<PackageName>,
7432
7433    /// Display only the specified packages.
7434    #[arg(long, value_hint = ValueHint::Other)]
7435    pub package: Vec<PackageName>,
7436
7437    /// Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its
7438    /// dependencies, further occurrences will not re-display its dependencies, and will include a
7439    /// (*) to indicate it has already been shown. This flag will cause those duplicates to be
7440    /// repeated.
7441    #[arg(long)]
7442    pub no_dedupe: bool,
7443
7444    /// Show the reverse dependencies for the given package. This flag will invert the tree and
7445    /// display the packages that depend on the given package.
7446    #[arg(long, alias = "reverse")]
7447    pub invert: bool,
7448
7449    /// Show the latest available version of each package in the tree.
7450    #[arg(long)]
7451    pub outdated: bool,
7452
7453    /// Show compressed wheel sizes for packages in the tree.
7454    #[arg(long)]
7455    pub show_sizes: bool,
7456}
7457
7458#[derive(Args, Debug)]
7459pub struct PublishArgs {
7460    /// Paths to the files to upload. Accepts glob expressions.
7461    ///
7462    /// Defaults to the `dist` directory. Selects only wheels and source distributions
7463    /// and their attestations, while ignoring other files.
7464    #[arg(default_value = "dist/*", value_hint = ValueHint::FilePath)]
7465    pub files: Vec<String>,
7466
7467    /// The name of an index in the configuration to use for publishing.
7468    ///
7469    /// The index must have a `publish-url` setting, for example:
7470    ///
7471    /// ```toml
7472    /// [[tool.uv.index]]
7473    /// name = "pypi"
7474    /// url = "https://pypi.org/simple"
7475    /// publish-url = "https://upload.pypi.org/legacy/"
7476    /// ```
7477    ///
7478    /// The index `url` will be used to check for existing files to skip duplicate uploads.
7479    ///
7480    /// With these settings, the following two calls are equivalent:
7481    ///
7482    /// ```shell
7483    /// uv publish --index pypi
7484    /// uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pypi.org/simple
7485    /// ```
7486    #[arg(
7487        long,
7488        verbatim_doc_comment,
7489        env = EnvVars::UV_PUBLISH_INDEX,
7490        conflicts_with = "publish_url",
7491        conflicts_with = "check_url",
7492        value_hint = ValueHint::Other,
7493    )]
7494    pub index: Option<String>,
7495
7496    /// The username for the upload.
7497    #[arg(
7498        short,
7499        long,
7500        env = EnvVars::UV_PUBLISH_USERNAME,
7501        hide_env_values = true,
7502        value_hint = ValueHint::Other
7503    )]
7504    pub username: Option<String>,
7505
7506    /// The password for the upload.
7507    #[arg(
7508        short,
7509        long,
7510        env = EnvVars::UV_PUBLISH_PASSWORD,
7511        hide_env_values = true,
7512        value_hint = ValueHint::Other
7513    )]
7514    pub password: Option<String>,
7515
7516    /// The token for the upload.
7517    ///
7518    /// Using a token is equivalent to passing `__token__` as `--username` and the token as
7519    /// `--password` password.
7520    #[arg(
7521        short,
7522        long,
7523        env = EnvVars::UV_PUBLISH_TOKEN,
7524        hide_env_values = true,
7525        conflicts_with = "username",
7526        conflicts_with = "password",
7527        value_hint = ValueHint::Other,
7528    )]
7529    pub token: Option<String>,
7530
7531    /// Configure trusted publishing.
7532    ///
7533    /// By default, uv checks for trusted publishing when running in a supported environment, but
7534    /// ignores it if it isn't configured.
7535    ///
7536    /// uv's supported environments for trusted publishing include GitHub Actions and GitLab CI/CD.
7537    #[arg(long)]
7538    pub trusted_publishing: Option<TrustedPublishing>,
7539
7540    /// Attempt to use `keyring` for authentication for remote requirements files.
7541    ///
7542    /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7543    /// the `keyring` CLI to handle authentication.
7544    ///
7545    /// Defaults to `disabled`.
7546    #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
7547    pub keyring_provider: Option<KeyringProviderType>,
7548
7549    /// The URL of the upload endpoint (not the index URL).
7550    ///
7551    /// Note that there are typically different URLs for index access (e.g., `https:://.../simple`)
7552    /// and index upload.
7553    ///
7554    /// Defaults to PyPI's publish URL (<https://upload.pypi.org/legacy/>).
7555    #[arg(long, env = EnvVars::UV_PUBLISH_URL, hide_env_values = true)]
7556    pub publish_url: Option<DisplaySafeUrl>,
7557
7558    /// Check an index URL for existing files to skip duplicate uploads.
7559    ///
7560    /// This option allows retrying publishing that failed after only some, but not all files have
7561    /// been uploaded, and handles errors due to parallel uploads of the same file.
7562    ///
7563    /// Before uploading, the index is checked. If the exact same file already exists in the index,
7564    /// the file will not be uploaded. If an error occurred during the upload, the index is checked
7565    /// again, to handle cases where the identical file was uploaded twice in parallel.
7566    ///
7567    /// The exact behavior will vary based on the index. When uploading to PyPI, uploading the same
7568    /// file succeeds even without `--check-url`, while most other indexes error. When uploading to
7569    /// pyx, the index URL can be inferred automatically from the publish URL.
7570    ///
7571    /// The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).
7572    #[arg(long, env = EnvVars::UV_PUBLISH_CHECK_URL, hide_env_values = true)]
7573    pub check_url: Option<IndexUrl>,
7574
7575    #[arg(long, hide = true)]
7576    pub skip_existing: bool,
7577
7578    /// Perform a dry run without uploading files.
7579    ///
7580    /// When enabled, the command will check for existing files if `--check-url` is provided,
7581    /// and will perform validation against the index if supported, but will not upload any files.
7582    #[arg(long)]
7583    pub dry_run: bool,
7584
7585    /// Do not upload attestations for the published files.
7586    ///
7587    /// By default, uv attempts to upload matching PEP 740 attestations with each distribution
7588    /// that is published.
7589    #[arg(long, env = EnvVars::UV_PUBLISH_NO_ATTESTATIONS)]
7590    pub no_attestations: bool,
7591
7592    /// Use direct upload to the registry.
7593    ///
7594    /// When enabled, the publish command will use a direct two-phase upload protocol
7595    /// that uploads files directly to storage, bypassing the registry's upload endpoint.
7596    #[arg(long, hide = true)]
7597    pub direct: bool,
7598}
7599
7600#[derive(Args)]
7601pub struct WorkspaceNamespace {
7602    #[command(subcommand)]
7603    pub command: WorkspaceCommand,
7604}
7605
7606#[derive(Subcommand)]
7607pub enum WorkspaceCommand {
7608    /// View metadata about the current workspace.
7609    ///
7610    /// The output of this command is not yet stable.
7611    Metadata(Box<MetadataArgs>),
7612    /// Display the path of a workspace member.
7613    ///
7614    /// By default, the path to the workspace root directory is displayed.
7615    /// The `--package` option can be used to display the path to a workspace member instead.
7616    ///
7617    /// If used outside of a workspace, i.e., if a `pyproject.toml` cannot be found, uv will exit with an error.
7618    Dir(WorkspaceDirArgs),
7619    /// List the members of a workspace.
7620    ///
7621    /// Displays newline separated names of workspace members.
7622    List(WorkspaceListArgs),
7623}
7624#[derive(Args)]
7625pub struct MetadataArgs {
7626    /// View metadata for the specified PEP 723 Python script, rather than the current workspace.
7627    ///
7628    /// If provided, uv will resolve the dependencies based on the script's inline metadata table,
7629    /// in adherence with PEP 723.
7630    #[arg(long, value_hint = ValueHint::FilePath)]
7631    pub script: Option<PathBuf>,
7632
7633    /// Check if the lockfile is up-to-date [env: UV_LOCKED=]
7634    ///
7635    /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
7636    /// missing or needs to be updated, uv will exit with an error.
7637    #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
7638    pub locked: bool,
7639
7640    /// Assert that a `uv.lock` exists without checking if it is up-to-date [env: UV_FROZEN=]
7641    #[arg(long, conflicts_with_all = ["locked"])]
7642    pub frozen: bool,
7643
7644    /// Perform a dry run, without writing the lockfile.
7645    ///
7646    /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
7647    /// changes, but will not write the lockfile to disk.
7648    #[arg(
7649        long,
7650        conflicts_with = "frozen",
7651        conflicts_with = "locked",
7652        conflicts_with = "sync"
7653    )]
7654    pub dry_run: bool,
7655
7656    #[command(flatten)]
7657    pub resolver: ResolverArgs,
7658
7659    #[command(flatten)]
7660    pub build: BuildOptionsArgs,
7661
7662    #[command(flatten)]
7663    pub refresh: RefreshArgs,
7664
7665    /// Sync the environment to include module ownership metadata in the output.
7666    ///
7667    /// This adds a mapping from importable module names to references to the package nodes
7668    /// that provide them. To do this, the venv will be synced in inexact mode.
7669    #[arg(long)]
7670    pub sync: bool,
7671
7672    /// Sync dependencies to the active virtual environment.
7673    ///
7674    /// Instead of creating or updating the virtual environment for the project or script, the
7675    /// active virtual environment will be preferred, if the `VIRTUAL_ENV` environment variable is
7676    /// set.
7677    #[arg(long)]
7678    pub active: bool,
7679
7680    /// The Python interpreter to use during resolution.
7681    ///
7682    /// A Python interpreter is required for building source distributions to determine package
7683    /// metadata when there are not wheels.
7684    ///
7685    /// The interpreter is also used as the fallback value for the minimum Python version if
7686    /// `requires-python` is not set.
7687    ///
7688    /// See `uv help python` for details on Python discovery and supported request formats.
7689    #[arg(
7690        long,
7691        short,
7692        env = EnvVars::UV_PYTHON,
7693        verbatim_doc_comment,
7694        help_heading = "Python options",
7695        value_parser = parse_maybe_string,
7696        value_hint = ValueHint::Other,
7697    )]
7698    pub python: Option<Maybe<String>>,
7699}
7700
7701#[derive(Args, Debug)]
7702pub struct WorkspaceDirArgs {
7703    /// Display the path to a specific package in the workspace.
7704    #[arg(long, value_hint = ValueHint::Other)]
7705    pub package: Option<PackageName>,
7706}
7707
7708#[derive(Args, Debug)]
7709pub struct WorkspaceListArgs {
7710    /// Show paths instead of names.
7711    #[arg(long)]
7712    pub paths: bool,
7713
7714    /// List all standalone scripts with inline metadata in the workspace.
7715    #[arg(long)]
7716    pub scripts: bool,
7717}
7718
7719/// See [PEP 517](https://peps.python.org/pep-0517/) and
7720/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.
7721#[derive(Subcommand)]
7722pub enum BuildBackendCommand {
7723    /// PEP 517 hook `build_sdist`.
7724    BuildSdist { sdist_directory: PathBuf },
7725    /// PEP 517 hook `build_wheel`.
7726    BuildWheel {
7727        wheel_directory: PathBuf,
7728        #[arg(long)]
7729        metadata_directory: Option<PathBuf>,
7730    },
7731    /// PEP 660 hook `build_editable`.
7732    BuildEditable {
7733        wheel_directory: PathBuf,
7734        #[arg(long)]
7735        metadata_directory: Option<PathBuf>,
7736    },
7737    /// PEP 517 hook `get_requires_for_build_sdist`.
7738    GetRequiresForBuildSdist,
7739    /// PEP 517 hook `get_requires_for_build_wheel`.
7740    GetRequiresForBuildWheel,
7741    /// PEP 517 hook `prepare_metadata_for_build_wheel`.
7742    PrepareMetadataForBuildWheel { wheel_directory: PathBuf },
7743    /// PEP 660 hook `get_requires_for_build_editable`.
7744    GetRequiresForBuildEditable,
7745    /// PEP 660 hook `prepare_metadata_for_build_editable`.
7746    PrepareMetadataForBuildEditable { wheel_directory: PathBuf },
7747}