Skip to main content

InterpreterConfig

Struct InterpreterConfig 

Source
pub struct InterpreterConfig {
Show 13 fields pub implementation: PythonImplementation, pub version: PythonVersion, pub shared: bool, target_abi: PythonAbi, pub abi3: bool, pub lib_name: Option<String>, pub lib_dir: Option<String>, pub executable: Option<String>, pub pointer_width: Option<u32>, pub build_flags: BuildFlags, pub suppress_build_script_link_lines: bool, pub extra_build_script_lines: Vec<String>, pub python_framework_prefix: Option<String>,
}
Expand description

Configuration needed by PyO3 to build for the correct Python implementation.

The version and implementation fields correspond to the interpreter used to host a build. These need not be the same as the implementation and version fields set for the build target in the target_abi field.

Usually this is queried directly from the Python interpreter, or overridden using the PYO3_CONFIG_FILE environment variable.

When the PYO3_NO_PYTHON variable is set, or during cross compile situations, then alternative strategies are used to populate this type.

Fields§

§implementation: PythonImplementation
👎Deprecated since 0.29.0:

please use .implementation() getter or InterpreterConfigBuilder instead

The host Python implementation flavor.

Serialized to implementation.

§version: PythonVersion
👎Deprecated since 0.29.0:

please use .version() getter or InterpreterConfigBuilder instead

The host Python X.Y version. e.g. 3.9.

Serialized to version.

§shared: bool
👎Deprecated since 0.29.0:

please use .shared() getter or InterpreterConfigBuilder instead

Whether link library is shared.

Serialized to shared.

§target_abi: PythonAbi§abi3: bool
👎Deprecated since 0.29.0:

please match against target_abi instead

Serialized to abi3.

§lib_name: Option<String>
👎Deprecated since 0.29.0:

please use .lib_name() getter or InterpreterConfigBuilder instead

The name of the link library defining Python.

This effectively controls the cargo:rustc-link-lib=<name> value to control how libpython is linked. Values should not contain the lib prefix.

Serialized to lib_name.

§lib_dir: Option<String>
👎Deprecated since 0.29.0:

please use .lib_dir() getter or InterpreterConfigBuilder instead

The directory containing the Python library to link against.

The effectively controls the cargo:rustc-link-search=native=<path> value to add an additional library search path for the linker.

Serialized to lib_dir.

§executable: Option<String>
👎Deprecated since 0.29.0:

please use .executable() getter or InterpreterConfigBuilder instead

Path of host python executable.

This is a valid executable capable of running on the host/building machine. For configurations derived by invoking a Python interpreter, it was the executable invoked.

Serialized to executable.

§pointer_width: Option<u32>
👎Deprecated since 0.29.0:

please use .pointer_width() getter or InterpreterConfigBuilder instead

Width in bits of pointers on the target machine.

Serialized to pointer_width.

§build_flags: BuildFlags
👎Deprecated since 0.29.0:

please use .build_flags() getter or InterpreterConfigBuilder instead

Additional relevant Python build flags / configuration settings.

Serialized to build_flags.

§suppress_build_script_link_lines: bool
👎Deprecated since 0.29.0:

please use .suppress_build_script_link_lines() getter or InterpreterConfigBuilder instead

Whether to suppress emitting of cargo:rustc-link-* lines from the build script.

Typically, pyo3’s build script will emit cargo:rustc-link-lib= and cargo:rustc-link-search= lines derived from other fields in this struct. In advanced building configurations, the default logic to derive these lines may not be sufficient. This field can be set to Some(true) to suppress the emission of these lines.

If suppression is enabled, extra_build_script_lines should contain equivalent functionality or else a build failure is likely.

§extra_build_script_lines: Vec<String>
👎Deprecated since 0.29.0:

please use .extra_build_script_lines() getter or InterpreterConfigBuilder instead

Additional lines to println!() from Cargo build scripts.

This field can be populated to enable the pyo3 crate to emit additional lines from its its Cargo build script.

This crate doesn’t populate this field itself. Rather, it is intended to be used with externally provided config files to give them significant control over how the crate is build/configured.

Serialized to multiple extra_build_script_line values.

§python_framework_prefix: Option<String>
👎Deprecated since 0.29.0:

please use .python_framework_prefix() getter or InterpreterConfigBuilder instead

macOS Python3.framework requires special rpath handling

Implementations§

Source§

impl InterpreterConfig

Source

pub(crate) const PYO3_FFI_CONFIG_ENV_VAR: &str = "DEP_PYTHON_PYO3_CONFIG"

Environment variable populated via pyo3-ffi’s build script

Source

pub(crate) const PYO3_CONFIG_ENV_VAR: &str = "DEP_PYO3_PYTHON_PYO3_CONFIG"

Environment variable populated via pyo3’s build script by forwarding the value from pyo3-ffi

Source

pub fn implementation(&self) -> PythonImplementation

The Python implementation flavor.

Serialized to implementation.

Source

pub fn version(&self) -> PythonVersion

Python X.Y version. e.g. 3.9.

Serialized to version.

Source

pub fn shared(&self) -> bool

Whether link library is shared.

Serialized to shared.

Source

pub fn target_abi(&self) -> PythonAbi

The ABI to use for the compilation target. See the documentation for the PythonAbi enum for more details.

Serialized to target_abi.

Source

pub fn abi3(&self) -> bool

👎Deprecated since 0.29.0:

please use target_abi() instead

Whether linking against the stable/limited Python 3 API.

Source

pub fn lib_name(&self) -> Option<&str>

The name of the link library defining Python.

This effectively controls the cargo:rustc-link-lib=<name> value to control how libpython is linked. Values should not contain the lib prefix.

Serialized to lib_name.

Source

pub fn lib_dir(&self) -> Option<&str>

The directory containing the Python library to link against.

The effectively controls the cargo:rustc-link-search=native=<path> value to add an additional library search path for the linker.

Serialized to lib_dir.

Source

pub fn executable(&self) -> Option<&str>

Path of host python executable.

This is a valid executable capable of running on the host/building machine. For configurations derived by invoking a Python interpreter, it was the executable invoked.

Serialized to executable.

Source

pub fn pointer_width(&self) -> Option<u32>

Width in bits of pointers on the target machine.

Serialized to pointer_width.

Source

pub fn build_flags(&self) -> &BuildFlags

Additional relevant Python build flags / configuration settings.

Serialized to build_flags.

Whether to suppress emitting of cargo:rustc-link-* lines from the build script.

Source

pub fn extra_build_script_lines(&self) -> &[String]

Additional lines to println!() from Cargo build scripts.

Serialized to multiple extra_build_script_line values.

Source

pub fn python_framework_prefix(&self) -> Option<&str>

macOS Python3.framework prefix used for special rpath handling.

Source

#[doc(hidden)]
pub fn build_script_outputs(&self) -> Vec<String>

Source

fn from_interpreter( interpreter: impl AsRef<Path>, abi3_version: Option<PythonVersion>, abi3t_version: Option<PythonVersion>, ) -> Result<Self>

Source

pub fn from_sysconfigdata(sysconfigdata: &Sysconfigdata) -> Result<Self>

Generate from parsed sysconfigdata file

Use parse_sysconfigdata to generate a hash map of configuration values which may be used to build an InterpreterConfig.

Source

pub(crate) fn from_pyo3_config_file_env(target: &Triple) -> Option<Result<Self>>

Import an externally-provided config file.

The abi3 features, if set, may apply an abi3 constraint to the Python version.

Source

fn from_path(path: impl AsRef<Path>) -> Result<Self>

Source

pub(crate) fn from_cargo_dep_env() -> Option<Result<Self>>

Source

fn from_reader(reader: impl Read) -> Result<Self>

Source

#[doc(hidden)]
pub fn to_cargo_dep_env(&self) -> Result<()>

Serialize the InterpreterConfig and print it to the environment for Cargo to pass along to dependent packages during build time.

NB: writing to the cargo environment requires the links manifest key to be set. In this case that means this is called by the pyo3-ffi crate and available for dependent package build scripts in DEP_PYTHON_PYO3_CONFIG. See documentation for the DEP_<name>_<key> environment variable.

Source

#[doc(hidden)]
pub fn to_writer(&self, writer: impl Write) -> Result<()>

Source

pub fn run_python_script(&self, script: &str) -> Result<String>

Run a python script using the InterpreterConfig::executable.

§Panics

This function will panic if the executable is None.

Source

pub fn run_python_script_with_envs<I, K, V>( &self, script: &str, envs: I, ) -> Result<String>
where I: IntoIterator<Item = (K, V)>, K: AsRef<OsStr>, V: AsRef<OsStr>,

Run a python script using the InterpreterConfig::executable with additional environment variables (e.g. PYTHONPATH) set.

§Panics

This function will panic if the executable is None.

Source

pub fn is_free_threaded(&self) -> bool

Source

fn apply_build_env(self) -> Result<InterpreterConfig>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here