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