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