Interpreter

Struct Interpreter 

Source
pub struct Interpreter { /* private fields */ }
Expand description

A Python executable and its associated platform markers.

Implementations§

Source§

impl Interpreter

Source

pub fn query(executable: impl AsRef<Path>, cache: &Cache) -> Result<Self, Error>

Detect the interpreter info for the given Python executable.

Source

pub fn with_virtualenv(self, virtualenv: VirtualEnvironment) -> Self

Return a new Interpreter with the given virtual environment root.

Source

pub fn with_target(self, target: Target) -> Result<Self>

Return a new Interpreter to install into the given --target directory.

Source

pub fn with_prefix(self, prefix: Prefix) -> Result<Self>

Return a new Interpreter to install into the given --prefix directory.

Source

pub fn to_base_python(&self) -> Result<PathBuf, Error>

Return the base Python executable; that is, the Python executable that should be considered the “base” for the virtual environment. This is typically the Python executable from the Interpreter; however, if the interpreter is a virtual environment itself, then the base Python executable is the Python executable of the interpreter’s base interpreter.

This routine relies on sys._base_executable, falling back to sys.executable if unset. Broadly, this routine should be used when attempting to determine the “base Python executable” in a way that is consistent with the CPython standard library, such as when determining the home key for a virtual environment.

Source

pub fn find_base_python(&self) -> Result<PathBuf, Error>

Determine the base Python executable; that is, the Python executable that should be considered the “base” for the virtual environment. This is typically the Python executable from the Interpreter; however, if the interpreter is a virtual environment itself, then the base Python executable is the Python executable of the interpreter’s base interpreter.

This routine mimics the CPython getpath.py logic in order to make a more robust assessment of the appropriate base Python executable. Broadly, this routine should be used when attempting to determine the “true” base executable for a Python interpreter by resolving symlinks until a valid Python installation is found. In particular, we tend to use this routine for our own managed (or standalone) Python installations.

Source

pub fn platform(&self) -> &Platform

Returns the path to the Python virtual environment.

Source

pub const fn markers(&self) -> &MarkerEnvironment

Returns the MarkerEnvironment for this Python executable.

Source

pub fn resolver_marker_environment(&self) -> ResolverMarkerEnvironment

Return the ResolverMarkerEnvironment for this Python executable.

Source

pub fn key(&self) -> PythonInstallationKey

Returns the PythonInstallationKey for this interpreter.

Source

pub fn variant(&self) -> PythonVariant

Source

pub fn arch(&self) -> Arch

Return the Arch reported by the interpreter platform tags.

Source

pub fn libc(&self) -> Libc

Return the Libc reported by the interpreter platform tags.

Source

pub fn os(&self) -> Os

Return the Os reported by the interpreter platform tags.

Source

pub fn tags(&self) -> Result<&Tags, TagsError>

Returns the Tags for this Python executable.

Source

pub fn is_virtualenv(&self) -> bool

Returns true if the environment is a PEP 405-compliant virtual environment.

See: https://github.com/pypa/pip/blob/0ad4c94be74cc24874c6feb5bb3c2152c398a18e/src/pip/_internal/utils/virtualenv.py#L14

Source

pub fn is_target(&self) -> bool

Returns true if the environment is a --target environment.

Source

pub fn is_prefix(&self) -> bool

Returns true if the environment is a --prefix environment.

Source

pub fn is_managed(&self) -> bool

Returns true if this interpreter is managed by uv.

Returns false if we cannot determine the path of the uv managed Python interpreters.

Source

pub fn is_externally_managed(&self) -> Option<ExternallyManaged>

Returns Some if the environment is externally managed, optionally including an error message from the EXTERNALLY-MANAGED file.

See: https://packaging.python.org/en/latest/specifications/externally-managed-environments/

Source

pub fn python_full_version(&self) -> &StringVersion

Returns the python_full_version marker corresponding to this Python version.

Source

pub fn python_version(&self) -> &Version

Returns the full Python version.

Source

pub fn python_minor_version(&self) -> Version

Returns the Python version up to the minor component.

Source

pub fn python_patch_version(&self) -> Version

Returns the Python version up to the patch component.

Source

pub fn python_major(&self) -> u8

Return the major version component of this Python version.

Source

pub fn python_minor(&self) -> u8

Return the minor version component of this Python version.

Source

pub fn python_patch(&self) -> u8

Return the patch version component of this Python version.

Source

pub fn python_tuple(&self) -> (u8, u8)

Returns the Python version as a simple tuple, e.g., (3, 12).

Source

pub fn implementation_major(&self) -> u8

Return the major version of the implementation (e.g., CPython or PyPy).

Source

pub fn implementation_minor(&self) -> u8

Return the minor version of the implementation (e.g., CPython or PyPy).

Source

pub fn implementation_tuple(&self) -> (u8, u8)

Returns the implementation version as a simple tuple.

Source

pub fn implementation_name(&self) -> &str

Returns the implementation name (e.g., CPython or PyPy).

Source

pub fn sys_base_exec_prefix(&self) -> &Path

Return the sys.base_exec_prefix path for this Python interpreter.

Source

pub fn sys_base_prefix(&self) -> &Path

Return the sys.base_prefix path for this Python interpreter.

Source

pub fn sys_prefix(&self) -> &Path

Return the sys.prefix path for this Python interpreter.

Source

pub fn sys_base_executable(&self) -> Option<&Path>

Return the sys._base_executable path for this Python interpreter. Some platforms do not have this attribute, so it may be None.

Source

pub fn sys_executable(&self) -> &Path

Return the sys.executable path for this Python interpreter.

Source

pub fn real_executable(&self) -> &Path

Return the “real” queried executable path for this Python interpreter.

Source

pub fn sys_path(&self) -> &[PathBuf]

Return the sys.path for this Python interpreter.

Source

pub fn runtime_site_packages(&self) -> &[PathBuf]

Return the site.getsitepackages for this Python interpreter.

These are the paths Python will search for packages in at runtime. We use this for environment layering, but not for checking for installed packages. We could use these paths to check for installed packages, but it introduces a lot of complexity, so instead we use a simplified version that does not respect customized site-packages. See Interpreter::site_packages.

Source

pub fn stdlib(&self) -> &Path

Return the stdlib path for this Python interpreter, as returned by sysconfig.get_paths().

Source

pub fn purelib(&self) -> &Path

Return the purelib path for this Python interpreter, as returned by sysconfig.get_paths().

Source

pub fn platlib(&self) -> &Path

Return the platlib path for this Python interpreter, as returned by sysconfig.get_paths().

Source

pub fn scripts(&self) -> &Path

Return the scripts path for this Python interpreter, as returned by sysconfig.get_paths().

Source

pub fn data(&self) -> &Path

Return the data path for this Python interpreter, as returned by sysconfig.get_paths().

Source

pub fn include(&self) -> &Path

Return the include path for this Python interpreter, as returned by sysconfig.get_paths().

Source

pub fn virtualenv(&self) -> &Scheme

Return the Scheme for a virtual environment created by this Interpreter.

Source

pub fn manylinux_compatible(&self) -> bool

Return whether this interpreter is manylinux compatible.

Source

pub fn pointer_size(&self) -> PointerSize

Return the PointerSize of the Python interpreter (i.e., 32- vs. 64-bit).

Source

pub fn gil_disabled(&self) -> bool

Return whether this is a Python 3.13+ freethreading Python, as specified by the sysconfig var Py_GIL_DISABLED.

freethreading Python is incompatible with earlier native modules, re-introducing abiflags with a t flag. https://peps.python.org/pep-0703/#build-configuration-changes

Source

pub fn debug_enabled(&self) -> bool

Return whether this is a debug build of Python, as specified by the sysconfig var Py_DEBUG.

Source

pub fn target(&self) -> Option<&Target>

Return the --target directory for this interpreter, if any.

Source

pub fn prefix(&self) -> Option<&Prefix>

Return the --prefix directory for this interpreter, if any.

Source

pub fn is_standalone(&self) -> bool

Returns true if an Interpreter may be a python-build-standalone interpreter.

This method may return false positives, but it should not return false negatives. In other words, if this method returns true, the interpreter may be from python-build-standalone; if it returns false, the interpreter is definitely not from python-build-standalone.

See: https://github.com/astral-sh/python-build-standalone/issues/382

Source

pub fn layout(&self) -> Layout

Return the Layout environment used to install wheels into this interpreter.

Source

pub fn site_packages(&self) -> impl Iterator<Item = Cow<'_, Path>>

Returns an iterator over the site-packages directories inside the environment.

In most cases, purelib and platlib will be the same, and so the iterator will contain a single element; however, in some distributions, they may be different.

Some distributions also create symbolic links from purelib to platlib; in such cases, we still deduplicate the entries, returning a single path.

Note this does not include all runtime site-packages directories if the interpreter has been customized. See Interpreter::runtime_site_packages.

Source

pub fn satisfies(&self, version: &PythonVersion) -> bool

Check if the interpreter matches the given Python version.

If a patch version is present, we will require an exact match. Otherwise, just the major and minor version numbers need to match.

Source

pub async fn lock(&self) -> Result<LockedFile, Error>

Grab a file lock for the environment to prevent concurrent writes across processes.

Trait Implementations§

Source§

impl Clone for Interpreter

Source§

fn clone(&self) -> Interpreter

Returns a duplicate 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 Interpreter

Source§

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

Formats the value using the given formatter. Read more

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

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

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

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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, 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.
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> ErasedDestructor for T
where T: 'static,