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