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