Skip to content

Commit

Permalink
Merge pull request #898 from messense/rm-python-interpreter-target
Browse files Browse the repository at this point in the history
Remove `target` field from `PythonInterpreter` struct
  • Loading branch information
messense authored May 4, 2022
2 parents 1b3316a + 23f9367 commit 847fe57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
19 changes: 6 additions & 13 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,14 @@ impl BuildContext {

fn auditwheel(
&self,
python_interpreter: Option<&PythonInterpreter>,
artifact: &Path,
platform_tag: Option<PlatformTag>,
) -> Result<(Policy, Vec<Library>)> {
if self.skip_auditwheel || self.editable {
return Ok((Policy::default(), Vec::new()));
}

let target = python_interpreter
.map(|x| &x.target)
.unwrap_or(&self.target);

get_policy_and_libs(artifact, platform_tag, target)
get_policy_and_libs(artifact, platform_tag, &self.target)
}

fn add_external_libs(
Expand Down Expand Up @@ -411,8 +406,7 @@ impl BuildContext {
python_interpreter,
Some(self.project_layout.extension_name()),
)?;
let (policy, external_libs) =
self.auditwheel(python_interpreter, &artifact, self.platform_tag)?;
let (policy, external_libs) = self.auditwheel(&artifact, self.platform_tag)?;
let (wheel_path, tag) = self.write_binding_wheel_abi3(
&artifact,
policy.platform_tag(),
Expand All @@ -439,7 +433,7 @@ impl BuildContext {
platform_tag: PlatformTag,
ext_libs: &[Library],
) -> Result<BuiltWheelMetadata> {
let tag = python_interpreter.get_tag(platform_tag, self.universal2)?;
let tag = python_interpreter.get_tag(&self.target, platform_tag, self.universal2)?;

let mut writer = WheelWriter::new(&tag, &self.out, &self.metadata21, &[tag.clone()])?;
self.add_external_libs(&mut writer, artifact, ext_libs)?;
Expand Down Expand Up @@ -481,8 +475,7 @@ impl BuildContext {
Some(python_interpreter),
Some(self.project_layout.extension_name()),
)?;
let (policy, external_libs) =
self.auditwheel(Some(python_interpreter), &artifact, self.platform_tag)?;
let (policy, external_libs) = self.auditwheel(&artifact, self.platform_tag)?;
let (wheel_path, tag) = self.write_binding_wheel(
python_interpreter,
&artifact,
Expand Down Expand Up @@ -573,7 +566,7 @@ impl BuildContext {
pub fn build_cffi_wheel(&self) -> Result<Vec<BuiltWheelMetadata>> {
let mut wheels = Vec::new();
let artifact = self.compile_cdylib(None, None)?;
let (policy, external_libs) = self.auditwheel(None, &artifact, self.platform_tag)?;
let (policy, external_libs) = self.auditwheel(&artifact, self.platform_tag)?;
let (wheel_path, tag) =
self.write_cffi_wheel(&artifact, policy.platform_tag(), &external_libs)?;

Expand Down Expand Up @@ -652,7 +645,7 @@ impl BuildContext {
.cloned()
.ok_or_else(|| anyhow!("Cargo didn't build a binary"))?;

let (policy, external_libs) = self.auditwheel(None, &artifact, self.platform_tag)?;
let (policy, external_libs) = self.auditwheel(&artifact, self.platform_tag)?;

let (wheel_path, tag) =
self.write_bin_wheel(&artifact, policy.platform_tag(), &external_libs)?;
Expand Down
8 changes: 1 addition & 7 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,6 @@ pub fn find_interpreter(
abi_tag,
calcsize_pointer: None,
},
target: target.clone(),
executable: PathBuf::new(),
platform: None,
runnable: false,
Expand Down Expand Up @@ -764,10 +763,7 @@ pub fn find_interpreter(
(ver_major, ver_minor),
)
.context("Failed to find a python interpreter")?;
interpreters.push(PythonInterpreter::from_config(
sysconfig.clone(),
target.clone(),
));
interpreters.push(PythonInterpreter::from_config(sysconfig.clone()));
}
}
} else {
Expand Down Expand Up @@ -818,7 +814,6 @@ pub fn find_interpreter(
abi_tag: None,
calcsize_pointer: None,
},
target: target.clone(),
executable: PathBuf::new(),
platform: None,
runnable: false,
Expand All @@ -839,7 +834,6 @@ pub fn find_interpreter(
abi_tag: None,
calcsize_pointer: None,
},
target: target.clone(),
executable: PathBuf::new(),
platform: None,
runnable: false,
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ fn pep517(subcommand: Pep517Command) -> Result<()> {
// Since afaik all other PEP 517 backends also return linux tagged wheels, we do so too
let tags = match context.bridge {
BridgeModel::Bindings(..) => {
vec![context.interpreter[0].get_tag(PlatformTag::Linux, context.universal2)?]
vec![context.interpreter[0].get_tag(
&context.target,
PlatformTag::Linux,
context.universal2,
)?]
}
BridgeModel::BindingsAbi3(major, minor) => {
let platform = context
Expand Down
26 changes: 13 additions & 13 deletions src/python_interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ pub struct PythonInterpreter {
/// Python's sysconfig
/// Python's major version
pub config: InterpreterConfig,
/// Currently just the value of [Target::os()], i.e. "windows", "linux",
/// "macos" or "freebsd"
pub target: Target,
/// Path to the python interpreter, e.g. /usr/bin/python3.6
///
/// Just the name of the binary in PATH does also work, e.g. `python3.5`
Expand Down Expand Up @@ -355,24 +352,29 @@ impl PythonInterpreter {
/// Don't ask me why or how, this is just what setuptools uses so I'm also going to use
///
/// If abi3 is true, cpython wheels use the generic abi3 with the given version as minimum
pub fn get_tag(&self, platform_tag: PlatformTag, universal2: bool) -> Result<String> {
pub fn get_tag(
&self,
target: &Target,
platform_tag: PlatformTag,
universal2: bool,
) -> Result<String> {
// Restrict `sysconfig.get_platform()` usage to Windows and non-portable Linux only for now
// so we don't need to deal with macOS deployment target
let use_sysconfig_platform = self.target.is_windows()
|| (self.target.is_linux() && !platform_tag.is_portable())
|| self.target.is_illumos();
let use_sysconfig_platform = target.is_windows()
|| (target.is_linux() && !platform_tag.is_portable())
|| target.is_illumos();
let platform = if use_sysconfig_platform {
if let Some(platform) = self.platform.clone() {
platform
} else {
self.target.get_platform_tag(platform_tag, universal2)?
target.get_platform_tag(platform_tag, universal2)?
}
} else {
self.target.get_platform_tag(platform_tag, universal2)?
target.get_platform_tag(platform_tag, universal2)?
};
let tag = match self.interpreter_kind {
InterpreterKind::CPython => {
if self.target.is_unix() {
if target.is_unix() {
format!(
"cp{major}{minor}-cp{major}{minor}{abiflags}-{platform}",
major = self.major,
Expand Down Expand Up @@ -524,18 +526,16 @@ impl PythonInterpreter {
abi_tag: message.abi_tag,
calcsize_pointer: None,
},
target: target.clone(),
executable: executable.as_ref().to_path_buf(),
platform,
runnable: true,
}))
}

/// Construct a `PythonInterpreter` from a sysconfig and target
pub fn from_config(config: InterpreterConfig, target: Target) -> Self {
pub fn from_config(config: InterpreterConfig) -> Self {
PythonInterpreter {
config,
target,
executable: PathBuf::new(),
platform: None,
runnable: false,
Expand Down

0 comments on commit 847fe57

Please sign in to comment.