Skip to main content

uv_cli/
lib.rs

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