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

Function get_config_from_interpreter

python3-sys/build.rs:315–333  ·  view source on GitHub ↗

Extract compilation vars from the specified interpreter.

(
    interpreter: &str,
)

Source from the content-addressed store, hash-verified

313
314/// Extract compilation vars from the specified interpreter.
315fn get_config_from_interpreter(
316 interpreter: &str,
317) -> Result<(String, PythonVersion, Vec<String>), String> {
318 let script = "import sys; import sysconfig; print(sys.executable); \
319print(sys.version_info[0:2]); \
320print(sysconfig.get_config_var('LIBDIR')); \
321print(sysconfig.get_config_var('Py_ENABLE_SHARED')); \
322print(sysconfig.get_config_var('LDVERSION') or '%s%s' % (sysconfig.get_config_var('py_version_short'), sysconfig.get_config_var('DEBUG_EXT') or '')); \
323print(sys.exec_prefix);";
324 let out = run_python_script(interpreter, script)?;
325 let mut lines: Vec<String> = out
326 .split(NEWLINE_SEQUENCE)
327 .map(|line| line.to_owned())
328 .collect();
329 let executable = lines.remove(0);
330 let interpreter_version = lines.remove(0);
331 let interpreter_version = get_interpreter_version(&interpreter_version)?;
332 Ok((executable, interpreter_version, lines))
333}
334
335/// Deduce configuration from the 'python' in the current PATH and print
336/// cargo vars to stdout.

Callers 1

Calls 4

collectMethod · 0.80
mapMethod · 0.80
run_python_scriptFunction · 0.70
get_interpreter_versionFunction · 0.70

Tested by

no test coverage detected