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