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