From da1d02ebe29d3defd0c308c986a1615147b88395 Mon Sep 17 00:00:00 2001 From: fatelei Date: Sat, 23 Mar 2024 23:29:17 +0800 Subject: [PATCH 1/5] feat: add allow prerelease flag --- src/build_options.rs | 17 +++++++++++++++-- src/develop.rs | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/build_options.rs b/src/build_options.rs index c8aa6db6e..c70f46a92 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -6,10 +6,10 @@ use crate::project_layout::ProjectResolver; use crate::pyproject_toml::ToolMaturin; use crate::python_interpreter::{InterpreterConfig, InterpreterKind, MINIMUM_PYTHON_MINOR}; use crate::{BuildContext, PythonInterpreter, Target}; -use anyhow::{bail, format_err, Context, Result}; +use anyhow::{bail, format_err, Context, Ok, Result}; use cargo_metadata::{Metadata, Node}; use cargo_options::heading; -use pep440_rs::VersionSpecifiers; +use pep440_rs::{Version, VersionSpecifiers}; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::env; @@ -175,6 +175,9 @@ pub struct BuildOptions { #[arg(short = 'f', long, conflicts_with = "interpreter")] pub find_interpreter: bool, + #[arg(long)] + pub allow_prereleases: bool, + /// Which kind of bindings to use. #[arg(short, long, value_parser = ["pyo3", "pyo3-ffi", "rust-cpython", "cffi", "uniffi", "bin"])] pub bindings: Option, @@ -587,6 +590,16 @@ impl BuildOptions { self.find_interpreters(&bridge, &interpreter, &target, None, generate_import_lib)? }; + if !self.allow_prereleases { + interpreter.retain(|interp| { + let version = Version::new([interp.config.major as u64, interp.config.minor as u64]); + if version.any_prerelease() { + eprintln!("⚠️ Warning: python version is pre release, need pass flag --allow-prereleases"); + } + !version.any_prerelease() + }); + } + if cargo_options.args.is_empty() { // if not supplied on command line, try pyproject.toml let tool_maturin = pyproject.and_then(|p| p.maturin()); diff --git a/src/develop.rs b/src/develop.rs index 3ec51026d..e9db93a99 100644 --- a/src/develop.rs +++ b/src/develop.rs @@ -333,6 +333,7 @@ pub fn develop(develop_options: DevelopOptions, venv_dir: &Path) -> Result<()> { platform_tag: vec![PlatformTag::Linux], interpreter: vec![python.clone()], find_interpreter: false, + allow_prereleases: true, bindings, out: Some(wheel_dir.path().to_path_buf()), skip_auditwheel: false, From d31c1f350714452d3def304d47d7caab697f2368 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 10 Apr 2024 09:34:57 +0800 Subject: [PATCH 2/5] Update src/build_options.rs --- src/build_options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build_options.rs b/src/build_options.rs index c70f46a92..d8cef0b6c 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -6,7 +6,7 @@ use crate::project_layout::ProjectResolver; use crate::pyproject_toml::ToolMaturin; use crate::python_interpreter::{InterpreterConfig, InterpreterKind, MINIMUM_PYTHON_MINOR}; use crate::{BuildContext, PythonInterpreter, Target}; -use anyhow::{bail, format_err, Context, Ok, Result}; +use anyhow::{bail, format_err, Context, Result}; use cargo_metadata::{Metadata, Node}; use cargo_options::heading; use pep440_rs::{Version, VersionSpecifiers}; From 9f03e56d19df5427a5358d542796783cc35aafa3 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 10 Apr 2024 09:53:09 +0800 Subject: [PATCH 3/5] Update build_options.rs --- src/build_options.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build_options.rs b/src/build_options.rs index d8cef0b6c..d2c48e4e9 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -562,7 +562,7 @@ impl BuildOptions { }; let generate_import_lib = is_generating_import_lib(&cargo_metadata)?; - let interpreter = if self.find_interpreter { + let mut interpreter = if self.find_interpreter { // Auto-detect interpreters self.find_interpreters( &bridge, From 014dd3f23837300e1a501b03e2a067ea3c55eba1 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 10 Apr 2024 10:25:33 +0800 Subject: [PATCH 4/5] Update src/build_options.rs --- src/build_options.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/build_options.rs b/src/build_options.rs index d2c48e4e9..7974a7463 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -175,6 +175,7 @@ pub struct BuildOptions { #[arg(short = 'f', long, conflicts_with = "interpreter")] pub find_interpreter: bool, + /// Allow prerelease python interpreters #[arg(long)] pub allow_prereleases: bool, From 400f0e76392110df8a096427fc583530f4e17138 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 10 Apr 2024 19:36:57 +0800 Subject: [PATCH 5/5] Fix cli tests --- tests/cmd/build.stdout | 3 +++ tests/cmd/publish.stdout | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/cmd/build.stdout b/tests/cmd/build.stdout index 0e2b600f3..ea9668485 100644 --- a/tests/cmd/build.stdout +++ b/tests/cmd/build.stdout @@ -34,6 +34,9 @@ Options: -f, --find-interpreter Find interpreters from the host machine + --allow-prereleases + Allow prerelease python interpreters + -b, --bindings Which kind of bindings to use diff --git a/tests/cmd/publish.stdout b/tests/cmd/publish.stdout index 8009f5f0d..7613324c1 100644 --- a/tests/cmd/publish.stdout +++ b/tests/cmd/publish.stdout @@ -80,6 +80,9 @@ Options: -f, --find-interpreter Find interpreters from the host machine + --allow-prereleases + Allow prerelease python interpreters + -b, --bindings Which kind of bindings to use