MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / version_from_env

Function version_from_env

python3-sys/build.rs:411–431  ·  view source on GitHub ↗

Determine the python version we're supposed to be building from the features passed via the environment. The environment variable can choose to omit a minor version if the user doesn't care.

()

Source from the content-addressed store, hash-verified

409/// The environment variable can choose to omit a minor
410/// version if the user doesn't care.
411fn version_from_env() -> Result<PythonVersion, String> {
412 let re = Regex::new(r"CARGO_FEATURE_PYTHON_(\d+)(_(\d+))?").unwrap();
413 // sort env::vars so we get more explicit version specifiers first
414 // so if the user passes e.g. the python-3 feature and the python-3-5
415 // feature, python-3-5 takes priority.
416 let mut vars = env::vars().collect::<Vec<_>>();
417 vars.sort_by(|a, b| b.cmp(a));
418 for (key, _) in vars {
419 if let Some(cap) = re.captures(&key) {
420 return Ok(PythonVersion {
421 major: cap.get(1).unwrap().as_str().parse().unwrap(),
422 minor: cap.get(3).map(|s| s.as_str().parse().unwrap()),
423 });
424 }
425 }
426 Err(
427 "Python version feature was not found. At least one python version \
428 feature must be enabled."
429 .to_owned(),
430 )
431}
432
433fn main() {
434 // 1. Setup cfg variables so we can do conditional compilation in this

Callers 1

mainFunction · 0.70

Calls 3

cmpMethod · 0.80
mapMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected