pub struct PythonInterpreter {
    pub config: InterpreterConfig,
    pub executable: PathBuf,
    pub platform: Option<String>,
    pub runnable: bool,
    pub implementation_name: String,
    pub soabi: Option<String>,
}
Expand description

The location and version of an interpreter

Fields§

§config: InterpreterConfig

Python’s sysconfig Python’s major version

§executable: PathBuf

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

§platform: Option<String>

Comes from sysconfig.get_platform()

Note that this can be None when cross compiling

§runnable: bool

Is this interpreter runnable

When cross compile the target interpreter isn’t runnable, and it’s executable is empty

§implementation_name: String

Comes from sys.platform.name

§soabi: Option<String>

Comes from sysconfig var SOABI

Implementations§

source§

impl PythonInterpreter

source

pub fn has_stable_api(&self) -> bool

Does this interpreter have PEP 384 stable api aka. abi3 support?

source

pub fn get_tag( &self, context: &BuildContext, platform_tags: &[PlatformTag] ) -> Result<String>

Returns the supported python environment in the PEP 425 format used for the wheel filename: {python tag}-{abi tag}-{platform tag}

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

source

pub fn get_library_name(&self, base: &str) -> String

Adds the ext_suffix we read from python or know (.pyd/.abi3.so) and adds it to the base name

For CPython, generate extensions as follows:

For python 3, there is PEP 3149, but that is only valid for 3.2 - 3.4. Since only 3.6+ is supported, the templates are adapted from the (also incorrect) release notes of CPython 3.5: https://docs.python.org/3/whatsnew/3.5.html#build-and-c-api-changes

Examples for 64-bit on CPython 3.6m: Linux: foobar.cpython-36m-x86_64-linux-gnu.so Windows: foobar.cp36-win_amd64.pyd Mac: foobar.cpython-36m-darwin.so FreeBSD: foobar.cpython-36m.so

For pypy3, we read importlib.machinery.EXTENSION_SUFFIXES[0].

source

pub fn is_windows_debug(&self) -> bool

Is this a debug build of Python for Windows?

source

pub fn check_executable( executable: impl AsRef<Path>, target: &Target, bridge: &BridgeModel ) -> Result<Option<PythonInterpreter>>

Checks whether the given command is a python interpreter and returns a PythonInterpreter if that is the case

source

pub fn from_config(config: InterpreterConfig) -> Self

Construct a PythonInterpreter from a sysconfig and target

source

pub fn find_by_target( target: &Target, requires_python: Option<&VersionSpecifiers> ) -> Vec<PythonInterpreter>

Find all available python interpreters for a given target

source

pub fn find_all( target: &Target, bridge: &BridgeModel, requires_python: Option<&VersionSpecifiers> ) -> Result<Vec<PythonInterpreter>>

Tries to find all installed python versions using the heuristic for the given platform.

We have two filters: The optional requires-python from the pyproject.toml and minimum python minor either from the bindings (i.e. Cargo.toml abi3-py{major}{minor}) or the global default minimum minor version

source

pub fn check_executables( executables: &[PathBuf], target: &Target, bridge: &BridgeModel ) -> Result<Vec<PythonInterpreter>>

Checks that given list of executables are all valid python interpreters, determines the abiflags and versions of those interpreters and returns them as PythonInterpreter

source

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

Run a python script using this Python interpreter.

source

pub fn support_portable_wheels(&self) -> bool

Whether this Python interpreter support portable manylinux/musllinux wheels

Returns true if we can not decide

source

pub fn environment_signature(&self) -> String

An opaque string that uniquely identifies this Python interpreter. Used to trigger rebuilds for pyo3 when the Python interpreter changes.

source

pub fn get_venv_site_package( &self, venv_base: impl AsRef<Path>, target: &Target ) -> PathBuf

Returns the site-packages directory inside a venv e.g. {venv_base}/lib/python{x}.{y} on unix or {venv_base}/Lib on window

Trait Implementations§

source§

impl Clone for PythonInterpreter

source§

fn clone(&self) -> PythonInterpreter

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PythonInterpreter

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for PythonInterpreter

§

type Target = InterpreterConfig

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Display for PythonInterpreter

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for PythonInterpreter

source§

fn eq(&self, other: &PythonInterpreter) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for PythonInterpreter

source§

impl StructuralPartialEq for PythonInterpreter

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> Chain<T> for T

source§

fn len(&self) -> usize

The number of items that this chain link consists of.
source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
source§

impl<T> Container<T> for T
where T: Clone,

§

type Iter = Once<T>

An iterator over the items within this container, by value.
source§

fn get_iter(&self) -> <T as Container<T>>::Iter

Iterate over the elements of the container (using internal iteration because GATs are unstable).
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> OrderedContainer<T> for T
where T: Clone,