fn parse_sysconfigdata(sysconfigdata_path: impl AsRef<Path>) -> Result<InterpreterConfig> {
    let sysconfigdata_path = sysconfigdata_path.as_ref();
    let mut script = fs::read_to_string(&sysconfigdata_path).with_context(|| {
        format!(
            "failed to read config from {}",
            sysconfigdata_path.display()
        )
    })?;
    script += r#"
print("version", build_time_vars["VERSION"])
print("SOABI", build_time_vars.get("SOABI", ""))
if "LIBDIR" in build_time_vars:
    print("LIBDIR", build_time_vars["LIBDIR"])
KEYS = [
    "WITH_THREAD",
    "Py_DEBUG",
    "Py_REF_DEBUG",
    "Py_TRACE_REFS",
    "COUNT_ALLOCS",
    "Py_ENABLE_SHARED",
    "LDVERSION",
    "SIZEOF_VOID_P"
]
for key in KEYS:
    print(key, build_time_vars.get(key, 0))
"#;
    let output = run_python_script(&find_interpreter()?, &script)?;

    let sysconfigdata = parse_script_output(&output);

    macro_rules! get_key {
        ($sysconfigdata:expr, $key:literal) => {
            $sysconfigdata
                .get($key)
                .ok_or(concat!($key, " not found in sysconfigdata file"))
        };
    }

    macro_rules! parse_key {
        ($sysconfigdata:expr, $key:literal) => {
            get_key!($sysconfigdata, $key)?
                .parse()
                .context(concat!("could not parse value of ", $key))
        };
    }

    let version = parse_key!(sysconfigdata, "version")?;
    let pointer_width = parse_key!(sysconfigdata, "SIZEOF_VOID_P")
        .map(|bytes_width: u32| bytes_width * 8)
        .ok();

    let soabi = get_key!(sysconfigdata, "SOABI")?;
    let implementation = if soabi.starts_with("pypy") {
        PythonImplementation::PyPy
    } else if soabi.starts_with("cpython") {
        PythonImplementation::CPython
    } else {
        bail!("unsupported Python interpreter");
    };

    let shared = match sysconfigdata
        .get("Py_ENABLE_SHARED")
        .map(|string| string.as_str())
    {
        Some("1") | Some("true") | Some("True") => true,
        Some("0") | Some("false") | Some("False") | None => false,
        _ => bail!("expected a bool (1/true/True or 0/false/False) for Py_ENABLE_SHARED"),
    };

    Ok(InterpreterConfig {
        implementation,
        version,
        shared,
        abi3: is_abi3(),
        lib_dir: get_key!(sysconfigdata, "LIBDIR").ok().cloned(),
        lib_name: Some(default_lib_name_unix(
            version,
            implementation,
            sysconfigdata.get("LDVERSION").map(String::as_str),
        )),
        executable: None,
        pointer_width,
        build_flags: BuildFlags::from_config_map(&sysconfigdata).fixup(version, implementation),
        suppress_build_script_link_lines: false,
        extra_build_script_lines: vec![],
    })
}
/// Parse sysconfigdata file
///
/// The sysconfigdata is simply a dictionary containing all the build time variables used for the
/// python executable and library. Here it is read and added to a script to extract only what is
/// necessary. This necessitates a python interpreter for the host machine to work.
Parse sysconfigdata file
The sysconfigdata is simply a dictionary containing all the build time variables used for the
python executable and library. Here it is read and added to a script to extract only what is
necessary. This necessitates a python interpreter for the host machine to work.
Parse sysconfigdata file The sysconfigdata is simply a dictionary containing all the build time variables used for the python executable and library . Here it is read and added to a script to extract only what is necessary . This necessitates a python interpreter for the host machine to work .
fn parse_sysconfigdata(sysconfigdata_path: impl AsRef<Path>) -> Result<InterpreterConfig> {
    let sysconfigdata_path = sysconfigdata_path.as_ref();
    let mut script = fs::read_to_string(&sysconfigdata_path).with_context(|| {
        format!(
            "failed to read config from {}",
            sysconfigdata_path.display()
        )
    })?;
    script += r#"
print("version", build_time_vars["VERSION"])
print("SOABI", build_time_vars.get("SOABI", ""))
if "LIBDIR" in build_time_vars:
    print("LIBDIR", build_time_vars["LIBDIR"])
KEYS = [
    "WITH_THREAD",
    "Py_DEBUG",
    "Py_REF_DEBUG",
    "Py_TRACE_REFS",
    "COUNT_ALLOCS",
    "Py_ENABLE_SHARED",
    "LDVERSION",
    "SIZEOF_VOID_P"
]
for key in KEYS:
    print(key, build_time_vars.get(key, 0))
"#;
    let output = run_python_script(&find_interpreter()?, &script)?;
    let sysconfigdata = parse_script_output(&output);
    macro_rules! get_key {
        ($sysconfigdata:expr, $key:literal) => {
            $sysconfigdata
                .get($key)
                .ok_or(concat!($key, " not found in sysconfigdata file"))
        };
    }
    macro_rules! parse_key {
        ($sysconfigdata:expr, $key:literal) => {
            get_key!($sysconfigdata, $key)?
                .parse()
                .context(concat!("could not parse value of ", $key))
        };
    }
    let version = parse_key!(sysconfigdata, "version")?;
    let pointer_width = parse_key!(sysconfigdata, "SIZEOF_VOID_P")
        .map(|bytes_width: u32| bytes_width * 8)
        .ok();
    let soabi = get_key!(sysconfigdata, "SOABI")?;
    let implementation = if soabi.starts_with("pypy") {
        PythonImplementation::PyPy
    } else if soabi.starts_with("cpython") {
        PythonImplementation::CPython
    } else {
        bail!("unsupported Python interpreter");
    };
    let shared = match sysconfigdata
        .get("Py_ENABLE_SHARED")
        .map(|string| string.as_str())
    {
        Some("1") | Some("true") | Some("True") => true,
        Some("0") | Some("false") | Some("False") | None => false,
        _ => bail!("expected a bool (1/true/True or 0/false/False) for Py_ENABLE_SHARED"),
    };
    Ok(InterpreterConfig {
        implementation,
        version,
        shared,
        abi3: is_abi3(),
        lib_dir: get_key!(sysconfigdata, "LIBDIR").ok().cloned(),
        lib_name: Some(default_lib_name_unix(
            version,
            implementation,
            sysconfigdata.get("LDVERSION").map(String::as_str),
        )),
        executable: None,
        pointer_width,
        build_flags: BuildFlags::from_config_map(&sysconfigdata).fixup(version, implementation),
        suppress_build_script_link_lines: false,
        extra_build_script_lines: vec![],
    })
}
fn parse_sysconfigdata ( sysconfigdata_path : impl AsRef < Path > ) -> Result < InterpreterConfig > { let sysconfigdata_path = sysconfigdata_path . as_ref ( ) ; let mut script = fs :: read_to_string ( & sysconfigdata_path ) . with_context ( | | { format ! ( " " sysconfigdata_path display ( ) ) } ) ? ; script += r#"
print("version", build_time_vars["VERSION"])
print("SOABI", build_time_vars.get("SOABI", ""))
if "LIBDIR" in build_time_vars:
    print("LIBDIR", build_time_vars["LIBDIR"])
KEYS = [
    "WITH_THREAD",
    "Py_DEBUG",
    "Py_REF_DEBUG",
    "Py_TRACE_REFS",
    "COUNT_ALLOCS",
    "Py_ENABLE_SHARED",
    "LDVERSION",
    "SIZEOF_VOID_P"
]
for key in KEYS:
    print(key, build_time_vars.get(key, 0))
"# ; let output = run_python_script ( & find_interpreter ( ) ? , & script ) ? ; let sysconfigdata = parse_script_output ( & output ) ; macro_rules! get_key { ( $sysconfigdata : expr $key : literal ) => { $sysconfigdata get ( $key ) ok_or ( concat ( $key " " ) ) } ; } macro_rules! parse_key { ( $sysconfigdata : expr $key : literal ) => { get_key ( $sysconfigdata $key ) parse ( ) context ( concat ( " " $key ) ) } ; } let version = parse_key ! ( sysconfigdata " " ) ? ; let pointer_width = parse_key ! ( sysconfigdata " " ) . map ( | bytes_width : u32 | bytes_width * 8 ) . ok ( ) ; let soabi = get_key ! ( sysconfigdata " " ) ? ; let implementation = if soabi . starts_with ( " " ) { PythonImplementation :: PyPy } else if soabi . starts_with ( " " ) { PythonImplementation :: CPython } else { bail ! ( " " ) ; } ; let shared = match sysconfigdata . get ( " " ) . map ( | string | string . as_str ( ) ) { Some ( " " ) | Some ( " " ) | Some ( " " ) => true , Some ( " " ) | Some ( " " ) | Some ( " " ) | None => false , _ => bail ! ( " " ) , } ; Ok ( InterpreterConfig { implementation , version , shared , abi3 : is_abi3 ( ) , lib_dir : get_key ! ( sysconfigdata " " ) . ok ( ) . cloned ( ) , lib_name : Some ( default_lib_name_unix ( version , implementation , sysconfigdata . get ( " " ) . map ( String :: as_str ) , ) ) , executable : None , pointer_width , build_flags : BuildFlags :: from_config_map ( & sysconfigdata ) . fixup ( version , implementation ) , suppress_build_script_link_lines : false , extra_build_script_lines : vec ! [ ] , } ) }
Parse sysconfigdata file
The sysconfigdata is simply a dictionary containing all the build time variables used for the
python executable and library.
Parse sysconfigdata file The sysconfigdata is simply a dictionary containing all the build time variables used for the python executable and library .
sysconfigdata_path
impl AsRef<Path>