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