Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add allow prerelease flag #2006

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -175,6 +175,10 @@ pub struct BuildOptions {
#[arg(short = 'f', long, conflicts_with = "interpreter")]
pub find_interpreter: bool,

/// Allow prerelease python interpreters
#[arg(long)]
messense marked this conversation as resolved.
Show resolved Hide resolved
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<String>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be enough, I think it also need patch version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python 3.13.0a6 (main, Apr 10 2024, 01:20:43) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=13, micro=0, releaselevel='alpha', serial=6)
>>> sys.version
'3.13.0a6 (main, Apr 10 2024, 01:20:43) [GCC 12.2.0]'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interp config only has major and minor, missing micro,we should pass minor to it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can modify interp config to add more detailed version info.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can remove major and minor, add version: pep440_rs::Version instead to interpreter config and maybe other places. I might give it a try on the weekend.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

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());
Expand Down
1 change: 1 addition & 0 deletions src/develop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions tests/cmd/build.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Options:
-f, --find-interpreter
Find interpreters from the host machine

--allow-prereleases
Allow prerelease python interpreters

-b, --bindings <BINDINGS>
Which kind of bindings to use

Expand Down
3 changes: 3 additions & 0 deletions tests/cmd/publish.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Options:
-f, --find-interpreter
Find interpreters from the host machine

--allow-prereleases
Allow prerelease python interpreters

-b, --bindings <BINDINGS>
Which kind of bindings to use

Expand Down