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