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