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