pub struct PythonInterpreter {
    pub major: usize,
    pub minor: usize,
    pub abiflags: String,
    pub target: Target,
    pub executable: PathBuf,
    pub ext_suffix: String,
    pub interpreter_kind: InterpreterKind,
    pub abi_tag: Option<String>,
    pub libs_dir: PathBuf,
    pub platform: Option<String>,
    pub runnable: bool,
}
Expand description

The location and version of an interpreter

Fields

major: usize

Python’s major version

minor: usize

Python’s minor version

abiflags: String

For linux and mac, this contains the value of the abiflags, e.g. “m” for python3.7m or “dm” for python3.6dm. Since python3.8, the value is empty. On windows, the value was always “”.

See PEP 261 and PEP 393 for details

target: Target

Currently just the value of [Target::os()], i.e. “windows”, “linux”, “macos” or “freebsd”

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

ext_suffix: String

Suffix to use for extension modules as given by sysconfig.

interpreter_kind: InterpreterKind

cpython or pypy

abi_tag: Option<String>

Part of sysconfig’s SOABI specifying {major}{minor}{abiflags}

Note that this always None on windows

libs_dir: PathBuf

We need this value for windows abi3 linking

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

Implementations

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

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].

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

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

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

Run a python script using this Python interpreter.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.