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 dangling cache entries and cached environments.
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, the exact version resolved in `uv.lock` will be used when `ty` is a project
5414 /// dependency or a dependency in the project's `dev` group. Otherwise, a constrained version
5415 /// range of ty will be used (e.g., `>=0.0,<0.1`).
5416 #[arg(long, value_hint = ValueHint::Other)]
5417 pub ty_version: Option<String>,
5418
5419 /// Display the version of ty that will be used for type checking.
5420 #[arg(long, hide = true)]
5421 pub show_version: bool,
5422
5423 /// Avoid discovering a project or workspace.
5424 ///
5425 /// Instead of running checks in the context of the current project, run them in the context of
5426 /// the current directory. This is useful when the current directory is not a project.
5427 #[arg(
5428 long,
5429 env = EnvVars::UV_NO_PROJECT,
5430 value_parser = clap::builder::BoolishValueParser::new()
5431 )]
5432 pub no_project: bool,
5433
5434 #[command(flatten)]
5435 pub installer: ResolverInstallerArgs,
5436
5437 #[command(flatten)]
5438 pub build: BuildOptionsArgs,
5439
5440 #[command(flatten)]
5441 pub refresh: RefreshArgs,
5442}
5443
5444#[derive(Args)]
5445pub struct AuditArgs {
5446 /// Don't audit the specified optional dependencies.
5447 ///
5448 /// May be provided multiple times.
5449 #[arg(long, value_hint = ValueHint::Other)]
5450 pub no_extra: Vec<ExtraName>,
5451
5452 /// Don't audit the development dependency group [env: UV_NO_DEV=]
5453 ///
5454 /// This option is an alias of `--no-group dev`.
5455 /// See `--no-default-groups` to exclude all default groups instead.
5456 ///
5457 /// This option is only available when running in a project.
5458 #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5459 pub no_dev: bool,
5460
5461 /// Don't audit the specified dependency group [env: `UV_NO_GROUP`=]
5462 ///
5463 /// May be provided multiple times.
5464 #[arg(long, value_delimiter = ' ', value_hint = ValueHint::Other)]
5465 pub no_group: Vec<GroupName>,
5466
5467 /// Don't audit the default dependency groups.
5468 #[arg(long, env = EnvVars::UV_NO_DEFAULT_GROUPS, value_parser = clap::builder::BoolishValueParser::new())]
5469 pub no_default_groups: bool,
5470
5471 /// Only audit dependencies from the specified dependency group.
5472 ///
5473 /// The project and its dependencies will be omitted.
5474 ///
5475 /// May be provided multiple times. Implies `--no-default-groups`.
5476 #[arg(long, value_hint = ValueHint::Other)]
5477 pub only_group: Vec<GroupName>,
5478
5479 /// Only audit the development dependency group.
5480 ///
5481 /// The project and its dependencies will be omitted.
5482 ///
5483 /// This option is an alias for `--only-group dev`. Implies `--no-default-groups`.
5484 #[arg(long, conflicts_with_all = ["no_dev"])]
5485 pub only_dev: bool,
5486
5487 /// Assert that the `uv.lock` will remain unchanged [env: UV_LOCKED=]
5488 ///
5489 /// Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated,
5490 /// uv will exit with an error.
5491 #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
5492 pub locked: bool,
5493
5494 /// Audit the requirements without locking the project [env: UV_FROZEN=]
5495 ///
5496 /// If the lockfile is missing, uv will exit with an error.
5497 #[arg(long, conflicts_with_all = ["locked", "upgrade", "no_sources"])]
5498 pub frozen: bool,
5499
5500 /// Select the output format.
5501 #[arg(long, value_enum, default_value_t = AuditOutputFormat::default())]
5502 pub output_format: AuditOutputFormat,
5503
5504 #[command(flatten)]
5505 pub build: BuildOptionsArgs,
5506
5507 #[command(flatten)]
5508 pub resolver: ResolverArgs,
5509
5510 /// Audit the specified PEP 723 Python script, rather than the current
5511 /// project.
5512 ///
5513 /// The specified script must be locked, i.e. with `uv lock --script <script>`
5514 /// before it can be audited.
5515 #[arg(long, value_hint = ValueHint::FilePath)]
5516 pub script: Option<PathBuf>,
5517
5518 /// The Python version to use when auditing.
5519 ///
5520 /// For example, pass `--python-version 3.10` to audit the dependencies that would be included
5521 /// when installing on Python 3.10.
5522 ///
5523 /// Defaults to the version of the discovered Python interpreter.
5524 #[arg(long)]
5525 pub python_version: Option<PythonVersion>,
5526
5527 /// The platform to use when auditing.
5528 ///
5529 /// For example, pass `--platform windows` to audit the dependencies that would be included
5530 /// when installing on Windows.
5531 ///
5532 /// Represented as a "target triple", a string that describes the target platform in terms of
5533 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5534 /// `aarch64-apple-darwin`.
5535 #[arg(long)]
5536 pub python_platform: Option<TargetTriple>,
5537
5538 /// Ignore a vulnerability by ID.
5539 ///
5540 /// Vulnerabilities matching any of the provided IDs (including aliases) will be excluded from
5541 /// the audit results.
5542 ///
5543 /// May be provided multiple times.
5544 #[arg(long)]
5545 pub ignore: Vec<String>,
5546
5547 /// Ignore a vulnerability by ID, but only while no fix is available.
5548 ///
5549 /// Vulnerabilities matching any of the provided IDs (including aliases) will be excluded from
5550 /// the audit results as long as they have no known fix versions. Once a fix version becomes
5551 /// available, the vulnerability will be reported again.
5552 ///
5553 /// May be provided multiple times.
5554 #[arg(long)]
5555 pub ignore_until_fixed: Vec<String>,
5556
5557 /// The service format to use for vulnerability lookups.
5558 ///
5559 /// Each service format has a default URL, which can be
5560 /// changed with `--service-url`. The defaults are:
5561 ///
5562 /// * OSV: <https://api.osv.dev/>
5563 #[arg(long, value_enum, default_value = "osv")]
5564 pub service_format: VulnerabilityServiceFormat,
5565
5566 /// The URL to vulnerability service API endpoint.
5567 ///
5568 /// If not provided, the default URL for the selected service will be used.
5569 ///
5570 /// The service needs to use the OSV protocol, unless a different
5571 /// format was requested by `--service-format`.
5572 #[arg(long, value_hint = ValueHint::Url)]
5573 pub service_url: Option<String>,
5574}
5575
5576#[derive(Args)]
5577pub struct AuthNamespace {
5578 #[command(subcommand)]
5579 pub command: AuthCommand,
5580}
5581
5582#[derive(Subcommand)]
5583pub enum AuthCommand {
5584 /// Login to a service
5585 Login(AuthLoginArgs),
5586 /// Logout of a service
5587 Logout(AuthLogoutArgs),
5588 /// Show the authentication token for a service
5589 Token(AuthTokenArgs),
5590 /// Show the path to the uv credentials directory.
5591 ///
5592 /// By default, credentials are stored in the uv data directory at
5593 /// `$XDG_DATA_HOME/uv/credentials` or `$HOME/.local/share/uv/credentials` on Unix and
5594 /// `%APPDATA%\uv\data\credentials` on Windows.
5595 ///
5596 /// The credentials directory may be overridden with `$UV_CREDENTIALS_DIR`.
5597 ///
5598 /// Credentials are only stored in this directory when the plaintext backend is used, as
5599 /// opposed to the native backend, which uses the system keyring.
5600 Dir(AuthDirArgs),
5601 /// Act as a credential helper for external tools.
5602 ///
5603 /// Implements the Bazel credential helper protocol to provide credentials
5604 /// to external tools via JSON over stdin/stdout.
5605 ///
5606 /// This command is typically invoked by external tools.
5607 #[command(hide = true)]
5608 Helper(AuthHelperArgs),
5609}
5610
5611#[derive(Args)]
5612pub struct ToolNamespace {
5613 #[command(subcommand)]
5614 pub command: ToolCommand,
5615}
5616
5617#[derive(Subcommand)]
5618pub enum ToolCommand {
5619 /// Run a command provided by a Python package.
5620 ///
5621 /// By default, the package to install is assumed to match the command name.
5622 ///
5623 /// The name of the command can include an exact version in the format `<package>@<version>`,
5624 /// e.g., `uv tool run ruff@0.3.0`. If more complex version specification is desired or if the
5625 /// command is provided by a different package, use `--from`.
5626 ///
5627 /// `uvx` can be used to invoke Python, e.g., with `uvx python` or `uvx python@<version>`. A
5628 /// Python interpreter will be started in an isolated virtual environment.
5629 ///
5630 /// If the tool was previously installed, i.e., via `uv tool install`, the installed version
5631 /// will be used unless a version is requested or the `--isolated` flag is used.
5632 ///
5633 /// `uvx` is provided as a convenient alias for `uv tool run`, their behavior is identical.
5634 ///
5635 /// If no command is provided, the installed tools are displayed.
5636 ///
5637 /// Packages are installed into an ephemeral virtual environment in the uv cache directory.
5638 #[command(
5639 after_help = "Use `uvx` as a shortcut for `uv tool run`.\n\n\
5640 Use `uv help tool run` for more details.",
5641 after_long_help = ""
5642 )]
5643 Run(ToolRunArgs),
5644 /// Hidden alias for `uv tool run` for the `uvx` command
5645 #[command(
5646 hide = true,
5647 override_usage = "uvx [OPTIONS] [COMMAND]",
5648 about = "Run a command provided by a Python package.",
5649 after_help = "Use `uv help tool run` for more details.",
5650 after_long_help = "",
5651 display_name = "uvx",
5652 long_version = crate::version::uv_self_version()
5653 )]
5654 Uvx(UvxArgs),
5655 /// Install commands provided by a Python package.
5656 ///
5657 /// Packages are installed into an isolated virtual environment in the uv tools directory. The
5658 /// executables are linked the tool executable directory, which is determined according to the
5659 /// XDG standard and can be retrieved with `uv tool dir --bin`.
5660 ///
5661 /// If the tool was previously installed, the existing tool will generally be replaced.
5662 Install(ToolInstallArgs),
5663 /// Upgrade installed tools.
5664 ///
5665 /// If a tool was installed with version constraints, they will be respected on upgrade — to
5666 /// upgrade a tool beyond the originally provided constraints, use `uv tool install` again.
5667 ///
5668 /// If a tool was installed with specific settings, they will be respected on upgraded. For
5669 /// example, if `--prereleases allow` was provided during installation, it will continue to be
5670 /// respected in upgrades.
5671 #[command(alias = "update")]
5672 Upgrade(ToolUpgradeArgs),
5673 /// List installed tools.
5674 #[command(alias = "ls")]
5675 List(ToolListArgs),
5676 /// Uninstall a tool.
5677 Uninstall(ToolUninstallArgs),
5678 /// Ensure that the tool executable directory is on the `PATH`.
5679 ///
5680 /// If the tool executable directory is not present on the `PATH`, uv will attempt to add it to
5681 /// the relevant shell configuration files.
5682 ///
5683 /// If the shell configuration files already include a blurb to add the executable directory to
5684 /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
5685 ///
5686 /// The tool executable directory is determined according to the XDG standard and can be
5687 /// retrieved with `uv tool dir --bin`.
5688 #[command(alias = "ensurepath")]
5689 UpdateShell,
5690 /// Show the path to the uv tools directory.
5691 ///
5692 /// The tools directory is used to store environments and metadata for installed tools.
5693 ///
5694 /// By default, tools are stored in the uv data directory at `$XDG_DATA_HOME/uv/tools` or
5695 /// `$HOME/.local/share/uv/tools` on Unix and `%APPDATA%\uv\data\tools` on Windows.
5696 ///
5697 /// The tool installation directory may be overridden with `$UV_TOOL_DIR`.
5698 ///
5699 /// To instead view the directory uv installs executables into, use the `--bin` flag.
5700 Dir(ToolDirArgs),
5701}
5702
5703#[derive(Args)]
5704pub struct ToolRunArgs {
5705 /// The command to run.
5706 ///
5707 /// WARNING: The documentation for [`Self::command`] is not included in help output
5708 #[command(subcommand)]
5709 pub command: Option<ExternalCommand>,
5710
5711 /// Use the given package to provide the command.
5712 ///
5713 /// By default, the package name is assumed to match the command name.
5714 #[arg(long, value_hint = ValueHint::Other)]
5715 pub from: Option<String>,
5716
5717 /// Run with the given packages installed.
5718 #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5719 pub with: Vec<comma::CommaSeparatedRequirements>,
5720
5721 /// Run with the given packages installed in editable mode
5722 ///
5723 /// When used in a project, these dependencies will be layered on top of the uv tool's
5724 /// environment in a separate, ephemeral environment. These dependencies are allowed to conflict
5725 /// with those specified.
5726 #[arg(long, value_hint = ValueHint::DirPath)]
5727 pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5728
5729 /// Run with the packages listed in the given files.
5730 ///
5731 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5732 /// and `pylock.toml`.
5733 #[arg(
5734 long,
5735 value_delimiter = ',',
5736 value_parser = parse_maybe_file_path,
5737 value_hint = ValueHint::FilePath,
5738 )]
5739 pub with_requirements: Vec<Maybe<PathBuf>>,
5740
5741 /// Constrain versions using the given requirements files.
5742 ///
5743 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5744 /// requirement that's installed. However, including a package in a constraints file will _not_
5745 /// trigger the installation of that package.
5746 ///
5747 /// This is equivalent to pip's `--constraint` option.
5748 #[arg(
5749 long,
5750 short,
5751 alias = "constraint",
5752 env = EnvVars::UV_CONSTRAINT,
5753 value_delimiter = ' ',
5754 value_parser = parse_maybe_file_path,
5755 value_hint = ValueHint::FilePath,
5756 )]
5757 pub constraints: Vec<Maybe<PathBuf>>,
5758
5759 /// Constrain build dependencies using the given requirements files when building source
5760 /// distributions.
5761 ///
5762 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5763 /// requirement that's installed. However, including a package in a constraints file will _not_
5764 /// trigger the installation of that package.
5765 #[arg(
5766 long,
5767 short,
5768 alias = "build-constraint",
5769 env = EnvVars::UV_BUILD_CONSTRAINT,
5770 value_delimiter = ' ',
5771 value_parser = parse_maybe_file_path,
5772 value_hint = ValueHint::FilePath,
5773 )]
5774 pub build_constraints: Vec<Maybe<PathBuf>>,
5775
5776 /// Override versions using the given requirements files.
5777 ///
5778 /// Overrides files are `requirements.txt`-like files that force a specific version of a
5779 /// requirement to be installed, regardless of the requirements declared by any constituent
5780 /// package, and regardless of whether this would be considered an invalid resolution.
5781 ///
5782 /// While constraints are _additive_, in that they're combined with the requirements of the
5783 /// constituent packages, overrides are _absolute_, in that they completely replace the
5784 /// requirements of the constituent packages.
5785 #[arg(
5786 long,
5787 alias = "override",
5788 env = EnvVars::UV_OVERRIDE,
5789 value_delimiter = ' ',
5790 value_parser = parse_maybe_file_path,
5791 value_hint = ValueHint::FilePath,
5792 )]
5793 pub overrides: Vec<Maybe<PathBuf>>,
5794
5795 /// Run the tool in an isolated virtual environment, ignoring any already-installed tools [env:
5796 /// UV_ISOLATED=]
5797 #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5798 pub isolated: bool,
5799
5800 /// Load environment variables from a `.env` file.
5801 ///
5802 /// Can be provided multiple times, with subsequent files overriding values defined in previous
5803 /// files.
5804 #[arg(long, value_delimiter = ' ', env = EnvVars::UV_ENV_FILE, value_hint = ValueHint::FilePath)]
5805 pub env_file: Vec<PathBuf>,
5806
5807 /// Avoid reading environment variables from a `.env` file [env: UV_NO_ENV_FILE=]
5808 #[arg(long, value_parser = clap::builder::BoolishValueParser::new())]
5809 pub no_env_file: bool,
5810
5811 #[command(flatten)]
5812 pub installer: ResolverInstallerArgs,
5813
5814 #[command(flatten)]
5815 pub build: BuildOptionsArgs,
5816
5817 #[command(flatten)]
5818 pub refresh: RefreshArgs,
5819
5820 /// Whether to use Git LFS when adding a dependency from Git.
5821 #[arg(long)]
5822 pub lfs: bool,
5823
5824 /// The Python interpreter to use to build the run environment.
5825 ///
5826 /// See `uv help python` for details on Python discovery and supported request formats.
5827 #[arg(
5828 long,
5829 short,
5830 env = EnvVars::UV_PYTHON,
5831 verbatim_doc_comment,
5832 help_heading = "Python options",
5833 value_parser = parse_maybe_string,
5834 value_hint = ValueHint::Other,
5835 )]
5836 pub python: Option<Maybe<String>>,
5837
5838 /// Whether to show resolver and installer output from any environment modifications [env:
5839 /// UV_SHOW_RESOLUTION=]
5840 ///
5841 /// By default, environment modifications are omitted, but enabled under `--verbose`.
5842 #[arg(long, value_parser = clap::builder::BoolishValueParser::new(), hide = true)]
5843 pub show_resolution: bool,
5844
5845 /// The platform for which requirements should be installed.
5846 ///
5847 /// Represented as a "target triple", a string that describes the target platform in terms of
5848 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
5849 /// `aarch64-apple-darwin`.
5850 ///
5851 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
5852 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5853 ///
5854 /// When targeting iOS, the default minimum version is `13.0`. Use
5855 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
5856 ///
5857 /// When targeting Android, the default minimum Android API level is `24`. Use
5858 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
5859 ///
5860 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
5861 /// platform; as a result, the installed distributions may not be compatible with the _current_
5862 /// platform. Conversely, any distributions that are built from source may be incompatible with
5863 /// the _target_ platform, as they will be built for the _current_ platform. The
5864 /// `--python-platform` option is intended for advanced use cases.
5865 #[arg(long)]
5866 pub python_platform: Option<TargetTriple>,
5867
5868 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
5869 ///
5870 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
5871 /// and will instead use the defined backend.
5872 ///
5873 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
5874 /// uv will use the PyTorch index for CUDA 12.6.
5875 ///
5876 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
5877 /// installed CUDA drivers.
5878 ///
5879 /// This option is in preview and may change in any future release.
5880 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
5881 pub torch_backend: Option<TorchMode>,
5882
5883 #[arg(long, hide = true)]
5884 pub generate_shell_completion: Option<clap_complete_command::Shell>,
5885}
5886
5887#[derive(Args)]
5888pub struct UvxArgs {
5889 #[command(flatten)]
5890 pub tool_run: ToolRunArgs,
5891
5892 /// Display the uvx version.
5893 #[arg(short = 'V', long, action = clap::ArgAction::Version)]
5894 pub version: Option<bool>,
5895}
5896
5897#[derive(Args)]
5898pub struct ToolInstallArgs {
5899 /// The package to install commands from.
5900 #[arg(value_hint = ValueHint::Other)]
5901 pub package: String,
5902
5903 /// The package to install commands from.
5904 ///
5905 /// This option is provided for parity with `uv tool run`, but is redundant with `package`.
5906 #[arg(long, hide = true, value_hint = ValueHint::Other)]
5907 pub from: Option<String>,
5908
5909 /// Include the following additional requirements.
5910 #[arg(short = 'w', long, value_hint = ValueHint::Other)]
5911 pub with: Vec<comma::CommaSeparatedRequirements>,
5912
5913 /// Run with the packages listed in the given files.
5914 ///
5915 /// The following formats are supported: `requirements.txt`, `.py` files with inline metadata,
5916 /// and `pylock.toml`.
5917 #[arg(long, value_delimiter = ',', value_parser = parse_maybe_file_path, value_hint = ValueHint::FilePath)]
5918 pub with_requirements: Vec<Maybe<PathBuf>>,
5919
5920 /// Install the target package in editable mode, such that changes in the package's source
5921 /// directory are reflected without reinstallation.
5922 #[arg(short, long)]
5923 pub editable: bool,
5924
5925 /// Include the given packages in editable mode.
5926 #[arg(long, value_hint = ValueHint::DirPath)]
5927 pub with_editable: Vec<comma::CommaSeparatedRequirements>,
5928
5929 /// Install executables from the following packages.
5930 #[arg(long, value_hint = ValueHint::Other)]
5931 pub with_executables_from: Vec<comma::CommaSeparatedRequirements>,
5932
5933 /// Constrain versions using the given requirements files.
5934 ///
5935 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5936 /// requirement that's installed. However, including a package in a constraints file will _not_
5937 /// trigger the installation of that package.
5938 ///
5939 /// This is equivalent to pip's `--constraint` option.
5940 #[arg(
5941 long,
5942 short,
5943 alias = "constraint",
5944 env = EnvVars::UV_CONSTRAINT,
5945 value_delimiter = ' ',
5946 value_parser = parse_maybe_file_path,
5947 value_hint = ValueHint::FilePath,
5948 )]
5949 pub constraints: Vec<Maybe<PathBuf>>,
5950
5951 /// Override versions using the given requirements files.
5952 ///
5953 /// Overrides files are `requirements.txt`-like files that force a specific version of a
5954 /// requirement to be installed, regardless of the requirements declared by any constituent
5955 /// package, and regardless of whether this would be considered an invalid resolution.
5956 ///
5957 /// While constraints are _additive_, in that they're combined with the requirements of the
5958 /// constituent packages, overrides are _absolute_, in that they completely replace the
5959 /// requirements of the constituent packages.
5960 #[arg(
5961 long,
5962 alias = "override",
5963 env = EnvVars::UV_OVERRIDE,
5964 value_delimiter = ' ',
5965 value_parser = parse_maybe_file_path,
5966 value_hint = ValueHint::FilePath,
5967 )]
5968 pub overrides: Vec<Maybe<PathBuf>>,
5969
5970 /// Exclude packages from resolution using the given requirements files.
5971 ///
5972 /// Excludes files are `requirements.txt`-like files that specify packages to exclude
5973 /// from the resolution. When a package is excluded, it will be omitted from the
5974 /// dependency list entirely and its own dependencies will be ignored during the resolution
5975 /// phase. Excludes are unconditional in that requirement specifiers and markers are ignored;
5976 /// any package listed in the provided file will be omitted from all resolved environments.
5977 #[arg(
5978 long,
5979 alias = "exclude",
5980 env = EnvVars::UV_EXCLUDE,
5981 value_delimiter = ' ',
5982 value_parser = parse_maybe_file_path,
5983 value_hint = ValueHint::FilePath,
5984 )]
5985 pub excludes: Vec<Maybe<PathBuf>>,
5986
5987 /// Constrain build dependencies using the given requirements files when building source
5988 /// distributions.
5989 ///
5990 /// Constraints files are `requirements.txt`-like files that only control the _version_ of a
5991 /// requirement that's installed. However, including a package in a constraints file will _not_
5992 /// trigger the installation of that package.
5993 #[arg(
5994 long,
5995 short,
5996 alias = "build-constraint",
5997 env = EnvVars::UV_BUILD_CONSTRAINT,
5998 value_delimiter = ' ',
5999 value_parser = parse_maybe_file_path,
6000 value_hint = ValueHint::FilePath,
6001 )]
6002 pub build_constraints: Vec<Maybe<PathBuf>>,
6003
6004 #[command(flatten)]
6005 pub installer: ResolverInstallerArgs,
6006
6007 #[command(flatten)]
6008 pub build: BuildOptionsArgs,
6009
6010 #[command(flatten)]
6011 pub refresh: RefreshArgs,
6012
6013 /// Force installation of the tool.
6014 ///
6015 /// Will recreate any existing environment for the tool and replace any existing entry points
6016 /// with the same name in the executable directory.
6017 #[arg(long)]
6018 pub force: bool,
6019
6020 /// Whether to use Git LFS when adding a dependency from Git.
6021 #[arg(long)]
6022 pub lfs: bool,
6023
6024 /// The Python interpreter to use to build the tool environment.
6025 ///
6026 /// See `uv help python` for details on Python discovery and supported request formats.
6027 #[arg(
6028 long,
6029 short,
6030 env = EnvVars::UV_PYTHON,
6031 verbatim_doc_comment,
6032 help_heading = "Python options",
6033 value_parser = parse_maybe_string,
6034 value_hint = ValueHint::Other,
6035 )]
6036 pub python: Option<Maybe<String>>,
6037
6038 /// The platform for which requirements should be installed.
6039 ///
6040 /// Represented as a "target triple", a string that describes the target platform in terms of
6041 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
6042 /// `aarch64-apple-darwin`.
6043 ///
6044 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
6045 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
6046 ///
6047 /// When targeting iOS, the default minimum version is `13.0`. Use
6048 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
6049 ///
6050 /// When targeting Android, the default minimum Android API level is `24`. Use
6051 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
6052 ///
6053 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
6054 /// platform; as a result, the installed distributions may not be compatible with the _current_
6055 /// platform. Conversely, any distributions that are built from source may be incompatible with
6056 /// the _target_ platform, as they will be built for the _current_ platform. The
6057 /// `--python-platform` option is intended for advanced use cases.
6058 #[arg(long)]
6059 pub python_platform: Option<TargetTriple>,
6060
6061 /// The backend to use when fetching packages in the PyTorch ecosystem (e.g., `cpu`, `cu126`, or `auto`)
6062 ///
6063 /// When set, uv will ignore the configured index URLs for packages in the PyTorch ecosystem,
6064 /// and will instead use the defined backend.
6065 ///
6066 /// For example, when set to `cpu`, uv will use the CPU-only PyTorch index; when set to `cu126`,
6067 /// uv will use the PyTorch index for CUDA 12.6.
6068 ///
6069 /// The `auto` mode will attempt to detect the appropriate PyTorch index based on the currently
6070 /// installed CUDA drivers.
6071 ///
6072 /// This option is in preview and may change in any future release.
6073 #[arg(long, value_enum, env = EnvVars::UV_TORCH_BACKEND)]
6074 pub torch_backend: Option<TorchMode>,
6075}
6076
6077#[derive(Args)]
6078pub struct ToolListArgs {
6079 /// Whether to display the path to each tool environment and installed executable.
6080 #[arg(long)]
6081 pub show_paths: bool,
6082
6083 /// Whether to display the version specifier(s) used to install each tool.
6084 #[arg(long)]
6085 pub show_version_specifiers: bool,
6086
6087 /// Whether to display the additional requirements installed with each tool.
6088 #[arg(long)]
6089 pub show_with: bool,
6090
6091 /// Whether to display the extra requirements installed with each tool.
6092 #[arg(long)]
6093 pub show_extras: bool,
6094
6095 /// Whether to display the Python version associated with each tool.
6096 #[arg(long)]
6097 pub show_python: bool,
6098
6099 /// List outdated tools.
6100 ///
6101 /// The latest version of each tool will be shown alongside the installed version. Up-to-date
6102 /// tools will be omitted from the output.
6103 #[arg(long, overrides_with("no_outdated"))]
6104 pub outdated: bool,
6105
6106 #[arg(long, overrides_with("outdated"), hide = true)]
6107 pub no_outdated: bool,
6108
6109 /// Limit candidate packages to those that were uploaded prior to the given date.
6110 ///
6111 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
6112 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
6113 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
6114 /// `P7D`, `P30D`).
6115 ///
6116 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6117 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6118 /// Calendar units such as months and years are not allowed.
6119 ///
6120 /// Use `false` to disable `exclude-newer`.
6121 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6122 pub exclude_newer: Option<ExcludeNewerOverride>,
6123
6124 // Hide unused global Python options.
6125 #[arg(long, hide = true)]
6126 pub python_preference: Option<PythonPreference>,
6127
6128 #[arg(long, hide = true)]
6129 pub no_python_downloads: bool,
6130}
6131
6132#[derive(Args)]
6133pub struct ToolDirArgs {
6134 /// Show the directory into which `uv tool` will install executables.
6135 ///
6136 /// By default, `uv tool dir` shows the directory into which the tool Python environments
6137 /// themselves are installed, rather than the directory containing the linked executables.
6138 ///
6139 /// The tool executable directory is determined according to the XDG standard and is derived
6140 /// from the following environment variables, in order of preference:
6141 ///
6142 /// - `$UV_TOOL_BIN_DIR`
6143 /// - `$XDG_BIN_HOME`
6144 /// - `$XDG_DATA_HOME/../bin`
6145 /// - `$HOME/.local/bin`
6146 #[arg(long, verbatim_doc_comment)]
6147 pub bin: bool,
6148}
6149
6150#[derive(Args)]
6151pub struct ToolUninstallArgs {
6152 /// The name of the tool to uninstall.
6153 #[arg(required = true, value_hint = ValueHint::Other)]
6154 pub name: Vec<PackageName>,
6155
6156 /// Uninstall all tools.
6157 #[arg(long, conflicts_with("name"))]
6158 pub all: bool,
6159}
6160
6161#[derive(Args)]
6162pub struct ToolUpgradeArgs {
6163 /// The name of the tool to upgrade, along with an optional version specifier.
6164 #[arg(required = true, value_hint = ValueHint::Other)]
6165 pub name: Vec<String>,
6166
6167 /// Upgrade all tools.
6168 #[arg(long, conflicts_with("name"))]
6169 pub all: bool,
6170
6171 /// Upgrade a tool, and specify it to use the given Python interpreter to build its environment.
6172 /// Use with `--all` to apply to all tools.
6173 ///
6174 /// See `uv help python` for details on Python discovery and supported request formats.
6175 #[arg(
6176 long,
6177 short,
6178 env = EnvVars::UV_PYTHON,
6179 verbatim_doc_comment,
6180 help_heading = "Python options",
6181 value_parser = parse_maybe_string,
6182 value_hint = ValueHint::Other,
6183 )]
6184 pub python: Option<Maybe<String>>,
6185
6186 /// The platform for which requirements should be installed.
6187 ///
6188 /// Represented as a "target triple", a string that describes the target platform in terms of
6189 /// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
6190 /// `aarch64-apple-darwin`.
6191 ///
6192 /// When targeting macOS (Darwin), the default minimum version is `13.0`. Use
6193 /// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
6194 ///
6195 /// When targeting iOS, the default minimum version is `13.0`. Use
6196 /// `IPHONEOS_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `14.0`.
6197 ///
6198 /// When targeting Android, the default minimum Android API level is `24`. Use
6199 /// `ANDROID_API_LEVEL` to specify a different minimum version, e.g., `26`.
6200 ///
6201 /// WARNING: When specified, uv will select wheels that are compatible with the _target_
6202 /// platform; as a result, the installed distributions may not be compatible with the _current_
6203 /// platform. Conversely, any distributions that are built from source may be incompatible with
6204 /// the _target_ platform, as they will be built for the _current_ platform. The
6205 /// `--python-platform` option is intended for advanced use cases.
6206 #[arg(long)]
6207 pub python_platform: Option<TargetTriple>,
6208
6209 // The following is equivalent to flattening `ResolverInstallerArgs`, with the `--upgrade`,
6210 // `--upgrade-package`, and `--upgrade-group` options hidden, and the `--no-upgrade` option
6211 // removed.
6212 /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
6213 /// `--refresh`.
6214 #[arg(hide = true, long, short = 'U', help_heading = "Resolver options")]
6215 pub upgrade: bool,
6216
6217 /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
6218 /// file. Implies `--refresh-package`.
6219 #[arg(hide = true, long, short = 'P', help_heading = "Resolver options")]
6220 pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
6221
6222 /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
6223 /// existing output file.
6224 #[arg(hide = true, long, help_heading = "Resolver options")]
6225 pub upgrade_group: Vec<GroupName>,
6226
6227 #[command(flatten)]
6228 pub index_args: IndexArgs,
6229
6230 /// Reinstall all packages, regardless of whether they're already installed. Implies
6231 /// `--refresh`.
6232 #[arg(
6233 long,
6234 alias = "force-reinstall",
6235 overrides_with("no_reinstall"),
6236 help_heading = "Installer options"
6237 )]
6238 pub reinstall: bool,
6239
6240 #[arg(
6241 long,
6242 overrides_with("reinstall"),
6243 hide = true,
6244 help_heading = "Installer options"
6245 )]
6246 pub no_reinstall: bool,
6247
6248 /// Reinstall a specific package, regardless of whether it's already installed. Implies
6249 /// `--refresh-package`.
6250 #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
6251 pub reinstall_package: Vec<PackageName>,
6252
6253 /// The strategy to use when resolving against multiple index URLs.
6254 ///
6255 /// By default, uv will stop at the first index on which a given package is available, and limit
6256 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
6257 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
6258 /// to an alternate index.
6259 #[arg(
6260 long,
6261 value_enum,
6262 env = EnvVars::UV_INDEX_STRATEGY,
6263 help_heading = "Index options"
6264 )]
6265 pub index_strategy: Option<IndexStrategy>,
6266
6267 /// Attempt to use `keyring` for authentication for index URLs.
6268 ///
6269 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
6270 /// the `keyring` CLI to handle authentication.
6271 ///
6272 /// Defaults to `disabled`.
6273 #[arg(
6274 long,
6275 value_enum,
6276 env = EnvVars::UV_KEYRING_PROVIDER,
6277 help_heading = "Index options"
6278 )]
6279 pub keyring_provider: Option<KeyringProviderType>,
6280
6281 /// The strategy to use when selecting between the different compatible versions for a given
6282 /// package requirement.
6283 ///
6284 /// By default, uv will use the latest compatible version of each package (`highest`).
6285 #[arg(
6286 long,
6287 value_enum,
6288 env = EnvVars::UV_RESOLUTION,
6289 help_heading = "Resolver options"
6290 )]
6291 pub resolution: Option<ResolutionMode>,
6292
6293 /// The strategy to use when considering pre-release versions.
6294 ///
6295 /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
6296 /// with first-party requirements that contain an explicit pre-release marker in the declared
6297 /// specifiers (`if-necessary-or-explicit`).
6298 #[arg(
6299 long,
6300 value_enum,
6301 env = EnvVars::UV_PRERELEASE,
6302 help_heading = "Resolver options"
6303 )]
6304 pub prerelease: Option<PrereleaseMode>,
6305
6306 #[arg(long, hide = true)]
6307 pub pre: bool,
6308
6309 /// The strategy to use when selecting multiple versions of a given package across Python
6310 /// versions and platforms.
6311 ///
6312 /// By default, uv will optimize for selecting the latest version of each package for each
6313 /// supported Python version (`requires-python`), while minimizing the number of selected
6314 /// versions across platforms.
6315 ///
6316 /// Under `fewest`, uv will minimize the number of selected versions for each package,
6317 /// preferring older versions that are compatible with a wider range of supported Python
6318 /// versions or platforms.
6319 #[arg(
6320 long,
6321 value_enum,
6322 env = EnvVars::UV_FORK_STRATEGY,
6323 help_heading = "Resolver options"
6324 )]
6325 pub fork_strategy: Option<ForkStrategy>,
6326
6327 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
6328 #[arg(
6329 long,
6330 short = 'C',
6331 alias = "config-settings",
6332 help_heading = "Build options"
6333 )]
6334 pub config_setting: Option<Vec<ConfigSettingEntry>>,
6335
6336 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
6337 #[arg(
6338 long,
6339 alias = "config-settings-package",
6340 help_heading = "Build options"
6341 )]
6342 pub config_setting_package: Option<Vec<ConfigSettingPackageEntry>>,
6343
6344 /// Disable isolation when building source distributions.
6345 ///
6346 /// Assumes that build dependencies specified by PEP 518 are already installed.
6347 #[arg(
6348 long,
6349 overrides_with("build_isolation"),
6350 help_heading = "Build options",
6351 env = EnvVars::UV_NO_BUILD_ISOLATION,
6352 value_parser = clap::builder::BoolishValueParser::new(),
6353 )]
6354 pub no_build_isolation: bool,
6355
6356 /// Disable isolation when building source distributions for a specific package.
6357 ///
6358 /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
6359 #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
6360 pub no_build_isolation_package: Vec<PackageName>,
6361
6362 #[arg(
6363 long,
6364 overrides_with("no_build_isolation"),
6365 hide = true,
6366 help_heading = "Build options"
6367 )]
6368 pub build_isolation: bool,
6369
6370 /// Limit candidate packages to those that were uploaded prior to the given date.
6371 ///
6372 /// The date is compared against the upload time of each individual distribution artifact
6373 /// (i.e., when each file was uploaded to the package index), not the release date of the
6374 /// package version.
6375 ///
6376 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
6377 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
6378 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
6379 /// `P7D`, `P30D`).
6380 ///
6381 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6382 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6383 /// Calendar units such as months and years are not allowed.
6384 ///
6385 /// Use `false` to disable `exclude-newer`.
6386 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
6387 pub exclude_newer: Option<ExcludeNewerOverride>,
6388
6389 /// Limit candidate packages for specific packages to those that were uploaded prior to the
6390 /// given date.
6391 ///
6392 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
6393 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
6394 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
6395 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
6396 /// `P30D`).
6397 ///
6398 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
6399 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
6400 /// Calendar units such as months and years are not allowed.
6401 ///
6402 /// Can be provided multiple times for different packages.
6403 #[arg(long, help_heading = "Resolver options")]
6404 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
6405
6406 /// The method to use when installing packages from the global cache.
6407 ///
6408 /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
6409 /// Windows.
6410 ///
6411 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
6412 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
6413 /// will break all installed packages by way of removing the underlying source files. Use
6414 /// symlinks with caution.
6415 #[arg(
6416 long,
6417 value_enum,
6418 env = EnvVars::UV_LINK_MODE,
6419 help_heading = "Installer options"
6420 )]
6421 pub link_mode: Option<uv_install_wheel::LinkMode>,
6422
6423 /// Compile Python files to bytecode after installation.
6424 ///
6425 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6426 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6427 /// in which start time is critical, such as CLI applications and Docker containers, this option
6428 /// can be enabled to trade longer installation times for faster start times.
6429 ///
6430 /// When enabled, uv will process the entire site-packages directory (including packages that
6431 /// are not being modified by the current operation) for consistency. Like pip, it will also
6432 /// ignore errors.
6433 #[arg(
6434 long,
6435 alias = "compile",
6436 overrides_with("no_compile_bytecode"),
6437 help_heading = "Installer options",
6438 env = EnvVars::UV_COMPILE_BYTECODE,
6439 value_parser = clap::builder::BoolishValueParser::new(),
6440 )]
6441 pub compile_bytecode: bool,
6442
6443 #[arg(
6444 long,
6445 alias = "no-compile",
6446 overrides_with("compile_bytecode"),
6447 hide = true,
6448 help_heading = "Installer options"
6449 )]
6450 pub no_compile_bytecode: bool,
6451
6452 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
6453 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
6454 /// URL, or local path sources.
6455 #[arg(
6456 long,
6457 env = EnvVars::UV_NO_SOURCES,
6458 value_parser = clap::builder::BoolishValueParser::new(),
6459 help_heading = "Resolver options",
6460 )]
6461 pub no_sources: bool,
6462
6463 /// Don't use sources from the `tool.uv.sources` table for the specified packages [env: `UV_NO_SOURCES_PACKAGE`=]
6464 #[arg(long, help_heading = "Resolver options", value_delimiter = ' ')]
6465 pub no_sources_package: Vec<PackageName>,
6466
6467 #[command(flatten)]
6468 pub build: BuildOptionsArgs,
6469}
6470
6471#[derive(Args)]
6472pub struct PythonNamespace {
6473 #[command(subcommand)]
6474 pub command: PythonCommand,
6475}
6476
6477#[derive(Subcommand)]
6478pub enum PythonCommand {
6479 /// List the available Python installations.
6480 ///
6481 /// By default, installed Python versions and the downloads for latest available patch version
6482 /// of each supported Python major version are shown.
6483 ///
6484 /// Use `--managed-python` to view only managed Python versions.
6485 ///
6486 /// Use `--no-managed-python` to omit managed Python versions.
6487 ///
6488 /// Use `--all-versions` to view all available patch versions.
6489 ///
6490 /// Use `--only-installed` to omit available downloads.
6491 #[command(alias = "ls")]
6492 List(PythonListArgs),
6493
6494 /// Download and install Python versions.
6495 ///
6496 /// Supports CPython and PyPy. CPython distributions are downloaded from the Astral
6497 /// `python-build-standalone` project. PyPy distributions are downloaded from `python.org`. The
6498 /// available Python versions are bundled with each uv release. To install new Python versions,
6499 /// you may need upgrade uv.
6500 ///
6501 /// Python versions are installed into the uv Python directory, which can be retrieved with `uv
6502 /// python dir`.
6503 ///
6504 /// By default, Python executables are added to a directory on the path with a minor version
6505 /// suffix, e.g., `python3.13`. To install `python3` and `python`, use the `--default` flag. Use
6506 /// `uv python dir --bin` to see the target directory.
6507 ///
6508 /// Multiple Python versions may be requested.
6509 ///
6510 /// See `uv help python` to view supported request formats.
6511 Install(PythonInstallArgs),
6512
6513 /// Upgrade installed Python versions.
6514 ///
6515 /// Upgrades versions to the latest supported patch release. Requires the `python-upgrade`
6516 /// preview feature.
6517 ///
6518 /// A target Python minor version to upgrade may be provided, e.g., `3.13`. Multiple versions
6519 /// may be provided to perform more than one upgrade.
6520 ///
6521 /// If no target version is provided, then uv will upgrade all managed CPython versions.
6522 ///
6523 /// During an upgrade, uv will not uninstall outdated patch versions.
6524 ///
6525 /// When an upgrade is performed, virtual environments created by uv will automatically
6526 /// use the new version. However, if the virtual environment was created before the
6527 /// upgrade functionality was added, it will continue to use the old Python version; to enable
6528 /// upgrades, the environment must be recreated.
6529 ///
6530 /// Upgrades are not yet supported for alternative implementations, like PyPy.
6531 Upgrade(PythonUpgradeArgs),
6532
6533 /// Search for a Python installation.
6534 ///
6535 /// Displays the path to the Python executable.
6536 ///
6537 /// See `uv help python` to view supported request formats and details on discovery behavior.
6538 Find(PythonFindArgs),
6539
6540 /// Pin to a specific Python version.
6541 ///
6542 /// Writes the pinned Python version to a `.python-version` file, which is used by other uv
6543 /// commands to determine the required Python version.
6544 ///
6545 /// If no version is provided, uv will look for an existing `.python-version` file and display
6546 /// the currently pinned version. If no `.python-version` file is found, uv will exit with an
6547 /// error.
6548 ///
6549 /// See `uv help python` to view supported request formats.
6550 Pin(PythonPinArgs),
6551
6552 /// Show the uv Python installation directory.
6553 ///
6554 /// By default, Python installations are stored in the uv data directory at
6555 /// `$XDG_DATA_HOME/uv/python` or `$HOME/.local/share/uv/python` on Unix and
6556 /// `%APPDATA%\uv\data\python` on Windows.
6557 ///
6558 /// The Python installation directory may be overridden with `$UV_PYTHON_INSTALL_DIR`.
6559 ///
6560 /// To view the directory where uv installs Python executables instead, use the `--bin` flag.
6561 /// The Python executable directory may be overridden with `$UV_PYTHON_BIN_DIR`. Note that
6562 /// Python executables are only installed when preview mode is enabled.
6563 Dir(PythonDirArgs),
6564
6565 /// Uninstall Python versions.
6566 Uninstall(PythonUninstallArgs),
6567
6568 /// Ensure that the Python executable directory is on the `PATH`.
6569 ///
6570 /// If the Python executable directory is not present on the `PATH`, uv will attempt to add it to
6571 /// the relevant shell configuration files.
6572 ///
6573 /// If the shell configuration files already include a blurb to add the executable directory to
6574 /// the path, but the directory is not present on the `PATH`, uv will exit with an error.
6575 ///
6576 /// The Python executable directory is determined according to the XDG standard and can be
6577 /// retrieved with `uv python dir --bin`.
6578 #[command(alias = "ensurepath")]
6579 UpdateShell,
6580}
6581
6582#[derive(Args)]
6583pub struct PythonListArgs {
6584 /// A Python request to filter by.
6585 ///
6586 /// See `uv help python` to view supported request formats.
6587 pub request: Option<String>,
6588
6589 /// List all Python versions, including old patch versions.
6590 ///
6591 /// By default, only the latest patch version is shown for each minor version.
6592 #[arg(long)]
6593 pub all_versions: bool,
6594
6595 /// List Python downloads for all platforms.
6596 ///
6597 /// By default, only downloads for the current platform are shown.
6598 #[arg(long)]
6599 pub all_platforms: bool,
6600
6601 /// List Python downloads for all architectures.
6602 ///
6603 /// By default, only downloads for the current architecture are shown.
6604 #[arg(long, alias = "all_architectures")]
6605 pub all_arches: bool,
6606
6607 /// Only show installed Python versions.
6608 ///
6609 /// By default, installed distributions and available downloads for the current platform are shown.
6610 #[arg(long, conflicts_with("only_downloads"))]
6611 pub only_installed: bool,
6612
6613 /// Only show available Python downloads.
6614 ///
6615 /// By default, installed distributions and available downloads for the current platform are shown.
6616 #[arg(long, conflicts_with("only_installed"))]
6617 pub only_downloads: bool,
6618
6619 /// Show the URLs of available Python downloads.
6620 ///
6621 /// By default, these display as `<download available>`.
6622 #[arg(long)]
6623 pub show_urls: bool,
6624
6625 /// Select the output format.
6626 #[arg(long, value_enum, default_value_t = PythonListFormat::default())]
6627 pub output_format: PythonListFormat,
6628
6629 /// URL pointing to JSON of custom Python installations.
6630 #[arg(long, value_hint = ValueHint::Other)]
6631 pub python_downloads_json_url: Option<String>,
6632}
6633
6634#[derive(Args)]
6635pub struct PythonDirArgs {
6636 /// Show the directory into which `uv python` will install Python executables.
6637 ///
6638 /// Note that this directory is only used when installing Python with preview mode enabled.
6639 ///
6640 /// The Python executable directory is determined according to the XDG standard and is derived
6641 /// from the following environment variables, in order of preference:
6642 ///
6643 /// - `$UV_PYTHON_BIN_DIR`
6644 /// - `$XDG_BIN_HOME`
6645 /// - `$XDG_DATA_HOME/../bin`
6646 /// - `$HOME/.local/bin`
6647 #[arg(long, verbatim_doc_comment)]
6648 pub bin: bool,
6649}
6650
6651#[derive(Args)]
6652pub struct PythonInstallCompileBytecodeArgs {
6653 /// Compile Python's standard library to bytecode after installation.
6654 ///
6655 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
6656 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
6657 /// in which start time is important, such as CLI applications and Docker containers, this
6658 /// option can be enabled to trade longer installation times and some additional disk space for
6659 /// faster start times.
6660 ///
6661 /// When enabled, uv will process the Python version's `stdlib` directory. It will ignore any
6662 /// compilation errors.
6663 #[arg(
6664 long,
6665 alias = "compile",
6666 overrides_with("no_compile_bytecode"),
6667 env = EnvVars::UV_COMPILE_BYTECODE,
6668 value_parser = clap::builder::BoolishValueParser::new(),
6669 )]
6670 pub compile_bytecode: bool,
6671
6672 #[arg(
6673 long,
6674 alias = "no-compile",
6675 overrides_with("compile_bytecode"),
6676 hide = true
6677 )]
6678 pub no_compile_bytecode: bool,
6679}
6680
6681#[derive(Args)]
6682pub struct PythonInstallArgs {
6683 /// The directory to store the Python installation in.
6684 ///
6685 /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6686 /// discover the Python installation.
6687 ///
6688 /// See `uv python dir` to view the current Python installation directory. Defaults to
6689 /// `~/.local/share/uv/python`.
6690 #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6691 pub install_dir: Option<PathBuf>,
6692
6693 /// Install a Python executable into the `bin` directory.
6694 ///
6695 /// This is the default behavior. If this flag is provided explicitly, uv will error if the
6696 /// executable cannot be installed.
6697 ///
6698 /// This can also be set with `UV_PYTHON_INSTALL_BIN=1`.
6699 ///
6700 /// See `UV_PYTHON_BIN_DIR` to customize the target directory.
6701 #[arg(long, overrides_with("no_bin"), hide = true)]
6702 pub bin: bool,
6703
6704 /// Do not install a Python executable into the `bin` directory.
6705 ///
6706 /// This can also be set with `UV_PYTHON_INSTALL_BIN=0`.
6707 #[arg(long, overrides_with("bin"), conflicts_with("default"))]
6708 pub no_bin: bool,
6709
6710 /// Register the Python installation in the Windows registry.
6711 ///
6712 /// This is the default behavior on Windows. If this flag is provided explicitly, uv will error if the
6713 /// registry entry cannot be created.
6714 ///
6715 /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=1`.
6716 #[arg(long, overrides_with("no_registry"), hide = true)]
6717 pub registry: bool,
6718
6719 /// Do not register the Python installation in the Windows registry.
6720 ///
6721 /// This can also be set with `UV_PYTHON_INSTALL_REGISTRY=0`.
6722 #[arg(long, overrides_with("registry"))]
6723 pub no_registry: bool,
6724
6725 /// The Python version(s) to install.
6726 ///
6727 /// If not provided, the requested Python version(s) will be read from the `UV_PYTHON`
6728 /// environment variable then `.python-versions` or `.python-version` files. If none of the
6729 /// above are present, uv will check if it has installed any Python versions. If not, it will
6730 /// install the latest stable version of Python.
6731 ///
6732 /// See `uv help python` to view supported request formats.
6733 #[arg(env = EnvVars::UV_PYTHON)]
6734 pub targets: Vec<String>,
6735
6736 /// Set the URL to use as the source for downloading Python installations.
6737 ///
6738 /// The provided URL will replace
6739 /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6740 /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6741 ///
6742 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6743 #[arg(long, value_hint = ValueHint::Url)]
6744 pub mirror: Option<String>,
6745
6746 /// Set the URL to use as the source for downloading PyPy installations.
6747 ///
6748 /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6749 /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6750 ///
6751 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6752 #[arg(long, value_hint = ValueHint::Url)]
6753 pub pypy_mirror: Option<String>,
6754
6755 /// URL pointing to JSON of custom Python installations.
6756 #[arg(long, value_hint = ValueHint::Other)]
6757 pub python_downloads_json_url: Option<String>,
6758
6759 /// Reinstall the requested Python version, if it's already installed.
6760 ///
6761 /// By default, uv will exit successfully if the version is already
6762 /// installed.
6763 #[arg(long, short)]
6764 pub reinstall: bool,
6765
6766 /// Replace existing Python executables during installation.
6767 ///
6768 /// By default, uv will refuse to replace executables that it does not manage.
6769 ///
6770 /// Implies `--reinstall`.
6771 #[arg(long, short)]
6772 pub force: bool,
6773
6774 /// Upgrade existing Python installations to the latest patch version.
6775 ///
6776 /// By default, uv will not upgrade already-installed Python versions to newer patch releases.
6777 /// With `--upgrade`, uv will upgrade to the latest available patch version for the specified
6778 /// minor version(s).
6779 ///
6780 /// If the requested versions are not yet installed, uv will install them.
6781 ///
6782 /// This option is only supported for minor version requests, e.g., `3.12`; uv will exit with an
6783 /// error if a patch version, e.g., `3.12.2`, is requested.
6784 #[arg(long, short = 'U')]
6785 pub upgrade: bool,
6786
6787 /// Use as the default Python version.
6788 ///
6789 /// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
6790 /// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
6791 /// also installed.
6792 ///
6793 /// Alternative Python variants will still include their tag. For example, installing
6794 /// 3.13+freethreaded with `--default` will include `python3t` and `pythont` instead of
6795 /// `python3` and `python`.
6796 ///
6797 /// If multiple Python versions are requested, uv will exit with an error.
6798 #[arg(long, conflicts_with("no_bin"))]
6799 pub default: bool,
6800
6801 #[command(flatten)]
6802 pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6803}
6804
6805impl PythonInstallArgs {
6806 #[must_use]
6807 pub fn install_mirrors(&self) -> PythonInstallMirrors {
6808 PythonInstallMirrors {
6809 python_install_mirror: self.mirror.clone(),
6810 pypy_install_mirror: self.pypy_mirror.clone(),
6811 python_downloads_json_url: self.python_downloads_json_url.clone(),
6812 }
6813 }
6814}
6815
6816#[derive(Args)]
6817pub struct PythonUpgradeArgs {
6818 /// The directory Python installations are stored in.
6819 ///
6820 /// If provided, `UV_PYTHON_INSTALL_DIR` will need to be set for subsequent operations for uv to
6821 /// discover the Python installation.
6822 ///
6823 /// See `uv python dir` to view the current Python installation directory. Defaults to
6824 /// `~/.local/share/uv/python`.
6825 #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6826 pub install_dir: Option<PathBuf>,
6827
6828 /// The Python minor version(s) to upgrade.
6829 ///
6830 /// If no target version is provided, then uv will upgrade all managed CPython versions.
6831 #[arg(env = EnvVars::UV_PYTHON)]
6832 pub targets: Vec<String>,
6833
6834 /// Set the URL to use as the source for downloading Python installations.
6835 ///
6836 /// The provided URL will replace
6837 /// `https://github.com/astral-sh/python-build-standalone/releases/download` in, e.g.,
6838 /// `https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz`.
6839 ///
6840 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6841 #[arg(long, value_hint = ValueHint::Url)]
6842 pub mirror: Option<String>,
6843
6844 /// Set the URL to use as the source for downloading PyPy installations.
6845 ///
6846 /// The provided URL will replace `https://downloads.python.org/pypy` in, e.g.,
6847 /// `https://downloads.python.org/pypy/pypy3.8-v7.3.7-osx64.tar.bz2`.
6848 ///
6849 /// Distributions can be read from a local directory by using the `file://` URL scheme.
6850 #[arg(long, value_hint = ValueHint::Url)]
6851 pub pypy_mirror: Option<String>,
6852
6853 /// Reinstall the latest Python patch, if it's already installed.
6854 ///
6855 /// By default, uv will exit successfully if the latest patch is already
6856 /// installed.
6857 #[arg(long, short)]
6858 pub reinstall: bool,
6859
6860 /// URL pointing to JSON of custom Python installations.
6861 #[arg(long, value_hint = ValueHint::Other)]
6862 pub python_downloads_json_url: Option<String>,
6863
6864 #[command(flatten)]
6865 pub compile_bytecode: PythonInstallCompileBytecodeArgs,
6866}
6867
6868impl PythonUpgradeArgs {
6869 #[must_use]
6870 pub fn install_mirrors(&self) -> PythonInstallMirrors {
6871 PythonInstallMirrors {
6872 python_install_mirror: self.mirror.clone(),
6873 pypy_install_mirror: self.pypy_mirror.clone(),
6874 python_downloads_json_url: self.python_downloads_json_url.clone(),
6875 }
6876 }
6877}
6878
6879#[derive(Args)]
6880pub struct PythonUninstallArgs {
6881 /// The directory where the Python was installed.
6882 #[arg(long, short, env = EnvVars::UV_PYTHON_INSTALL_DIR, value_hint = ValueHint::DirPath)]
6883 pub install_dir: Option<PathBuf>,
6884
6885 /// The Python version(s) to uninstall.
6886 ///
6887 /// See `uv help python` to view supported request formats.
6888 #[arg(required = true)]
6889 pub targets: Vec<String>,
6890
6891 /// Uninstall all managed Python versions.
6892 #[arg(long, conflicts_with("targets"))]
6893 pub all: bool,
6894}
6895
6896#[derive(Args)]
6897pub struct PythonFindArgs {
6898 /// The Python request.
6899 ///
6900 /// See `uv help python` to view supported request formats.
6901 pub request: Option<String>,
6902
6903 /// Avoid discovering a project or workspace.
6904 ///
6905 /// Otherwise, when no request is provided, the Python requirement of a project in the current
6906 /// directory or parent directories will be used.
6907 #[arg(
6908 long,
6909 alias = "no_workspace",
6910 env = EnvVars::UV_NO_PROJECT,
6911 value_parser = clap::builder::BoolishValueParser::new()
6912 )]
6913 pub no_project: bool,
6914
6915 /// Only find system Python interpreters.
6916 ///
6917 /// By default, uv will report the first Python interpreter it would use, including those in an
6918 /// active virtual environment or a virtual environment in the current working directory or any
6919 /// parent directory.
6920 ///
6921 /// The `--system` option instructs uv to skip virtual environment Python interpreters and
6922 /// restrict its search to the system path.
6923 #[arg(
6924 long,
6925 env = EnvVars::UV_SYSTEM_PYTHON,
6926 value_parser = clap::builder::BoolishValueParser::new(),
6927 overrides_with("no_system")
6928 )]
6929 pub system: bool,
6930
6931 #[arg(long, overrides_with("system"), hide = true)]
6932 pub no_system: bool,
6933
6934 /// Find the environment for a Python script, rather than the current project.
6935 #[arg(
6936 long,
6937 conflicts_with = "request",
6938 conflicts_with = "no_project",
6939 conflicts_with = "system",
6940 conflicts_with = "no_system",
6941 value_hint = ValueHint::FilePath,
6942 )]
6943 pub script: Option<PathBuf>,
6944
6945 /// Show the Python version that would be used instead of the path to the interpreter.
6946 #[arg(long)]
6947 pub show_version: bool,
6948
6949 /// Resolve symlinks in the output path.
6950 ///
6951 /// When enabled, the output path will be canonicalized, resolving any symlinks.
6952 #[arg(long)]
6953 pub resolve_links: bool,
6954
6955 /// URL pointing to JSON of custom Python installations.
6956 #[arg(long, value_hint = ValueHint::Other)]
6957 pub python_downloads_json_url: Option<String>,
6958}
6959
6960#[derive(Args)]
6961pub struct PythonPinArgs {
6962 /// The Python version request.
6963 ///
6964 /// uv supports more formats than other tools that read `.python-version` files, i.e., `pyenv`.
6965 /// If compatibility with those tools is needed, only use version numbers instead of complex
6966 /// requests such as `cpython@3.10`.
6967 ///
6968 /// If no request is provided, the currently pinned version will be shown.
6969 ///
6970 /// See `uv help python` to view supported request formats.
6971 pub request: Option<String>,
6972
6973 /// Write the resolved Python interpreter path instead of the request.
6974 ///
6975 /// Ensures that the exact same interpreter is used.
6976 ///
6977 /// This option is usually not safe to use when committing the `.python-version` file to version
6978 /// control.
6979 #[arg(long, overrides_with("resolved"))]
6980 pub resolved: bool,
6981
6982 #[arg(long, overrides_with("no_resolved"), hide = true)]
6983 pub no_resolved: bool,
6984
6985 /// Avoid validating the Python pin is compatible with the project or workspace.
6986 ///
6987 /// By default, a project or workspace is discovered in the current directory or any parent
6988 /// directory. If a workspace is found, the Python pin is validated against the workspace's
6989 /// `requires-python` constraint.
6990 #[arg(
6991 long,
6992 alias = "no-workspace",
6993 env = EnvVars::UV_NO_PROJECT,
6994 value_parser = clap::builder::BoolishValueParser::new()
6995 )]
6996 pub no_project: bool,
6997
6998 /// Update the global Python version pin.
6999 ///
7000 /// Writes the pinned Python version to a `.python-version` file in the uv user configuration
7001 /// directory: `XDG_CONFIG_HOME/uv` on Linux/macOS and `%APPDATA%/uv` on Windows.
7002 ///
7003 /// When a local Python version pin is not found in the working directory or an ancestor
7004 /// directory, this version will be used instead.
7005 #[arg(long)]
7006 pub global: bool,
7007
7008 /// Remove the Python version pin.
7009 #[arg(long, conflicts_with = "request", conflicts_with = "resolved")]
7010 pub rm: bool,
7011
7012 /// URL pointing to JSON of custom Python installations.
7013 #[arg(long, value_hint = ValueHint::Other)]
7014 pub python_downloads_json_url: Option<String>,
7015}
7016
7017#[derive(Args)]
7018pub struct AuthLogoutArgs {
7019 /// The domain or URL of the service to logout from.
7020 pub service: Service,
7021
7022 /// The username to logout.
7023 #[arg(long, short, value_hint = ValueHint::Other)]
7024 pub username: Option<String>,
7025
7026 /// The keyring provider to use for storage of credentials.
7027 ///
7028 /// Only `--keyring-provider native` is supported for `logout`, which uses the system keyring
7029 /// via an integration built into uv.
7030 #[arg(
7031 long,
7032 value_enum,
7033 env = EnvVars::UV_KEYRING_PROVIDER,
7034 )]
7035 pub keyring_provider: Option<KeyringProviderType>,
7036}
7037
7038#[derive(Args)]
7039pub struct AuthLoginArgs {
7040 /// The domain or URL of the service to log into.
7041 #[arg(value_hint = ValueHint::Url)]
7042 pub service: Service,
7043
7044 /// The username to use for the service.
7045 #[arg(long, short, conflicts_with = "token", value_hint = ValueHint::Other)]
7046 pub username: Option<String>,
7047
7048 /// The password to use for the service.
7049 ///
7050 /// Use `-` to read the password from stdin.
7051 #[arg(long, conflicts_with = "token", value_hint = ValueHint::Other)]
7052 pub password: Option<String>,
7053
7054 /// The token to use for the service.
7055 ///
7056 /// The username will be set to `__token__`.
7057 ///
7058 /// Use `-` to read the token from stdin.
7059 #[arg(long, short, conflicts_with = "username", conflicts_with = "password", value_hint = ValueHint::Other)]
7060 pub token: Option<String>,
7061
7062 /// The keyring provider to use for storage of credentials.
7063 ///
7064 /// Only `--keyring-provider native` is supported for `login`, which uses the system keyring via
7065 /// an integration built into uv.
7066 #[arg(
7067 long,
7068 value_enum,
7069 env = EnvVars::UV_KEYRING_PROVIDER,
7070 )]
7071 pub keyring_provider: Option<KeyringProviderType>,
7072}
7073
7074#[derive(Args)]
7075pub struct AuthTokenArgs {
7076 /// The domain or URL of the service to lookup.
7077 #[arg(value_hint = ValueHint::Url)]
7078 pub service: Service,
7079
7080 /// The username to lookup.
7081 #[arg(long, short, value_hint = ValueHint::Other)]
7082 pub username: Option<String>,
7083
7084 /// The keyring provider to use for reading credentials.
7085 #[arg(
7086 long,
7087 value_enum,
7088 env = EnvVars::UV_KEYRING_PROVIDER,
7089 )]
7090 pub keyring_provider: Option<KeyringProviderType>,
7091}
7092
7093#[derive(Args)]
7094pub struct AuthDirArgs {
7095 /// The domain or URL of the service to lookup.
7096 #[arg(value_hint = ValueHint::Url)]
7097 pub service: Option<Service>,
7098}
7099
7100#[derive(Args)]
7101pub struct AuthHelperArgs {
7102 #[command(subcommand)]
7103 pub command: AuthHelperCommand,
7104
7105 /// The credential helper protocol to use
7106 #[arg(long, value_enum, required = true)]
7107 pub protocol: AuthHelperProtocol,
7108}
7109
7110/// Credential helper protocols supported by uv
7111#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::ValueEnum)]
7112pub enum AuthHelperProtocol {
7113 /// Bazel credential helper protocol as described in [the
7114 /// spec](https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md)
7115 Bazel,
7116}
7117
7118#[derive(Subcommand)]
7119pub enum AuthHelperCommand {
7120 /// Retrieve credentials for a URI
7121 Get,
7122}
7123
7124#[derive(Args)]
7125pub struct GenerateShellCompletionArgs {
7126 /// The shell to generate the completion script for
7127 pub shell: clap_complete_command::Shell,
7128
7129 // Hide unused global options.
7130 #[arg(long, short, hide = true)]
7131 pub no_cache: bool,
7132 #[arg(long, hide = true)]
7133 pub cache_dir: Option<PathBuf>,
7134
7135 #[arg(long, hide = true)]
7136 pub python_preference: Option<PythonPreference>,
7137 #[arg(long, hide = true)]
7138 pub no_python_downloads: bool,
7139
7140 #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "verbose", hide = true)]
7141 pub quiet: u8,
7142 #[arg(long, short, action = clap::ArgAction::Count, conflicts_with = "quiet", hide = true)]
7143 pub verbose: u8,
7144 #[arg(long, conflicts_with = "no_color", hide = true)]
7145 pub color: Option<ColorChoice>,
7146 #[arg(long, hide = true)]
7147 pub native_tls: bool,
7148 #[arg(long, hide = true)]
7149 pub offline: bool,
7150 #[arg(long, hide = true)]
7151 pub no_progress: bool,
7152 #[arg(long, hide = true)]
7153 pub config_file: Option<PathBuf>,
7154 #[arg(long, hide = true)]
7155 pub no_config: bool,
7156 #[arg(long, short, action = clap::ArgAction::HelpShort, hide = true)]
7157 pub help: Option<bool>,
7158 #[arg(short = 'V', long, hide = true)]
7159 pub version: bool,
7160}
7161
7162#[derive(Args)]
7163pub struct IndexArgs {
7164 /// The URLs to use when resolving dependencies, in addition to the default index.
7165 ///
7166 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
7167 /// directory laid out in the same format.
7168 ///
7169 /// All indexes provided via this flag take priority over the index specified by
7170 /// `--default-index` (which defaults to PyPI). When multiple `--index` flags are provided,
7171 /// earlier values take priority.
7172 ///
7173 /// Index names are not supported as values. Relative paths must be disambiguated from index
7174 /// names with `./` or `../` on Unix or `.\\`, `..\\`, `./` or `../` on Windows.
7175 //
7176 // The nested Vec structure (`Vec<Vec<Maybe<Index>>>`) is required for clap's
7177 // value parsing mechanism, which processes one value at a time, in order to handle
7178 // `UV_INDEX` the same way pip handles `PIP_EXTRA_INDEX_URL`.
7179 #[arg(
7180 long,
7181 env = EnvVars::UV_INDEX,
7182 hide_env_values = true,
7183 value_parser = parse_indices,
7184 help_heading = "Index options"
7185 )]
7186 pub index: Option<Vec<Vec<Maybe<Index>>>>,
7187
7188 /// The URL of the default package index (by default: <https://pypi.org/simple>).
7189 ///
7190 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
7191 /// directory laid out in the same format.
7192 ///
7193 /// The index given by this flag is given lower priority than all other indexes specified via
7194 /// the `--index` flag.
7195 #[arg(
7196 long,
7197 env = EnvVars::UV_DEFAULT_INDEX,
7198 hide_env_values = true,
7199 value_parser = parse_default_index,
7200 help_heading = "Index options"
7201 )]
7202 pub default_index: Option<Maybe<Index>>,
7203
7204 /// (Deprecated: use `--default-index` instead) The URL of the Python package index (by default:
7205 /// <https://pypi.org/simple>).
7206 ///
7207 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
7208 /// directory laid out in the same format.
7209 ///
7210 /// The index given by this flag is given lower priority than all other indexes specified via
7211 /// the `--extra-index-url` flag.
7212 #[arg(
7213 long,
7214 short,
7215 env = EnvVars::UV_INDEX_URL,
7216 hide_env_values = true,
7217 value_parser = parse_index_url,
7218 help_heading = "Index options"
7219 )]
7220 pub index_url: Option<Maybe<PipIndex>>,
7221
7222 /// (Deprecated: use `--index` instead) Extra URLs of package indexes to use, in addition to
7223 /// `--index-url`.
7224 ///
7225 /// Accepts either a repository compliant with PEP 503 (the simple repository API), or a local
7226 /// directory laid out in the same format.
7227 ///
7228 /// All indexes provided via this flag take priority over the index specified by `--index-url`
7229 /// (which defaults to PyPI). When multiple `--extra-index-url` flags are provided, earlier
7230 /// values take priority.
7231 #[arg(
7232 long,
7233 env = EnvVars::UV_EXTRA_INDEX_URL,
7234 hide_env_values = true,
7235 value_delimiter = ' ',
7236 value_parser = parse_extra_index_url,
7237 help_heading = "Index options"
7238 )]
7239 pub extra_index_url: Option<Vec<Maybe<PipExtraIndex>>>,
7240
7241 /// Locations to search for candidate distributions, in addition to those found in the registry
7242 /// indexes.
7243 ///
7244 /// If a path, the target must be a directory that contains packages as wheel files (`.whl`) or
7245 /// source distributions (e.g., `.tar.gz` or `.zip`) at the top level.
7246 ///
7247 /// If a URL, the page must contain a flat list of links to package files adhering to the
7248 /// formats described above.
7249 #[arg(
7250 long,
7251 short,
7252 env = EnvVars::UV_FIND_LINKS,
7253 hide_env_values = true,
7254 value_delimiter = ',',
7255 value_parser = parse_find_links,
7256 help_heading = "Index options"
7257 )]
7258 pub find_links: Option<Vec<Maybe<PipFindLinks>>>,
7259
7260 /// Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those
7261 /// provided via `--find-links`.
7262 #[arg(long, help_heading = "Index options")]
7263 pub no_index: bool,
7264}
7265
7266#[derive(Args)]
7267pub struct RefreshArgs {
7268 /// Refresh all cached data.
7269 #[arg(long, overrides_with("no_refresh"), help_heading = "Cache options")]
7270 refresh: bool,
7271
7272 #[arg(
7273 long,
7274 overrides_with("refresh"),
7275 hide = true,
7276 help_heading = "Cache options"
7277 )]
7278 no_refresh: bool,
7279
7280 /// Refresh cached data for a specific package.
7281 #[arg(long, help_heading = "Cache options", value_hint = ValueHint::Other)]
7282 refresh_package: Vec<PackageName>,
7283}
7284
7285#[derive(Args)]
7286pub struct BuildOptionsArgs {
7287 /// Don't build source distributions.
7288 ///
7289 /// When enabled, resolving will not run arbitrary Python code. The cached wheels of
7290 /// already-built source distributions will be reused, but operations that require building
7291 /// distributions will exit with an error.
7292 #[arg(
7293 long,
7294 env = EnvVars::UV_NO_BUILD,
7295 overrides_with("build"),
7296 value_parser = clap::builder::BoolishValueParser::new(),
7297 help_heading = "Build options",
7298 )]
7299 no_build: bool,
7300
7301 #[arg(
7302 long,
7303 overrides_with("no_build"),
7304 hide = true,
7305 help_heading = "Build options"
7306 )]
7307 build: bool,
7308
7309 /// Don't build source distributions for a specific package [env: `UV_NO_BUILD_PACKAGE`=]
7310 #[arg(
7311 long,
7312 help_heading = "Build options",
7313 value_delimiter = ' ',
7314 value_hint = ValueHint::Other,
7315 )]
7316 no_build_package: Vec<PackageName>,
7317
7318 /// Don't install pre-built wheels.
7319 ///
7320 /// The given packages will be built and installed from source. The resolver will still use
7321 /// pre-built wheels to extract package metadata, if available.
7322 #[arg(
7323 long,
7324 env = EnvVars::UV_NO_BINARY,
7325 overrides_with("binary"),
7326 value_parser = clap::builder::BoolishValueParser::new(),
7327 help_heading = "Build options"
7328 )]
7329 no_binary: bool,
7330
7331 #[arg(
7332 long,
7333 overrides_with("no_binary"),
7334 hide = true,
7335 help_heading = "Build options"
7336 )]
7337 binary: bool,
7338
7339 /// Don't install pre-built wheels for a specific package [env: `UV_NO_BINARY_PACKAGE`=]
7340 #[arg(
7341 long,
7342 help_heading = "Build options",
7343 value_delimiter = ' ',
7344 value_hint = ValueHint::Other,
7345 )]
7346 no_binary_package: Vec<PackageName>,
7347}
7348
7349/// Arguments that are used by commands that need to install (but not resolve) packages.
7350#[derive(Args)]
7351pub struct InstallerArgs {
7352 #[command(flatten)]
7353 index_args: IndexArgs,
7354
7355 /// Reinstall all packages, regardless of whether they're already installed. Implies
7356 /// `--refresh`.
7357 #[arg(
7358 long,
7359 alias = "force-reinstall",
7360 overrides_with("no_reinstall"),
7361 help_heading = "Installer options"
7362 )]
7363 reinstall: bool,
7364
7365 #[arg(
7366 long,
7367 overrides_with("reinstall"),
7368 hide = true,
7369 help_heading = "Installer options"
7370 )]
7371 no_reinstall: bool,
7372
7373 /// Reinstall a specific package, regardless of whether it's already installed. Implies
7374 /// `--refresh-package`.
7375 #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7376 reinstall_package: Vec<PackageName>,
7377
7378 /// The strategy to use when resolving against multiple index URLs.
7379 ///
7380 /// By default, uv will stop at the first index on which a given package is available, and limit
7381 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7382 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7383 /// to an alternate index.
7384 #[arg(
7385 long,
7386 value_enum,
7387 env = EnvVars::UV_INDEX_STRATEGY,
7388 help_heading = "Index options"
7389 )]
7390 index_strategy: Option<IndexStrategy>,
7391
7392 /// Attempt to use `keyring` for authentication for index URLs.
7393 ///
7394 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7395 /// the `keyring` CLI to handle authentication.
7396 ///
7397 /// Defaults to `disabled`.
7398 #[arg(
7399 long,
7400 value_enum,
7401 env = EnvVars::UV_KEYRING_PROVIDER,
7402 help_heading = "Index options"
7403 )]
7404 keyring_provider: Option<KeyringProviderType>,
7405
7406 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7407 #[arg(
7408 long,
7409 short = 'C',
7410 alias = "config-settings",
7411 help_heading = "Build options"
7412 )]
7413 config_setting: Option<Vec<ConfigSettingEntry>>,
7414
7415 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7416 #[arg(
7417 long,
7418 alias = "config-settings-package",
7419 help_heading = "Build options"
7420 )]
7421 config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7422
7423 /// Disable isolation when building source distributions.
7424 ///
7425 /// Assumes that build dependencies specified by PEP 518 are already installed.
7426 #[arg(
7427 long,
7428 overrides_with("build_isolation"),
7429 help_heading = "Build options",
7430 env = EnvVars::UV_NO_BUILD_ISOLATION,
7431 value_parser = clap::builder::BoolishValueParser::new(),
7432 )]
7433 no_build_isolation: bool,
7434
7435 #[arg(
7436 long,
7437 overrides_with("no_build_isolation"),
7438 hide = true,
7439 help_heading = "Build options"
7440 )]
7441 build_isolation: bool,
7442
7443 /// Limit candidate packages to those that were uploaded prior to the given date.
7444 ///
7445 /// The date is compared against the upload time of each individual distribution artifact
7446 /// (i.e., when each file was uploaded to the package index), not the release date of the
7447 /// package version.
7448 ///
7449 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7450 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7451 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7452 /// `P7D`, `P30D`).
7453 ///
7454 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7455 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7456 /// Calendar units such as months and years are not allowed.
7457 ///
7458 /// Use `false` to disable `exclude-newer`.
7459 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7460 exclude_newer: Option<ExcludeNewerOverride>,
7461
7462 /// Limit candidate packages for specific packages to those that were uploaded prior to the
7463 /// given date.
7464 ///
7465 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7466 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7467 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7468 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7469 /// `P30D`).
7470 ///
7471 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7472 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7473 /// Calendar units such as months and years are not allowed.
7474 ///
7475 /// Can be provided multiple times for different packages.
7476 #[arg(long, help_heading = "Resolver options")]
7477 exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7478
7479 /// The method to use when installing packages from the global cache.
7480 ///
7481 /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7482 /// Windows.
7483 ///
7484 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7485 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7486 /// will break all installed packages by way of removing the underlying source files. Use
7487 /// symlinks with caution.
7488 #[arg(
7489 long,
7490 value_enum,
7491 env = EnvVars::UV_LINK_MODE,
7492 help_heading = "Installer options"
7493 )]
7494 link_mode: Option<uv_install_wheel::LinkMode>,
7495
7496 /// Compile Python files to bytecode after installation.
7497 ///
7498 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
7499 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
7500 /// in which start time is critical, such as CLI applications and Docker containers, this option
7501 /// can be enabled to trade longer installation times for faster start times.
7502 ///
7503 /// When enabled, uv will process the entire site-packages directory (including packages that
7504 /// are not being modified by the current operation) for consistency. Like pip, it will also
7505 /// ignore errors.
7506 #[arg(
7507 long,
7508 alias = "compile",
7509 overrides_with("no_compile_bytecode"),
7510 help_heading = "Installer options",
7511 env = EnvVars::UV_COMPILE_BYTECODE,
7512 value_parser = clap::builder::BoolishValueParser::new(),
7513 )]
7514 compile_bytecode: bool,
7515
7516 #[arg(
7517 long,
7518 alias = "no-compile",
7519 overrides_with("compile_bytecode"),
7520 hide = true,
7521 help_heading = "Installer options"
7522 )]
7523 no_compile_bytecode: bool,
7524
7525 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7526 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7527 /// URL, or local path sources.
7528 #[arg(
7529 long,
7530 env = EnvVars::UV_NO_SOURCES,
7531 value_parser = clap::builder::BoolishValueParser::new(),
7532 help_heading = "Resolver options"
7533 )]
7534 no_sources: bool,
7535
7536 /// Don't use sources from the `tool.uv.sources` table for the specified packages [env: `UV_NO_SOURCES_PACKAGE`=]
7537 #[arg(long, help_heading = "Resolver options", value_delimiter = ' ')]
7538 no_sources_package: Vec<PackageName>,
7539}
7540
7541/// Arguments that are used by commands that need to resolve (but not install) packages.
7542#[derive(Args)]
7543pub struct ResolverArgs {
7544 #[command(flatten)]
7545 index_args: IndexArgs,
7546
7547 /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7548 /// `--refresh`.
7549 #[arg(
7550 long,
7551 short = 'U',
7552 overrides_with("no_upgrade"),
7553 help_heading = "Resolver options"
7554 )]
7555 upgrade: bool,
7556
7557 #[arg(
7558 long,
7559 overrides_with("upgrade"),
7560 hide = true,
7561 help_heading = "Resolver options"
7562 )]
7563 no_upgrade: bool,
7564
7565 /// Allow upgrades for a specific package, ignoring pinned versions in any existing output
7566 /// file. Implies `--refresh-package`.
7567 #[arg(long, short = 'P', help_heading = "Resolver options")]
7568 upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7569
7570 /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7571 /// existing output file.
7572 #[arg(long, help_heading = "Resolver options")]
7573 upgrade_group: Vec<GroupName>,
7574
7575 /// The strategy to use when resolving against multiple index URLs.
7576 ///
7577 /// By default, uv will stop at the first index on which a given package is available, and limit
7578 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7579 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7580 /// to an alternate index.
7581 #[arg(
7582 long,
7583 value_enum,
7584 env = EnvVars::UV_INDEX_STRATEGY,
7585 help_heading = "Index options"
7586 )]
7587 index_strategy: Option<IndexStrategy>,
7588
7589 /// Attempt to use `keyring` for authentication for index URLs.
7590 ///
7591 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7592 /// the `keyring` CLI to handle authentication.
7593 ///
7594 /// Defaults to `disabled`.
7595 #[arg(
7596 long,
7597 value_enum,
7598 env = EnvVars::UV_KEYRING_PROVIDER,
7599 help_heading = "Index options"
7600 )]
7601 keyring_provider: Option<KeyringProviderType>,
7602
7603 /// The strategy to use when selecting between the different compatible versions for a given
7604 /// package requirement.
7605 ///
7606 /// By default, uv will use the latest compatible version of each package (`highest`).
7607 #[arg(
7608 long,
7609 value_enum,
7610 env = EnvVars::UV_RESOLUTION,
7611 help_heading = "Resolver options"
7612 )]
7613 resolution: Option<ResolutionMode>,
7614
7615 /// The strategy to use when considering pre-release versions.
7616 ///
7617 /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
7618 /// with first-party requirements that contain an explicit pre-release marker in the declared
7619 /// specifiers (`if-necessary-or-explicit`).
7620 #[arg(
7621 long,
7622 value_enum,
7623 env = EnvVars::UV_PRERELEASE,
7624 help_heading = "Resolver options"
7625 )]
7626 prerelease: Option<PrereleaseMode>,
7627
7628 #[arg(long, hide = true, help_heading = "Resolver options")]
7629 pre: bool,
7630
7631 /// The strategy to use when selecting multiple versions of a given package across Python
7632 /// versions and platforms.
7633 ///
7634 /// By default, uv will optimize for selecting the latest version of each package for each
7635 /// supported Python version (`requires-python`), while minimizing the number of selected
7636 /// versions across platforms.
7637 ///
7638 /// Under `fewest`, uv will minimize the number of selected versions for each package,
7639 /// preferring older versions that are compatible with a wider range of supported Python
7640 /// versions or platforms.
7641 #[arg(
7642 long,
7643 value_enum,
7644 env = EnvVars::UV_FORK_STRATEGY,
7645 help_heading = "Resolver options"
7646 )]
7647 fork_strategy: Option<ForkStrategy>,
7648
7649 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7650 #[arg(
7651 long,
7652 short = 'C',
7653 alias = "config-settings",
7654 help_heading = "Build options"
7655 )]
7656 config_setting: Option<Vec<ConfigSettingEntry>>,
7657
7658 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7659 #[arg(
7660 long,
7661 alias = "config-settings-package",
7662 help_heading = "Build options"
7663 )]
7664 config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7665
7666 /// Disable isolation when building source distributions.
7667 ///
7668 /// Assumes that build dependencies specified by PEP 518 are already installed.
7669 #[arg(
7670 long,
7671 overrides_with("build_isolation"),
7672 help_heading = "Build options",
7673 env = EnvVars::UV_NO_BUILD_ISOLATION,
7674 value_parser = clap::builder::BoolishValueParser::new(),
7675 )]
7676 no_build_isolation: bool,
7677
7678 /// Disable isolation when building source distributions for a specific package.
7679 ///
7680 /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7681 #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7682 no_build_isolation_package: Vec<PackageName>,
7683
7684 #[arg(
7685 long,
7686 overrides_with("no_build_isolation"),
7687 hide = true,
7688 help_heading = "Build options"
7689 )]
7690 build_isolation: bool,
7691
7692 /// Limit candidate packages to those that were uploaded prior to the given date.
7693 ///
7694 /// The date is compared against the upload time of each individual distribution artifact
7695 /// (i.e., when each file was uploaded to the package index), not the release date of the
7696 /// package version.
7697 ///
7698 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7699 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7700 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7701 /// `P7D`, `P30D`).
7702 ///
7703 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7704 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7705 /// Calendar units such as months and years are not allowed.
7706 ///
7707 /// Use `false` to disable `exclude-newer`.
7708 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
7709 exclude_newer: Option<ExcludeNewerOverride>,
7710
7711 /// Limit candidate packages for specific packages to those that were uploaded prior to the
7712 /// given date.
7713 ///
7714 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7715 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7716 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7717 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7718 /// `P30D`).
7719 ///
7720 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7721 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7722 /// Calendar units such as months and years are not allowed.
7723 ///
7724 /// Can be provided multiple times for different packages.
7725 #[arg(long, help_heading = "Resolver options")]
7726 exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7727
7728 /// The method to use when installing packages from the global cache.
7729 ///
7730 /// This option is only used when building source distributions.
7731 ///
7732 /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7733 /// Windows.
7734 ///
7735 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7736 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7737 /// will break all installed packages by way of removing the underlying source files. Use
7738 /// symlinks with caution.
7739 #[arg(
7740 long,
7741 value_enum,
7742 env = EnvVars::UV_LINK_MODE,
7743 help_heading = "Installer options"
7744 )]
7745 link_mode: Option<uv_install_wheel::LinkMode>,
7746
7747 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
7748 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
7749 /// URL, or local path sources.
7750 #[arg(
7751 long,
7752 env = EnvVars::UV_NO_SOURCES,
7753 value_parser = clap::builder::BoolishValueParser::new(),
7754 help_heading = "Resolver options",
7755 )]
7756 no_sources: bool,
7757
7758 /// Don't use sources from the `tool.uv.sources` table for the specified packages [env: `UV_NO_SOURCES_PACKAGE`=]
7759 #[arg(long, help_heading = "Resolver options", value_delimiter = ' ')]
7760 no_sources_package: Vec<PackageName>,
7761}
7762
7763/// Arguments that are used by commands that need to resolve and install packages.
7764#[derive(Args)]
7765pub struct ResolverInstallerArgs {
7766 #[command(flatten)]
7767 pub index_args: IndexArgs,
7768
7769 /// Allow package upgrades, ignoring pinned versions in any existing output file. Implies
7770 /// `--refresh`.
7771 #[arg(
7772 long,
7773 short = 'U',
7774 overrides_with("no_upgrade"),
7775 help_heading = "Resolver options"
7776 )]
7777 pub upgrade: bool,
7778
7779 #[arg(
7780 long,
7781 overrides_with("upgrade"),
7782 hide = true,
7783 help_heading = "Resolver options"
7784 )]
7785 pub no_upgrade: bool,
7786
7787 /// Allow upgrades for a specific package, ignoring pinned versions in any existing output file.
7788 /// Implies `--refresh-package`.
7789 #[arg(long, short = 'P', help_heading = "Resolver options", value_hint = ValueHint::Other)]
7790 pub upgrade_package: Vec<Requirement<VerbatimParsedUrl>>,
7791
7792 /// Allow upgrades for all packages in a dependency group, ignoring pinned versions in any
7793 /// existing output file.
7794 #[arg(long, help_heading = "Resolver options")]
7795 pub upgrade_group: Vec<GroupName>,
7796
7797 /// Reinstall all packages, regardless of whether they're already installed. Implies
7798 /// `--refresh`.
7799 #[arg(
7800 long,
7801 alias = "force-reinstall",
7802 overrides_with("no_reinstall"),
7803 help_heading = "Installer options"
7804 )]
7805 pub reinstall: bool,
7806
7807 #[arg(
7808 long,
7809 overrides_with("reinstall"),
7810 hide = true,
7811 help_heading = "Installer options"
7812 )]
7813 pub no_reinstall: bool,
7814
7815 /// Reinstall a specific package, regardless of whether it's already installed. Implies
7816 /// `--refresh-package`.
7817 #[arg(long, help_heading = "Installer options", value_hint = ValueHint::Other)]
7818 pub reinstall_package: Vec<PackageName>,
7819
7820 /// The strategy to use when resolving against multiple index URLs.
7821 ///
7822 /// By default, uv will stop at the first index on which a given package is available, and limit
7823 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
7824 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
7825 /// to an alternate index.
7826 #[arg(
7827 long,
7828 value_enum,
7829 env = EnvVars::UV_INDEX_STRATEGY,
7830 help_heading = "Index options"
7831 )]
7832 pub index_strategy: Option<IndexStrategy>,
7833
7834 /// Attempt to use `keyring` for authentication for index URLs.
7835 ///
7836 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
7837 /// the `keyring` CLI to handle authentication.
7838 ///
7839 /// Defaults to `disabled`.
7840 #[arg(
7841 long,
7842 value_enum,
7843 env = EnvVars::UV_KEYRING_PROVIDER,
7844 help_heading = "Index options"
7845 )]
7846 pub keyring_provider: Option<KeyringProviderType>,
7847
7848 /// The strategy to use when selecting between the different compatible versions for a given
7849 /// package requirement.
7850 ///
7851 /// By default, uv will use the latest compatible version of each package (`highest`).
7852 #[arg(
7853 long,
7854 value_enum,
7855 env = EnvVars::UV_RESOLUTION,
7856 help_heading = "Resolver options"
7857 )]
7858 pub resolution: Option<ResolutionMode>,
7859
7860 /// The strategy to use when considering pre-release versions.
7861 ///
7862 /// By default, uv will accept pre-releases for packages that _only_ publish pre-releases, along
7863 /// with first-party requirements that contain an explicit pre-release marker in the declared
7864 /// specifiers (`if-necessary-or-explicit`).
7865 #[arg(
7866 long,
7867 value_enum,
7868 env = EnvVars::UV_PRERELEASE,
7869 help_heading = "Resolver options"
7870 )]
7871 pub prerelease: Option<PrereleaseMode>,
7872
7873 #[arg(long, hide = true)]
7874 pub pre: bool,
7875
7876 /// The strategy to use when selecting multiple versions of a given package across Python
7877 /// versions and platforms.
7878 ///
7879 /// By default, uv will optimize for selecting the latest version of each package for each
7880 /// supported Python version (`requires-python`), while minimizing the number of selected
7881 /// versions across platforms.
7882 ///
7883 /// Under `fewest`, uv will minimize the number of selected versions for each package,
7884 /// preferring older versions that are compatible with a wider range of supported Python
7885 /// versions or platforms.
7886 #[arg(
7887 long,
7888 value_enum,
7889 env = EnvVars::UV_FORK_STRATEGY,
7890 help_heading = "Resolver options"
7891 )]
7892 pub fork_strategy: Option<ForkStrategy>,
7893
7894 /// Settings to pass to the PEP 517 build backend, specified as `KEY=VALUE` pairs.
7895 #[arg(
7896 long,
7897 short = 'C',
7898 alias = "config-settings",
7899 help_heading = "Build options",
7900 value_hint = ValueHint::Other,
7901 )]
7902 pub config_setting: Option<Vec<ConfigSettingEntry>>,
7903
7904 /// Settings to pass to the PEP 517 build backend for a specific package, specified as `PACKAGE:KEY=VALUE` pairs.
7905 #[arg(
7906 long,
7907 alias = "config-settings-package",
7908 help_heading = "Build options",
7909 value_hint = ValueHint::Other,
7910 )]
7911 pub config_settings_package: Option<Vec<ConfigSettingPackageEntry>>,
7912
7913 /// Disable isolation when building source distributions.
7914 ///
7915 /// Assumes that build dependencies specified by PEP 518 are already installed.
7916 #[arg(
7917 long,
7918 overrides_with("build_isolation"),
7919 help_heading = "Build options",
7920 env = EnvVars::UV_NO_BUILD_ISOLATION,
7921 value_parser = clap::builder::BoolishValueParser::new(),
7922 )]
7923 pub no_build_isolation: bool,
7924
7925 /// Disable isolation when building source distributions for a specific package.
7926 ///
7927 /// Assumes that the packages' build dependencies specified by PEP 518 are already installed.
7928 #[arg(long, help_heading = "Build options", value_hint = ValueHint::Other)]
7929 pub no_build_isolation_package: Vec<PackageName>,
7930
7931 #[arg(
7932 long,
7933 overrides_with("no_build_isolation"),
7934 hide = true,
7935 help_heading = "Build options"
7936 )]
7937 pub build_isolation: bool,
7938
7939 /// Limit candidate packages to those that were uploaded prior to the given date.
7940 ///
7941 /// The date is compared against the upload time of each individual distribution artifact
7942 /// (i.e., when each file was uploaded to the package index), not the release date of the
7943 /// package version.
7944 ///
7945 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
7946 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
7947 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
7948 /// `P7D`, `P30D`).
7949 ///
7950 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7951 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7952 /// Calendar units such as months and years are not allowed.
7953 ///
7954 /// Use `false` to disable `exclude-newer`.
7955 #[arg(
7956 long,
7957 env = EnvVars::UV_EXCLUDE_NEWER,
7958 help_heading = "Resolver options",
7959 value_hint = ValueHint::Other,
7960 )]
7961 pub exclude_newer: Option<ExcludeNewerOverride>,
7962
7963 /// Limit candidate packages for specific packages to those that were uploaded prior to the
7964 /// given date.
7965 ///
7966 /// Accepts package-date pairs in the format `PACKAGE=DATE`, where `DATE` is an RFC 3339
7967 /// timestamp (e.g., `2006-12-02T02:07:43Z`), a local date in the same format (e.g.,
7968 /// `2006-12-02`) resolved based on your system's configured time zone, a "friendly" duration
7969 /// (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`, `P7D`,
7970 /// `P30D`).
7971 ///
7972 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
7973 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
7974 /// Calendar units such as months and years are not allowed.
7975 ///
7976 /// Can be provided multiple times for different packages.
7977 #[arg(long, help_heading = "Resolver options", value_hint = ValueHint::Other)]
7978 pub exclude_newer_package: Option<Vec<ExcludeNewerPackageEntry>>,
7979
7980 /// The method to use when installing packages from the global cache.
7981 ///
7982 /// Defaults to `clone` (also known as Copy-on-Write) on macOS and Linux, and `hardlink` on
7983 /// Windows.
7984 ///
7985 /// WARNING: The use of symlink link mode is discouraged, as they create tight coupling between
7986 /// the cache and the target environment. For example, clearing the cache (`uv cache clean`)
7987 /// will break all installed packages by way of removing the underlying source files. Use
7988 /// symlinks with caution.
7989 #[arg(
7990 long,
7991 value_enum,
7992 env = EnvVars::UV_LINK_MODE,
7993 help_heading = "Installer options"
7994 )]
7995 pub link_mode: Option<uv_install_wheel::LinkMode>,
7996
7997 /// Compile Python files to bytecode after installation.
7998 ///
7999 /// By default, uv does not compile Python (`.py`) files to bytecode (`__pycache__/*.pyc`);
8000 /// instead, compilation is performed lazily the first time a module is imported. For use-cases
8001 /// in which start time is critical, such as CLI applications and Docker containers, this option
8002 /// can be enabled to trade longer installation times for faster start times.
8003 ///
8004 /// When enabled, uv will process the entire site-packages directory (including packages that
8005 /// are not being modified by the current operation) for consistency. Like pip, it will also
8006 /// ignore errors.
8007 #[arg(
8008 long,
8009 alias = "compile",
8010 overrides_with("no_compile_bytecode"),
8011 help_heading = "Installer options",
8012 env = EnvVars::UV_COMPILE_BYTECODE,
8013 value_parser = clap::builder::BoolishValueParser::new(),
8014 )]
8015 pub compile_bytecode: bool,
8016
8017 #[arg(
8018 long,
8019 alias = "no-compile",
8020 overrides_with("compile_bytecode"),
8021 hide = true,
8022 help_heading = "Installer options"
8023 )]
8024 pub no_compile_bytecode: bool,
8025
8026 /// Ignore the `tool.uv.sources` table when resolving dependencies. Used to lock against the
8027 /// standards-compliant, publishable package metadata, as opposed to using any workspace, Git,
8028 /// URL, or local path sources.
8029 #[arg(
8030 long,
8031 env = EnvVars::UV_NO_SOURCES,
8032 value_parser = clap::builder::BoolishValueParser::new(),
8033 help_heading = "Resolver options",
8034 )]
8035 pub no_sources: bool,
8036
8037 /// Don't use sources from the `tool.uv.sources` table for the specified packages [env: `UV_NO_SOURCES_PACKAGE`=]
8038 #[arg(long, help_heading = "Resolver options", value_delimiter = ' ')]
8039 pub no_sources_package: Vec<PackageName>,
8040}
8041
8042/// Arguments that are used by commands that need to fetch from the Simple API.
8043#[derive(Args)]
8044pub struct FetchArgs {
8045 #[command(flatten)]
8046 index_args: IndexArgs,
8047
8048 /// The strategy to use when resolving against multiple index URLs.
8049 ///
8050 /// By default, uv will stop at the first index on which a given package is available, and limit
8051 /// resolutions to those present on that first index (`first-index`). This prevents "dependency
8052 /// confusion" attacks, whereby an attacker can upload a malicious package under the same name
8053 /// to an alternate index.
8054 #[arg(
8055 long,
8056 value_enum,
8057 env = EnvVars::UV_INDEX_STRATEGY,
8058 help_heading = "Index options"
8059 )]
8060 index_strategy: Option<IndexStrategy>,
8061
8062 /// Attempt to use `keyring` for authentication for index URLs.
8063 ///
8064 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
8065 /// the `keyring` CLI to handle authentication.
8066 ///
8067 /// Defaults to `disabled`.
8068 #[arg(
8069 long,
8070 value_enum,
8071 env = EnvVars::UV_KEYRING_PROVIDER,
8072 help_heading = "Index options"
8073 )]
8074 keyring_provider: Option<KeyringProviderType>,
8075
8076 /// Limit candidate packages to those that were uploaded prior to the given date.
8077 ///
8078 /// The date is compared against the upload time of each individual distribution artifact
8079 /// (i.e., when each file was uploaded to the package index), not the release date of the
8080 /// package version.
8081 ///
8082 /// Accepts RFC 3339 timestamps (e.g., `2006-12-02T02:07:43Z`), local dates in the same format
8083 /// (e.g., `2006-12-02`) resolved based on your system's configured time zone, a "friendly"
8084 /// duration (e.g., `24 hours`, `1 week`, `30 days`), or an ISO 8601 duration (e.g., `PT24H`,
8085 /// `P7D`, `P30D`).
8086 ///
8087 /// Durations do not respect semantics of the local time zone and are always resolved to a fixed
8088 /// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
8089 /// Calendar units such as months and years are not allowed.
8090 ///
8091 /// Use `false` to disable `exclude-newer`.
8092 #[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
8093 exclude_newer: Option<ExcludeNewerOverride>,
8094}
8095
8096#[derive(Args)]
8097pub struct DisplayTreeArgs {
8098 /// Maximum display depth of the dependency tree
8099 #[arg(long, short, default_value_t = 255)]
8100 pub depth: u8,
8101
8102 /// Prune the given package from the display of the dependency tree.
8103 #[arg(long, value_hint = ValueHint::Other)]
8104 pub prune: Vec<PackageName>,
8105
8106 /// Display only the specified packages.
8107 #[arg(long, value_hint = ValueHint::Other)]
8108 pub package: Vec<PackageName>,
8109
8110 /// Do not de-duplicate repeated dependencies. Usually, when a package has already displayed its
8111 /// dependencies, further occurrences will not re-display its dependencies, and will include a
8112 /// (*) to indicate it has already been shown. This flag will cause those duplicates to be
8113 /// repeated.
8114 #[arg(long)]
8115 pub no_dedupe: bool,
8116
8117 /// Show the reverse dependencies for the given package. This flag will invert the tree and
8118 /// display the packages that depend on the given package.
8119 #[arg(long, alias = "reverse")]
8120 pub invert: bool,
8121
8122 /// Show the latest available version of each package in the tree.
8123 #[arg(long)]
8124 pub outdated: bool,
8125
8126 /// Show compressed wheel sizes for packages in the tree.
8127 #[arg(long)]
8128 pub show_sizes: bool,
8129}
8130
8131#[derive(Args, Debug)]
8132pub struct PublishArgs {
8133 /// Paths to the files to upload. Accepts glob expressions.
8134 ///
8135 /// Defaults to the `dist` directory. Selects only wheels and source distributions
8136 /// and their attestations, while ignoring other files.
8137 #[arg(default_value = "dist/*", value_hint = ValueHint::FilePath)]
8138 pub files: Vec<String>,
8139
8140 /// The name of an index in the configuration to use for publishing.
8141 ///
8142 /// The index must have a `publish-url` setting, for example:
8143 ///
8144 /// ```toml
8145 /// [[tool.uv.index]]
8146 /// name = "pypi"
8147 /// url = "https://pypi.org/simple"
8148 /// publish-url = "https://upload.pypi.org/legacy/"
8149 /// ```
8150 ///
8151 /// The index `url` will be used to check for existing files to skip duplicate uploads.
8152 ///
8153 /// With these settings, the following two calls are equivalent:
8154 ///
8155 /// ```shell
8156 /// uv publish --index pypi
8157 /// uv publish --publish-url https://upload.pypi.org/legacy/ --check-url https://pypi.org/simple
8158 /// ```
8159 #[arg(
8160 long,
8161 verbatim_doc_comment,
8162 env = EnvVars::UV_PUBLISH_INDEX,
8163 conflicts_with = "publish_url",
8164 conflicts_with = "check_url",
8165 value_hint = ValueHint::Other,
8166 )]
8167 pub index: Option<String>,
8168
8169 /// The username for the upload.
8170 #[arg(
8171 short,
8172 long,
8173 env = EnvVars::UV_PUBLISH_USERNAME,
8174 hide_env_values = true,
8175 value_hint = ValueHint::Other
8176 )]
8177 pub username: Option<String>,
8178
8179 /// The password for the upload.
8180 #[arg(
8181 short,
8182 long,
8183 env = EnvVars::UV_PUBLISH_PASSWORD,
8184 hide_env_values = true,
8185 value_hint = ValueHint::Other
8186 )]
8187 pub password: Option<String>,
8188
8189 /// The token for the upload.
8190 ///
8191 /// Using a token is equivalent to passing `__token__` as `--username` and the token as
8192 /// `--password` password.
8193 #[arg(
8194 short,
8195 long,
8196 env = EnvVars::UV_PUBLISH_TOKEN,
8197 hide_env_values = true,
8198 conflicts_with = "username",
8199 conflicts_with = "password",
8200 value_hint = ValueHint::Other,
8201 )]
8202 pub token: Option<String>,
8203
8204 /// Configure trusted publishing.
8205 ///
8206 /// By default, uv checks for trusted publishing when running in a supported environment, but
8207 /// ignores it if it isn't configured.
8208 ///
8209 /// uv's supported environments for trusted publishing include GitHub Actions and GitLab CI/CD.
8210 #[arg(long)]
8211 pub trusted_publishing: Option<TrustedPublishing>,
8212
8213 /// Attempt to use `keyring` for authentication for remote requirements files.
8214 ///
8215 /// At present, only `--keyring-provider subprocess` is supported, which configures uv to use
8216 /// the `keyring` CLI to handle authentication.
8217 ///
8218 /// Defaults to `disabled`.
8219 #[arg(long, value_enum, env = EnvVars::UV_KEYRING_PROVIDER)]
8220 pub keyring_provider: Option<KeyringProviderType>,
8221
8222 /// The URL of the upload endpoint (not the index URL).
8223 ///
8224 /// Note that there are typically different URLs for index access (e.g., `https:://.../simple`)
8225 /// and index upload.
8226 ///
8227 /// Defaults to PyPI's publish URL (<https://upload.pypi.org/legacy/>).
8228 #[arg(long, env = EnvVars::UV_PUBLISH_URL, hide_env_values = true)]
8229 pub publish_url: Option<DisplaySafeUrl>,
8230
8231 /// Check an index URL for existing files to skip duplicate uploads.
8232 ///
8233 /// This option allows retrying publishing that failed after only some, but not all files have
8234 /// been uploaded, and handles errors due to parallel uploads of the same file.
8235 ///
8236 /// Before uploading, the index is checked. If the exact same file already exists in the index,
8237 /// the file will not be uploaded. If an error occurred during the upload, the index is checked
8238 /// again, to handle cases where the identical file was uploaded twice in parallel.
8239 ///
8240 /// The exact behavior will vary based on the index. When uploading to PyPI, uploading the same
8241 /// file succeeds even without `--check-url`, while most other indexes error. When uploading to
8242 /// pyx, the index URL can be inferred automatically from the publish URL.
8243 ///
8244 /// The index must provide one of the supported hashes (SHA-256, SHA-384, or SHA-512).
8245 #[arg(long, env = EnvVars::UV_PUBLISH_CHECK_URL, hide_env_values = true)]
8246 pub check_url: Option<IndexUrl>,
8247
8248 #[arg(long, hide = true)]
8249 pub skip_existing: bool,
8250
8251 /// Perform a dry run without uploading files.
8252 ///
8253 /// When enabled, the command will check for existing files if `--check-url` is provided,
8254 /// and will perform validation against the index if supported, but will not upload any files.
8255 #[arg(long)]
8256 pub dry_run: bool,
8257
8258 /// Do not upload attestations for the published files.
8259 ///
8260 /// By default, uv attempts to upload matching PEP 740 attestations with each distribution
8261 /// that is published.
8262 #[arg(long, env = EnvVars::UV_PUBLISH_NO_ATTESTATIONS)]
8263 pub no_attestations: bool,
8264
8265 /// Use direct upload to the registry.
8266 ///
8267 /// When enabled, the publish command will use a direct two-phase upload protocol
8268 /// that uploads files directly to storage, bypassing the registry's upload endpoint.
8269 #[arg(long, hide = true)]
8270 pub direct: bool,
8271}
8272
8273#[derive(Args)]
8274pub struct WorkspaceNamespace {
8275 #[command(subcommand)]
8276 pub command: WorkspaceCommand,
8277}
8278
8279#[derive(Subcommand)]
8280pub enum WorkspaceCommand {
8281 /// View metadata about the current workspace.
8282 ///
8283 /// The output of this command is not yet stable.
8284 Metadata(Box<MetadataArgs>),
8285 /// Display the path of a workspace member.
8286 ///
8287 /// By default, the path to the workspace root directory is displayed.
8288 /// The `--package` option can be used to display the path to a workspace member instead.
8289 ///
8290 /// If used outside of a workspace, i.e., if a `pyproject.toml` cannot be found, uv will exit with an error.
8291 Dir(WorkspaceDirArgs),
8292 /// List the members of a workspace.
8293 ///
8294 /// Displays newline separated names of workspace members.
8295 List(WorkspaceListArgs),
8296}
8297#[derive(Args)]
8298pub struct MetadataArgs {
8299 /// View metadata for the specified PEP 723 Python script, rather than the current workspace.
8300 ///
8301 /// If provided, uv will resolve the dependencies based on the script's inline metadata table,
8302 /// in adherence with PEP 723.
8303 #[arg(long, value_hint = ValueHint::FilePath)]
8304 pub script: Option<PathBuf>,
8305
8306 /// Check if the lockfile is up-to-date [env: UV_LOCKED=]
8307 ///
8308 /// Asserts that the `uv.lock` would remain unchanged after a resolution. If the lockfile is
8309 /// missing or needs to be updated, uv will exit with an error.
8310 #[arg(long, conflicts_with_all = ["frozen", "upgrade"])]
8311 pub locked: bool,
8312
8313 /// Assert that a `uv.lock` exists without checking if it is up-to-date [env: UV_FROZEN=]
8314 #[arg(long, conflicts_with_all = ["locked"])]
8315 pub frozen: bool,
8316
8317 /// Perform a dry run, without writing the lockfile.
8318 ///
8319 /// In dry-run mode, uv will resolve the project's dependencies and report on the resulting
8320 /// changes, but will not write the lockfile to disk.
8321 #[arg(
8322 long,
8323 conflicts_with = "frozen",
8324 conflicts_with = "locked",
8325 conflicts_with = "sync"
8326 )]
8327 pub dry_run: bool,
8328
8329 #[command(flatten)]
8330 pub resolver: ResolverArgs,
8331
8332 #[command(flatten)]
8333 pub build: BuildOptionsArgs,
8334
8335 #[command(flatten)]
8336 pub refresh: RefreshArgs,
8337
8338 /// Sync the environment to include module ownership metadata in the output.
8339 ///
8340 /// This adds a mapping from importable module names to references to the package nodes
8341 /// that provide them. To do this, the venv will be synced in inexact mode.
8342 #[arg(long)]
8343 pub sync: bool,
8344
8345 /// The Python interpreter to use during resolution.
8346 ///
8347 /// A Python interpreter is required for building source distributions to determine package
8348 /// metadata when there are not wheels.
8349 ///
8350 /// The interpreter is also used as the fallback value for the minimum Python version if
8351 /// `requires-python` is not set.
8352 ///
8353 /// See `uv help python` for details on Python discovery and supported request formats.
8354 #[arg(
8355 long,
8356 short,
8357 env = EnvVars::UV_PYTHON,
8358 verbatim_doc_comment,
8359 help_heading = "Python options",
8360 value_parser = parse_maybe_string,
8361 value_hint = ValueHint::Other,
8362 )]
8363 pub python: Option<Maybe<String>>,
8364}
8365
8366#[derive(Args, Debug)]
8367pub struct WorkspaceDirArgs {
8368 /// Display the path to a specific package in the workspace.
8369 #[arg(long, value_hint = ValueHint::Other)]
8370 pub package: Option<PackageName>,
8371}
8372
8373#[derive(Args, Debug)]
8374pub struct WorkspaceListArgs {
8375 /// Show paths instead of names.
8376 #[arg(long)]
8377 pub paths: bool,
8378
8379 /// List all standalone scripts with inline metadata in the workspace.
8380 #[arg(long)]
8381 pub scripts: bool,
8382}
8383
8384/// See [PEP 517](https://peps.python.org/pep-0517/) and
8385/// [PEP 660](https://peps.python.org/pep-0660/) for specifications of the parameters.
8386#[derive(Subcommand)]
8387pub enum BuildBackendCommand {
8388 /// PEP 517 hook `build_sdist`.
8389 BuildSdist { sdist_directory: PathBuf },
8390 /// PEP 517 hook `build_wheel`.
8391 BuildWheel {
8392 wheel_directory: PathBuf,
8393 #[arg(long)]
8394 metadata_directory: Option<PathBuf>,
8395 },
8396 /// PEP 660 hook `build_editable`.
8397 BuildEditable {
8398 wheel_directory: PathBuf,
8399 #[arg(long)]
8400 metadata_directory: Option<PathBuf>,
8401 },
8402 /// PEP 517 hook `get_requires_for_build_sdist`.
8403 GetRequiresForBuildSdist,
8404 /// PEP 517 hook `get_requires_for_build_wheel`.
8405 GetRequiresForBuildWheel,
8406 /// PEP 517 hook `prepare_metadata_for_build_wheel`.
8407 PrepareMetadataForBuildWheel { wheel_directory: PathBuf },
8408 /// PEP 660 hook `get_requires_for_build_editable`.
8409 GetRequiresForBuildEditable,
8410 /// PEP 660 hook `prepare_metadata_for_build_editable`.
8411 PrepareMetadataForBuildEditable { wheel_directory: PathBuf },
8412}