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