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