Skip to content

Commit

Permalink
Merge #2926
Browse files Browse the repository at this point in the history
2926: Warn about unknown config keys in `PYO3_CONFIG_FILE` r=davidhewitt a=messense

`maturin` also read from `PYO3_CONFIG_FILE` to get `ext_suffix` config, `pyo3-build-config` currently denies unknown config keys makes it inconvenient.

See PyO3/maturin#1430

Co-authored-by: messense <[email protected]>
  • Loading branch information
bors[bot] and messense authored Jan 29, 2023
2 parents 165062e + f8e2a26 commit 3149a80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/2926.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warn about unknown config keys in `PYO3_CONFIG_FILE` instead of denying.
3 changes: 3 additions & 0 deletions pyo3-build-config/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ macro_rules! warn {
($msg: literal) => {
println!(concat!("cargo:warning=", $msg))
};
($fmt: expr, $($args: tt)+) => {
println!("cargo:warning={}", format_args!($fmt, $($args)+))
};
}

/// A simple error implementation which allows chaining of errors, inspired somewhat by anyhow.
Expand Down
24 changes: 23 additions & 1 deletion pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ print("mingw", get_platform().startswith("mingw"))
"extra_build_script_line" => {
extra_build_script_lines.push(value.to_string());
}
unknown => bail!("unknown config key `{}`", unknown),
unknown => warn!("unknown config key `{}`", unknown),
}
}

Expand Down Expand Up @@ -1865,6 +1865,28 @@ mod tests {
)
}

#[test]
fn test_config_file_unknown_keys() {
// ext_suffix is unknown to pyo3-build-config, but it shouldn't error
assert_eq!(
InterpreterConfig::from_reader("version=3.7\next_suffix=.python37.so".as_bytes())
.unwrap(),
InterpreterConfig {
version: PythonVersion { major: 3, minor: 7 },
implementation: PythonImplementation::CPython,
shared: true,
abi3: false,
lib_name: None,
lib_dir: None,
executable: None,
pointer_width: None,
build_flags: BuildFlags::default(),
suppress_build_script_link_lines: false,
extra_build_script_lines: vec![],
}
)
}

#[test]
fn build_flags_default() {
assert_eq!(BuildFlags::default(), BuildFlags::new());
Expand Down

0 comments on commit 3149a80

Please sign in to comment.