diff --git a/Cargo.lock b/Cargo.lock index 07bb17fa6..cca57d850 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4595,6 +4595,7 @@ dependencies = [ "clap", "itertools 0.12.1", "pep508_rs", + "platform-tags", "rustc-hash", "schemars", "serde", diff --git a/crates/uv-configuration/Cargo.toml b/crates/uv-configuration/Cargo.toml index 848ff94e2..3ef6076ef 100644 --- a/crates/uv-configuration/Cargo.toml +++ b/crates/uv-configuration/Cargo.toml @@ -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 } diff --git a/crates/uv-configuration/src/lib.rs b/crates/uv-configuration/src/lib.rs index dce1dd1fd..96a539218 100644 --- a/crates/uv-configuration/src/lib.rs +++ b/crates/uv-configuration/src/lib.rs @@ -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; diff --git a/crates/uv/src/target.rs b/crates/uv-configuration/src/target_triple.rs similarity index 83% rename from crates/uv/src/target.rs rename to crates/uv-configuration/src/target_triple.rs index 70a279e36..e06350bfa 100644 --- a/crates/uv/src/target.rs +++ b/crates/uv-configuration/src/target_triple.rs @@ -5,8 +5,15 @@ use platform_tags::{Arch, Os, Platform}; /// system. /// /// See: -#[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(), diff --git a/crates/uv-workspace/src/settings.rs b/crates/uv-workspace/src/settings.rs index 77ab5bc74..0d6351eba 100644 --- a/crates/uv-workspace/src/settings.rs +++ b/crates/uv-workspace/src/settings.rs @@ -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, pub config_settings: Option, pub python_version: Option, + pub python_platform: Option, pub exclude_newer: Option, pub no_emit_package: Option>, pub emit_index_url: Option, diff --git a/crates/uv/src/cli.rs b/crates/uv/src/cli.rs index 59a0d8f2f..51ce09b21 100644 --- a/crates/uv/src/cli.rs +++ b/crates/uv/src/cli.rs @@ -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)] diff --git a/crates/uv/src/commands/pip_compile.rs b/crates/uv/src/commands/pip_compile.rs index 2a704666e..7e99dbee0 100644 --- a/crates/uv/src/commands/pip_compile.rs +++ b/crates/uv/src/commands/pip_compile.rs @@ -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)] diff --git a/crates/uv/src/main.rs b/crates/uv/src/main.rs index 475830117..bdf39bd27 100644 --- a/crates/uv/src/main.rs +++ b/crates/uv/src/main.rs @@ -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 { 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, diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 198ac0816..d33bcc9ba 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -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, pub(crate) constraint: Vec, pub(crate) r#override: Vec, - pub(crate) python_platform: Option, pub(crate) refresh: bool, pub(crate) refresh_package: Vec, 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::() }), 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, + pub(crate) python_platform: Option, pub(crate) exclude_newer: Option, pub(crate) no_emit_package: Vec, 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(), diff --git a/uv.schema.json b/uv.schema.json index 9bf6dff5f..47ff009ec 100644 --- a/uv.schema.json +++ b/uv.schema.json @@ -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: ", + "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" + ] + } + ] } } } \ No newline at end of file