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

Add support for PYO3_ENVIRONMENT_SIGNATURE #1263

Merged
merged 3 commits into from
Nov 11, 2022
Merged
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
3 changes: 3 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[profile.default]
# Terminate slow tests after 5 minutes
slow-timeout = { period = "60s", terminate-after = 5 }
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ fn compile_target(
|| (matches!(bindings_crate, BridgeModel::BindingsAbi3(_, _))
&& interpreter.interpreter_kind.is_pypy())
{
build_command.env("PYO3_PYTHON", &interpreter.executable);
build_command
.env("PYO3_PYTHON", &interpreter.executable)
.env(
"PYO3_ENVIRONMENT_SIGNATURE",
interpreter.environment_signature(),
);
}

// rust-cpython, and legacy pyo3 versions
Expand Down
10 changes: 10 additions & 0 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,16 @@ impl PythonInterpreter {
}
}
}

/// An opaque string that uniquely identifies this Python interpreter.
/// Used to trigger rebuilds for `pyo3` when the Python interpreter changes.
pub fn environment_signature(&self) -> String {
let pointer_width = self.pointer_width.unwrap_or(64);
format!(
"{}-{}.{}-{}bit",
self.implmentation_name, self.major, self.minor, pointer_width
)
}
}

impl fmt::Display for PythonInterpreter {
Expand Down
1 change: 1 addition & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ fn integration_pyo3_mixed_src_layout() {
}

#[test]
#[cfg_attr(target_os = "macos", ignore)] // Don't run it on macOS, too slow
fn integration_pyo3_pure_conda() {
// Only run on GitHub Actions for now
if std::env::var("GITHUB_ACTIONS").is_ok() {
Expand Down