Skip to content

Commit

Permalink
Remove dead code. Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Anderson committed Nov 19, 2021
1 parent 7bbfe99 commit 664c31d
Showing 1 changed file with 11 additions and 77 deletions.
88 changes: 11 additions & 77 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ print("mingw", get_platform().startswith("mingw"))
})
}

#[doc(hidden)]
/// Generate from parsed sysconfigdata file
///
/// Use [`parse_sysconfigdata`](parse_sysconfigdata) to generate a hash map of
/// configuration values which may be used to build an `InterpreterConfig`.
pub fn from_sysconfigdata(sysconfigdata: Sysconfigdata) -> Result<Self> {
macro_rules! get_key {
($sysconfigdata:expr, $key:literal) => {
Expand Down Expand Up @@ -730,20 +733,6 @@ impl BuildFlags {
)
}

fn from_config_map(config_map: &HashMap<String, String>) -> Self {
Self(
BuildFlags::ALL
.iter()
.cloned()
.filter(|flag| {
config_map
.get(&flag.to_string())
.map_or(false, |value| value == "1")
})
.collect(),
)
}

/// Examine python's compile flags to pass to cfg by launching
/// the interpreter and printing variables of interest from
/// sysconfig.get_config_vars.
Expand Down Expand Up @@ -846,6 +835,9 @@ fn parse_script_output(output: &str) -> HashMap<String, String> {
.collect()
}

/// Parsed data from Python sysconfigdata file
///
/// A hash map of all values from a sysconfigdata file.
pub struct Sysconfigdata(std::collections::HashMap<String, String>);

impl Sysconfigdata {
Expand All @@ -857,8 +849,10 @@ impl Sysconfigdata {
/// 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.
/// python executable and library. This function necessitates a python interpreter on the host
/// machine to work. Here it is read into a `Sysconfigdata` (hash map), which can be turned into an
/// [`InterpreterConfig`](InterpreterConfig) using
/// [`from_sysconfigdata`](InterpreterConfig::from_sysconfigdata).
pub fn parse_sysconfigdata(sysconfigdata_path: impl AsRef<Path>) -> Result<Sysconfigdata> {
let sysconfigdata_path = sysconfigdata_path.as_ref();
let mut script = fs::read_to_string(&sysconfigdata_path).with_context(|| {
Expand All @@ -877,66 +871,6 @@ for key, val in build_time_vars.items():
Ok(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 starts_with(entry: &DirEntry, pat: &str) -> bool {
let name = entry.file_name();
name.to_string_lossy().starts_with(pat)
Expand Down

0 comments on commit 664c31d

Please sign in to comment.