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