Add `--python-platform` to `uv pip check` (#15486)

## Summary

I want this to facilitate some testing for
https://github.com/astral-sh/uv/issues/15035.
This commit is contained in:
Charlie Marsh 2025-08-24 14:14:42 -04:00 committed by GitHub
parent 99f1f4fee4
commit d19d0e26aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 118 additions and 4 deletions

View File

@ -2373,6 +2373,27 @@ pub struct PipCheckArgs {
#[arg(long, overrides_with("system"), hide = true)] #[arg(long, overrides_with("system"), hide = true)]
pub no_system: bool, pub no_system: bool,
/// The Python version against which packages should be checked.
///
/// By default, the installed packages are checked against the version of the current
/// interpreter.
#[arg(long)]
pub python_version: Option<PythonVersion>,
/// The platform for which packages should be checked.
///
/// By default, the installed packages are checked against the platform of the current
/// interpreter.
///
/// Represented as a "target triple", a string that describes the target platform in terms of
/// its CPU, vendor, and operating system name, like `x86_64-unknown-linux-gnu` or
/// `aarch64-apple-darwin`.
///
/// When targeting macOS (Darwin), the default minimum version is `12.0`. Use
/// `MACOSX_DEPLOYMENT_TARGET` to specify a different minimum version, e.g., `13.0`.
#[arg(long)]
pub python_platform: Option<TargetTriple>,
} }
#[derive(Args)] #[derive(Args)]

View File

@ -5,13 +5,16 @@ use anyhow::Result;
use owo_colors::OwoColorize; use owo_colors::OwoColorize;
use uv_cache::Cache; use uv_cache::Cache;
use uv_configuration::TargetTriple;
use uv_distribution_types::{Diagnostic, InstalledDist}; use uv_distribution_types::{Diagnostic, InstalledDist};
use uv_installer::{SitePackages, SitePackagesDiagnostic}; use uv_installer::{SitePackages, SitePackagesDiagnostic};
use uv_preview::Preview; use uv_preview::Preview;
use uv_python::PythonPreference; use uv_python::{
use uv_python::{EnvironmentPreference, PythonEnvironment, PythonRequest}; EnvironmentPreference, PythonEnvironment, PythonPreference, PythonRequest, PythonVersion,
};
use crate::commands::pip::operations::report_target_environment; use crate::commands::pip::operations::report_target_environment;
use crate::commands::pip::resolution_markers;
use crate::commands::{ExitStatus, elapsed}; use crate::commands::{ExitStatus, elapsed};
use crate::printer::Printer; use crate::printer::Printer;
@ -19,6 +22,8 @@ use crate::printer::Printer;
pub(crate) fn pip_check( pub(crate) fn pip_check(
python: Option<&str>, python: Option<&str>,
system: bool, system: bool,
python_version: Option<&PythonVersion>,
python_platform: Option<&TargetTriple>,
cache: &Cache, cache: &Cache,
printer: Printer, printer: Printer,
preview: Preview, preview: Preview,
@ -53,7 +58,7 @@ pub(crate) fn pip_check(
)?; )?;
// Determine the markers to use for resolution. // Determine the markers to use for resolution.
let markers = environment.interpreter().resolver_marker_environment(); let markers = resolution_markers(python_version, python_platform, environment.interpreter());
// Run the diagnostics. // Run the diagnostics.
let diagnostics: Vec<SitePackagesDiagnostic> = let diagnostics: Vec<SitePackagesDiagnostic> =

View File

@ -916,6 +916,8 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
commands::pip_check( commands::pip_check(
args.settings.python.as_deref(), args.settings.python.as_deref(),
args.settings.system, args.settings.system,
args.python_version.as_ref(),
args.python_platform.as_ref(),
&cache, &cache,
printer, printer,
globals.preview, globals.preview,

View File

@ -2589,6 +2589,8 @@ impl PipTreeSettings {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct PipCheckSettings { pub(crate) struct PipCheckSettings {
pub(crate) settings: PipSettings, pub(crate) settings: PipSettings,
pub(crate) python_version: Option<PythonVersion>,
pub(crate) python_platform: Option<TargetTriple>,
} }
impl PipCheckSettings { impl PipCheckSettings {
@ -2598,6 +2600,8 @@ impl PipCheckSettings {
python, python,
system, system,
no_system, no_system,
python_version,
python_platform,
} = args; } = args;
Self { Self {
@ -2609,6 +2613,8 @@ impl PipCheckSettings {
}, },
filesystem, filesystem,
), ),
python_version,
python_platform,
} }
} }
} }

View File

@ -187,3 +187,36 @@ fn check_multiple_incompatible_packages() -> Result<()> {
Ok(()) Ok(())
} }
#[test]
fn check_python_version() {
let context = TestContext::new("3.12");
uv_snapshot!(context
.pip_install()
.arg("urllib3")
.arg("--strict"), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ urllib3==2.2.1
"
);
uv_snapshot!(context.filters(), context.pip_check().arg("--python-version").arg("3.7"), @r"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
Checked 1 package in [TIME]
Found 1 incompatibility
The package `urllib3` requires Python >=3.8, but `3.12.[X]` is installed
"
);
}

View File

@ -4823,7 +4823,54 @@ uv pip check [OPTIONS]
<p>By default, uv checks packages in a virtual environment but will check packages in a system <p>By default, uv checks packages in a virtual environment but will check packages in a system
Python environment if no virtual environment is found.</p> Python environment if no virtual environment is found.</p>
<p>See <a href="#uv-python">uv python</a> for details on Python discovery and supported request formats.</p> <p>See <a href="#uv-python">uv python</a> for details on Python discovery and supported request formats.</p>
<p>May also be set with the <code>UV_PYTHON</code> environment variable.</p></dd><dt id="uv-pip-check--quiet"><a href="#uv-pip-check--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p> <p>May also be set with the <code>UV_PYTHON</code> environment variable.</p></dd><dt id="uv-pip-check--python-platform"><a href="#uv-pip-check--python-platform"><code>--python-platform</code></a> <i>python-platform</i></dt><dd><p>The platform for which packages should be checked.</p>
<p>By default, the installed packages are checked against the platform of the current interpreter.</p>
<p>Represented as a &quot;target triple&quot;, a string that describes the target platform in terms of its CPU, vendor, and operating system name, like <code>x86_64-unknown-linux-gnu</code> or <code>aarch64-apple-darwin</code>.</p>
<p>When targeting macOS (Darwin), the default minimum version is <code>12.0</code>. Use <code>MACOSX_DEPLOYMENT_TARGET</code> to specify a different minimum version, e.g., <code>13.0</code>.</p>
<p>Possible values:</p>
<ul>
<li><code>windows</code>: An alias for <code>x86_64-pc-windows-msvc</code>, the default target for Windows</li>
<li><code>linux</code>: An alias for <code>x86_64-unknown-linux-gnu</code>, the default target for Linux</li>
<li><code>macos</code>: An alias for <code>aarch64-apple-darwin</code>, the default target for macOS</li>
<li><code>x86_64-pc-windows-msvc</code>: A 64-bit x86 Windows target</li>
<li><code>aarch64-pc-windows-msvc</code>: An ARM64 Windows target</li>
<li><code>i686-pc-windows-msvc</code>: A 32-bit x86 Windows target</li>
<li><code>x86_64-unknown-linux-gnu</code>: An x86 Linux target. Equivalent to <code>x86_64-manylinux_2_28</code></li>
<li><code>aarch64-apple-darwin</code>: An ARM-based macOS target, as seen on Apple Silicon devices</li>
<li><code>x86_64-apple-darwin</code>: An x86 macOS target</li>
<li><code>aarch64-unknown-linux-gnu</code>: An ARM64 Linux target. Equivalent to <code>aarch64-manylinux_2_28</code></li>
<li><code>aarch64-unknown-linux-musl</code>: An ARM64 Linux target</li>
<li><code>x86_64-unknown-linux-musl</code>: An <code>x86_64</code> Linux target</li>
<li><code>x86_64-manylinux2014</code>: An <code>x86_64</code> target for the <code>manylinux2014</code> platform. Equivalent to <code>x86_64-manylinux_2_17</code></li>
<li><code>x86_64-manylinux_2_17</code>: An <code>x86_64</code> target for the <code>manylinux_2_17</code> platform</li>
<li><code>x86_64-manylinux_2_28</code>: An <code>x86_64</code> target for the <code>manylinux_2_28</code> platform</li>
<li><code>x86_64-manylinux_2_31</code>: An <code>x86_64</code> target for the <code>manylinux_2_31</code> platform</li>
<li><code>x86_64-manylinux_2_32</code>: An <code>x86_64</code> target for the <code>manylinux_2_32</code> platform</li>
<li><code>x86_64-manylinux_2_33</code>: An <code>x86_64</code> target for the <code>manylinux_2_33</code> platform</li>
<li><code>x86_64-manylinux_2_34</code>: An <code>x86_64</code> target for the <code>manylinux_2_34</code> platform</li>
<li><code>x86_64-manylinux_2_35</code>: An <code>x86_64</code> target for the <code>manylinux_2_35</code> platform</li>
<li><code>x86_64-manylinux_2_36</code>: An <code>x86_64</code> target for the <code>manylinux_2_36</code> platform</li>
<li><code>x86_64-manylinux_2_37</code>: An <code>x86_64</code> target for the <code>manylinux_2_37</code> platform</li>
<li><code>x86_64-manylinux_2_38</code>: An <code>x86_64</code> target for the <code>manylinux_2_38</code> platform</li>
<li><code>x86_64-manylinux_2_39</code>: An <code>x86_64</code> target for the <code>manylinux_2_39</code> platform</li>
<li><code>x86_64-manylinux_2_40</code>: An <code>x86_64</code> target for the <code>manylinux_2_40</code> platform</li>
<li><code>aarch64-manylinux2014</code>: An ARM64 target for the <code>manylinux2014</code> platform. Equivalent to <code>aarch64-manylinux_2_17</code></li>
<li><code>aarch64-manylinux_2_17</code>: An ARM64 target for the <code>manylinux_2_17</code> platform</li>
<li><code>aarch64-manylinux_2_28</code>: An ARM64 target for the <code>manylinux_2_28</code> platform</li>
<li><code>aarch64-manylinux_2_31</code>: An ARM64 target for the <code>manylinux_2_31</code> platform</li>
<li><code>aarch64-manylinux_2_32</code>: An ARM64 target for the <code>manylinux_2_32</code> platform</li>
<li><code>aarch64-manylinux_2_33</code>: An ARM64 target for the <code>manylinux_2_33</code> platform</li>
<li><code>aarch64-manylinux_2_34</code>: An ARM64 target for the <code>manylinux_2_34</code> platform</li>
<li><code>aarch64-manylinux_2_35</code>: An ARM64 target for the <code>manylinux_2_35</code> platform</li>
<li><code>aarch64-manylinux_2_36</code>: An ARM64 target for the <code>manylinux_2_36</code> platform</li>
<li><code>aarch64-manylinux_2_37</code>: An ARM64 target for the <code>manylinux_2_37</code> platform</li>
<li><code>aarch64-manylinux_2_38</code>: An ARM64 target for the <code>manylinux_2_38</code> platform</li>
<li><code>aarch64-manylinux_2_39</code>: An ARM64 target for the <code>manylinux_2_39</code> platform</li>
<li><code>aarch64-manylinux_2_40</code>: An ARM64 target for the <code>manylinux_2_40</code> platform</li>
<li><code>wasm32-pyodide2024</code>: A wasm32 target using the Pyodide 2024 platform. Meant for use with Python 3.12</li>
</ul></dd><dt id="uv-pip-check--python-version"><a href="#uv-pip-check--python-version"><code>--python-version</code></a> <i>python-version</i></dt><dd><p>The Python version against which packages should be checked.</p>
<p>By default, the installed packages are checked against the version of the current interpreter.</p>
</dd><dt id="uv-pip-check--quiet"><a href="#uv-pip-check--quiet"><code>--quiet</code></a>, <code>-q</code></dt><dd><p>Use quiet output.</p>
<p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which uv will write no output to stdout.</p> <p>Repeating this option, e.g., <code>-qq</code>, will enable a silent mode in which uv will write no output to stdout.</p>
</dd><dt id="uv-pip-check--system"><a href="#uv-pip-check--system"><code>--system</code></a></dt><dd><p>Check packages in the system Python environment.</p> </dd><dt id="uv-pip-check--system"><a href="#uv-pip-check--system"><code>--system</code></a></dt><dd><p>Check packages in the system Python environment.</p>
<p>Disables discovery of virtual environments.</p> <p>Disables discovery of virtual environments.</p>