mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
Add --python-platform
to configuration (#3147)
## Summary Just for consistency with `--python-version`.
This commit is contained in:
parent
5e4e2fa0bf
commit
70b6bde254
10 changed files with 128 additions and 28 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -4595,6 +4595,7 @@ dependencies = [
|
|||
"clap",
|
||||
"itertools 0.12.1",
|
||||
"pep508_rs",
|
||||
"platform-tags",
|
||||
"rustc-hash",
|
||||
"schemars",
|
||||
"serde",
|
||||
|
|
|
@ -14,6 +14,7 @@ workspace = true
|
|||
|
||||
[dependencies]
|
||||
pep508_rs = { workspace = true }
|
||||
platform-tags = { workspace = true }
|
||||
uv-cache = { workspace = true }
|
||||
uv-auth = { workspace = true }
|
||||
uv-normalize = { workspace = true }
|
||||
|
|
|
@ -5,6 +5,7 @@ pub use constraints::*;
|
|||
pub use name_specifiers::*;
|
||||
pub use overrides::*;
|
||||
pub use package_options::*;
|
||||
pub use target_triple::*;
|
||||
|
||||
mod authentication;
|
||||
mod build_options;
|
||||
|
@ -13,3 +14,4 @@ mod constraints;
|
|||
mod name_specifiers;
|
||||
mod overrides;
|
||||
mod package_options;
|
||||
mod target_triple;
|
||||
|
|
|
@ -5,8 +5,15 @@ use platform_tags::{Arch, Os, Platform};
|
|||
/// system.
|
||||
///
|
||||
/// See: <https://doc.rust-lang.org/nightly/rustc/platform-support.html>
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, clap::ValueEnum)]
|
||||
pub(crate) enum TargetTriple {
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
|
||||
#[cfg_attr(
|
||||
feature = "serde",
|
||||
serde(deny_unknown_fields, rename_all = "kebab-case")
|
||||
)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub enum TargetTriple {
|
||||
/// An alias for `x86_64-pc-windows-msvc`, the default target for Windows.
|
||||
Windows,
|
||||
|
||||
|
@ -17,37 +24,37 @@ pub(crate) enum TargetTriple {
|
|||
Macos,
|
||||
|
||||
/// An x86 Windows target.
|
||||
#[value(name = "x86_64-pc-windows-msvc")]
|
||||
#[cfg_attr(feature = "clap", value(name = "x86_64-pc-windows-msvc"))]
|
||||
X8664PcWindowsMsvc,
|
||||
|
||||
/// An x86 Linux target.
|
||||
#[value(name = "x86_64-unknown-linux-gnu")]
|
||||
#[cfg_attr(feature = "clap", value(name = "x86_64-unknown-linux-gnu"))]
|
||||
X8664UnknownLinuxGnu,
|
||||
|
||||
/// An ARM-based macOS target, as seen on Apple Silicon devices.
|
||||
#[value(name = "aarch64-apple-darwin")]
|
||||
#[cfg_attr(feature = "clap", value(name = "aarch64-apple-darwin"))]
|
||||
Aarch64AppleDarwin,
|
||||
|
||||
/// An x86 macOS target.
|
||||
#[value(name = "x86_64-apple-darwin")]
|
||||
#[cfg_attr(feature = "clap", value(name = "x86_64-apple-darwin"))]
|
||||
X8664AppleDarwin,
|
||||
|
||||
/// An ARM64 Linux target.
|
||||
#[value(name = "aarch64-unknown-linux-gnu")]
|
||||
#[cfg_attr(feature = "clap", value(name = "aarch64-unknown-linux-gnu"))]
|
||||
Aarch64UnknownLinuxGnu,
|
||||
|
||||
/// An ARM64 Linux target.
|
||||
#[value(name = "aarch64-unknown-linux-musl")]
|
||||
#[cfg_attr(feature = "clap", value(name = "aarch64-unknown-linux-musl"))]
|
||||
Aarch64UnknownLinuxMusl,
|
||||
|
||||
/// An x86_64 Linux target.
|
||||
#[value(name = "x86_64-unknown-linux-musl")]
|
||||
#[cfg_attr(feature = "clap", value(name = "x86_64-unknown-linux-musl"))]
|
||||
X8664UnknownLinuxMusl,
|
||||
}
|
||||
|
||||
impl TargetTriple {
|
||||
/// Return the [`Platform`] for the target.
|
||||
pub(crate) fn platform(self) -> Platform {
|
||||
pub fn platform(self) -> Platform {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => Platform::new(Os::Windows, Arch::X86_64),
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => Platform::new(
|
||||
|
@ -88,7 +95,7 @@ impl TargetTriple {
|
|||
}
|
||||
|
||||
/// Return the `platform_machine` value for the target.
|
||||
pub(crate) fn platform_machine(self) -> &'static str {
|
||||
pub fn platform_machine(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => "x86_64",
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => "x86_64",
|
||||
|
@ -101,7 +108,7 @@ impl TargetTriple {
|
|||
}
|
||||
|
||||
/// Return the `platform_system` value for the target.
|
||||
pub(crate) fn platform_system(self) -> &'static str {
|
||||
pub fn platform_system(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => "Windows",
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => "Linux",
|
||||
|
@ -114,7 +121,7 @@ impl TargetTriple {
|
|||
}
|
||||
|
||||
/// Return the `platform_version` value for the target.
|
||||
pub(crate) fn platform_version(self) -> &'static str {
|
||||
pub fn platform_version(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => "",
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => "",
|
||||
|
@ -127,7 +134,7 @@ impl TargetTriple {
|
|||
}
|
||||
|
||||
/// Return the `platform_release` value for the target.
|
||||
pub(crate) fn platform_release(self) -> &'static str {
|
||||
pub fn platform_release(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => "",
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => "",
|
||||
|
@ -140,7 +147,7 @@ impl TargetTriple {
|
|||
}
|
||||
|
||||
/// Return the `os_name` value for the target.
|
||||
pub(crate) fn os_name(self) -> &'static str {
|
||||
pub fn os_name(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => "nt",
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => "posix",
|
||||
|
@ -153,7 +160,7 @@ impl TargetTriple {
|
|||
}
|
||||
|
||||
/// Return the `sys_platform` value for the target.
|
||||
pub(crate) fn sys_platform(self) -> &'static str {
|
||||
pub fn sys_platform(self) -> &'static str {
|
||||
match self {
|
||||
Self::Windows | Self::X8664PcWindowsMsvc => "win32",
|
||||
Self::Linux | Self::X8664UnknownLinuxGnu => "linux",
|
||||
|
@ -170,7 +177,7 @@ impl TargetTriple {
|
|||
///
|
||||
/// The returned [`MarkerEnvironment`] will preserve the base environment's Python version
|
||||
/// markers, but override its platform markers.
|
||||
pub(crate) fn markers(self, base: &MarkerEnvironment) -> MarkerEnvironment {
|
||||
pub fn markers(self, base: &MarkerEnvironment) -> MarkerEnvironment {
|
||||
MarkerEnvironment {
|
||||
// Platform markers
|
||||
os_name: self.os_name().to_string(),
|
|
@ -4,7 +4,9 @@ use serde::Deserialize;
|
|||
|
||||
use distribution_types::{FlatIndexLocation, IndexUrl};
|
||||
use install_wheel_rs::linker::LinkMode;
|
||||
use uv_configuration::{ConfigSettings, IndexStrategy, KeyringProviderType, PackageNameSpecifier};
|
||||
use uv_configuration::{
|
||||
ConfigSettings, IndexStrategy, KeyringProviderType, PackageNameSpecifier, TargetTriple,
|
||||
};
|
||||
use uv_normalize::{ExtraName, PackageName};
|
||||
use uv_resolver::{AnnotationStyle, ExcludeNewer, PreReleaseMode, ResolutionMode};
|
||||
use uv_toolchain::PythonVersion;
|
||||
|
@ -70,6 +72,7 @@ pub struct PipOptions {
|
|||
pub legacy_setup_py: Option<bool>,
|
||||
pub config_settings: Option<ConfigSettings>,
|
||||
pub python_version: Option<PythonVersion>,
|
||||
pub python_platform: Option<TargetTriple>,
|
||||
pub exclude_newer: Option<ExcludeNewer>,
|
||||
pub no_emit_package: Option<Vec<PackageName>>,
|
||||
pub emit_index_url: Option<bool>,
|
||||
|
|
|
@ -9,7 +9,7 @@ use clap::{Args, Parser, Subcommand};
|
|||
use distribution_types::{FlatIndexLocation, IndexUrl};
|
||||
use uv_cache::CacheArgs;
|
||||
use uv_configuration::{
|
||||
ConfigSettingEntry, IndexStrategy, KeyringProviderType, PackageNameSpecifier,
|
||||
ConfigSettingEntry, IndexStrategy, KeyringProviderType, PackageNameSpecifier, TargetTriple,
|
||||
};
|
||||
use uv_normalize::{ExtraName, PackageName};
|
||||
use uv_resolver::{AnnotationStyle, ExcludeNewer, PreReleaseMode, ResolutionMode};
|
||||
|
@ -17,7 +17,6 @@ use uv_toolchain::PythonVersion;
|
|||
|
||||
use crate::commands::{extra_name_with_clap_error, ListFormat, VersionFormat};
|
||||
use crate::compat;
|
||||
use crate::target::TargetTriple;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, long_version = crate::version::version(), about)]
|
||||
|
|
|
@ -20,11 +20,11 @@ use requirements_txt::EditableRequirement;
|
|||
use uv_auth::store_credentials_from_url;
|
||||
use uv_cache::Cache;
|
||||
use uv_client::{BaseClientBuilder, Connectivity, FlatIndexClient, RegistryClientBuilder};
|
||||
use uv_configuration::KeyringProviderType;
|
||||
use uv_configuration::{
|
||||
ConfigSettings, Constraints, IndexStrategy, NoBinary, NoBuild, Overrides, SetupPyStrategy,
|
||||
Upgrade,
|
||||
};
|
||||
use uv_configuration::{KeyringProviderType, TargetTriple};
|
||||
use uv_dispatch::BuildDispatch;
|
||||
use uv_fs::Simplified;
|
||||
use uv_installer::Downloader;
|
||||
|
@ -46,7 +46,6 @@ use uv_warnings::warn_user;
|
|||
use crate::commands::reporters::{DownloadReporter, ResolverReporter};
|
||||
use crate::commands::{elapsed, ExitStatus};
|
||||
use crate::printer::Printer;
|
||||
use crate::target::TargetTriple;
|
||||
|
||||
/// Resolve a set of requirements into a set of pinned versions.
|
||||
#[allow(clippy::too_many_arguments, clippy::fn_params_excessive_bools)]
|
||||
|
|
|
@ -50,7 +50,6 @@ mod logging;
|
|||
mod printer;
|
||||
mod settings;
|
||||
mod shell;
|
||||
mod target;
|
||||
mod version;
|
||||
|
||||
#[instrument]
|
||||
|
@ -255,7 +254,7 @@ async fn run() -> Result<ExitStatus> {
|
|||
args.shared.no_build_isolation,
|
||||
no_build,
|
||||
args.shared.python_version,
|
||||
args.python_platform,
|
||||
args.shared.python_platform,
|
||||
args.shared.exclude_newer,
|
||||
args.shared.annotation_style,
|
||||
args.shared.link_mode,
|
||||
|
|
|
@ -3,7 +3,9 @@ use std::path::PathBuf;
|
|||
use distribution_types::{FlatIndexLocation, IndexUrl};
|
||||
use install_wheel_rs::linker::LinkMode;
|
||||
use uv_cache::CacheArgs;
|
||||
use uv_configuration::{ConfigSettings, IndexStrategy, KeyringProviderType, PackageNameSpecifier};
|
||||
use uv_configuration::{
|
||||
ConfigSettings, IndexStrategy, KeyringProviderType, PackageNameSpecifier, TargetTriple,
|
||||
};
|
||||
use uv_normalize::{ExtraName, PackageName};
|
||||
use uv_resolver::{AnnotationStyle, ExcludeNewer, PreReleaseMode, ResolutionMode};
|
||||
use uv_toolchain::PythonVersion;
|
||||
|
@ -14,7 +16,6 @@ use crate::cli::{
|
|||
PipListArgs, PipShowArgs, PipSyncArgs, PipUninstallArgs, VenvArgs,
|
||||
};
|
||||
use crate::commands::ListFormat;
|
||||
use crate::target::TargetTriple;
|
||||
|
||||
/// The resolved global settings to use for any invocation of the CLI.
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
|
@ -75,7 +76,6 @@ pub(crate) struct PipCompileSettings {
|
|||
pub(crate) src_file: Vec<PathBuf>,
|
||||
pub(crate) constraint: Vec<PathBuf>,
|
||||
pub(crate) r#override: Vec<PathBuf>,
|
||||
pub(crate) python_platform: Option<TargetTriple>,
|
||||
pub(crate) refresh: bool,
|
||||
pub(crate) refresh_package: Vec<PackageName>,
|
||||
pub(crate) upgrade: bool,
|
||||
|
@ -155,7 +155,7 @@ impl PipCompileSettings {
|
|||
src_file,
|
||||
constraint,
|
||||
r#override,
|
||||
python_platform,
|
||||
|
||||
refresh,
|
||||
refresh_package: refresh_package.unwrap_or_default(),
|
||||
upgrade,
|
||||
|
@ -201,6 +201,7 @@ impl PipCompileSettings {
|
|||
config_settings.into_iter().collect::<ConfigSettings>()
|
||||
}),
|
||||
python_version,
|
||||
python_platform,
|
||||
exclude_newer,
|
||||
no_emit_package,
|
||||
emit_index_url: flag(emit_index_url, no_emit_index_url),
|
||||
|
@ -777,6 +778,7 @@ pub(crate) struct PipSharedSettings {
|
|||
pub(crate) legacy_setup_py: bool,
|
||||
pub(crate) config_setting: ConfigSettings,
|
||||
pub(crate) python_version: Option<PythonVersion>,
|
||||
pub(crate) python_platform: Option<TargetTriple>,
|
||||
pub(crate) exclude_newer: Option<ExcludeNewer>,
|
||||
pub(crate) no_emit_package: Vec<PackageName>,
|
||||
pub(crate) emit_index_url: bool,
|
||||
|
@ -822,6 +824,7 @@ impl PipSharedSettings {
|
|||
legacy_setup_py,
|
||||
config_settings,
|
||||
python_version,
|
||||
python_platform,
|
||||
exclude_newer,
|
||||
no_emit_package,
|
||||
emit_index_url,
|
||||
|
@ -871,6 +874,7 @@ impl PipSharedSettings {
|
|||
only_binary: args.only_binary.or(only_binary).unwrap_or_default(),
|
||||
config_setting: args.config_settings.or(config_settings).unwrap_or_default(),
|
||||
python_version: args.python_version.or(python_version),
|
||||
python_platform: args.python_platform.or(python_platform),
|
||||
exclude_newer: args.exclude_newer.or(exclude_newer),
|
||||
no_emit_package: args.no_emit_package.or(no_emit_package).unwrap_or_default(),
|
||||
emit_index_url: args.emit_index_url.or(emit_index_url).unwrap_or_default(),
|
||||
|
|
85
uv.schema.json
generated
85
uv.schema.json
generated
|
@ -436,6 +436,16 @@
|
|||
"null"
|
||||
]
|
||||
},
|
||||
"python-platform": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/TargetTriple"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"python-version": {
|
||||
"anyOf": [
|
||||
{
|
||||
|
@ -543,6 +553,81 @@
|
|||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"TargetTriple": {
|
||||
"description": "The supported target triples. Each triple consists of an architecture, vendor, and operating system.\n\nSee: <https://doc.rust-lang.org/nightly/rustc/platform-support.html>",
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "An alias for `x86_64-pc-windows-msvc`, the default target for Windows.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"windows"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An alias for `x86_64-unknown-linux-gnu`, the default target for Linux.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An alias for `aarch64-apple-darwin`, the default target for macOS.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"macos"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An x86 Windows target.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"x8664-pc-windows-msvc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An x86 Linux target.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"x8664-unknown-linux-gnu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An ARM-based macOS target, as seen on Apple Silicon devices.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"aarch64-apple-darwin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An x86 macOS target.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"x8664-apple-darwin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An ARM64 Linux target.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"aarch64-unknown-linux-gnu"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An ARM64 Linux target.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"aarch64-unknown-linux-musl"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "An x86_64 Linux target.",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"x8664-unknown-linux-musl"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue