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