diff --git a/src/build_options.rs b/src/build_options.rs index c8aa6db6e..7974a7463 100644 --- a/src/build_options.rs +++ b/src/build_options.rs @@ -9,7 +9,7 @@ use crate::{BuildContext, PythonInterpreter, Target}; use anyhow::{bail, format_err, Context, 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,10 @@ pub struct BuildOptions { #[arg(short = 'f', long, conflicts_with = "interpreter")] pub find_interpreter: bool, + /// Allow prerelease python interpreters + #[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, @@ -559,7 +563,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, @@ -587,6 +591,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, 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