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