Skip to content

Commit

Permalink
test and newsfragment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Dec 3, 2024
1 parent 53cea3e commit e394f20
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/4758.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix compile-time regression in PyO3 0.23.0 where changing `PYO3_CONFIG_FILE` would not reconfigure PyO3 for the new interpreter.
24 changes: 22 additions & 2 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#[path = "import_lib.rs"]
mod import_lib;

#[cfg(test)]
use std::cell::RefCell;
use std::{
collections::{HashMap, HashSet},
env,
Expand All @@ -15,8 +17,7 @@ use std::{
io::{BufRead, BufReader, Read, Write},
path::{Path, PathBuf},
process::{Command, Stdio},
str,
str::FromStr,
str::{self, FromStr},
};

pub use target_lexicon::Triple;
Expand All @@ -41,6 +42,11 @@ const MINIMUM_SUPPORTED_VERSION_GRAALPY: PythonVersion = PythonVersion {
/// Maximum Python version that can be used as minimum required Python version with abi3.
pub(crate) const ABI3_MAX_MINOR: u8 = 12;

#[cfg(test)]
thread_local! {
static READ_ENV_VARS: RefCell<Vec<String>> = RefCell::new(Vec::new());
}

/// Gets an environment variable owned by cargo.
///
/// Environment variables set by cargo are expected to be valid UTF8.
Expand All @@ -54,6 +60,12 @@ pub fn env_var(var: &str) -> Option<OsString> {
if cfg!(feature = "resolve-config") {
println!("cargo:rerun-if-env-changed={}", var);
}
#[cfg(test)]
{
READ_ENV_VARS.with(|env_vars| {
env_vars.borrow_mut().push(var.to_owned());
});
}
env::var_os(var)
}

Expand Down Expand Up @@ -3070,4 +3082,12 @@ mod tests {
"
));
}

#[test]
fn test_from_pyo3_config_file_env_rebuild() {
READ_ENV_VARS.with(|vars| vars.borrow_mut().clear());
let _ = InterpreterConfig::from_pyo3_config_file_env();
READ_ENV_VARS
.with(|vars| assert_eq!(vars.borrow().as_slice(), &["PYO3_CONFIG_FILE".to_string()]));
}
}

0 comments on commit e394f20

Please sign in to comment.