Struct PythonResourcesState

Source
pub struct PythonResourcesState<'a, X>
where [X]: ToOwned<Owned = Vec<X>>,
{ /* private fields */ }
Expand description

Defines Python resources available for import.

Implementations§

Source§

impl<'a> PythonResourcesState<'a, u8>

Source

pub fn new_from_env() -> Result<PythonResourcesState<'a, u8>, &'static str>

Construct an instance from environment state.

Source

pub fn current_exe(&self) -> &Path

Obtain the path of the current executable.

Source

pub fn set_current_exe(&mut self, path: PathBuf)

Set the path of the current executable.

Source

pub fn origin(&self) -> &Path

Obtain the source path that relative paths are relative to.

Source

pub fn set_origin(&mut self, path: PathBuf)

Set the source path that relative paths are relative to.

Source

pub fn index_data(&mut self, data: &'a [u8]) -> Result<(), &'static str>

Load resources by parsing a blob.

If an existing entry exists, the new entry will be merged into it. Set fields on the incoming entry will overwrite fields on the existing entry.

If an entry doesn’t exist, the resource will be inserted as-is.

Source

pub fn index_path_memory_mapped( &mut self, path: impl AsRef<Path>, ) -> Result<(), String>

Load resources data from a filesystem path using memory mapped I/O.

Source

pub fn index_pyobject( &mut self, py: Python<'_>, obj: &PyAny, ) -> Result<(), PyErr>

Load resources from packed data stored in a PyObject.

The PyObject must conform to the buffer protocol.

Source

pub fn index_interpreter_builtin_extension_modules( &mut self, ) -> Result<(), &'static str>

Load builtin modules from the Python interpreter.

Source

pub fn index_interpreter_frozen_modules(&mut self) -> Result<(), &'static str>

Load frozen modules from the Python interpreter.

Source

pub fn index_interpreter_builtins(&mut self) -> Result<(), &'static str>

Load resources that are built-in to the Python interpreter.

If this instance’s resources are being used by the sole Python importer, this needs to be called to ensure modules required during interpreter initialization are indexed and loadable by our importer.

Source

pub fn has_resource(&self, name: &str) -> bool

Says whether a named resource exists.

Source

pub fn add_resource<'resource>( &mut self, resource: Resource<'resource, u8>, ) -> Result<(), &'static str>
where 'resource: 'a,

Add a resource to the instance.

Memory in the resource must live for at least as long as the lifetime of the resources this instance was created with.

Source

pub fn resolve_importable_module( &self, name: &str, optimize_level: BytecodeOptimizationLevel, ) -> Option<ImportablePythonModule<'_, u8>>

Attempt to resolve an importable Python module.

Source

pub fn get_package_resource_file<'p>( &self, py: Python<'p>, package: &str, resource_name: &str, ) -> Result<Option<&'p PyAny>, PyErr>

Obtain a single named resource in a package.

Err occurs if loading the resource data fails. Ok(None) is returned if the resource does not exist. Otherwise the returned PyObject is a file-like object to read the resource data.

Source

pub fn is_package_resource(&self, package: &str, resource_name: &str) -> bool

Determines whether a specific package + name pair is a known Python package resource.

Source

pub fn package_resource_names<'p>( &self, py: Python<'p>, package: &str, ) -> Result<&'p PyAny, PyErr>

Obtain the resources available in a Python package, as a Python list.

The names are returned in sorted order.

Source

pub fn is_package_resource_directory(&self, package: &str, name: &str) -> bool

Whether the given resource name is a directory with resources.

Source

pub fn package_resources_list_directory( &self, package: &str, name: &str, ) -> Vec<String>

Resolve package resources in a directory.

Source

pub fn resolve_resource_data_from_path<'p>( &self, py: Python<'p>, path: &str, ) -> Result<&'p PyAny, PyErr>

Attempt to resolve a PyBytes for resource data given a relative path.

Raises OSerror on failure.

This method is meant to be an implementation of ResourceLoader.get_data() and should only be used for that purpose.

Source

pub fn pkgutil_modules_infos<'p>( &self, py: Python<'p>, package_filter: Option<&str>, prefix: Option<String>, optimize_level: BytecodeOptimizationLevel, ) -> Result<&'p PyList, PyErr>

Obtain a PyList of pkgutil.ModuleInfo for known resources.

This is intended to be used as the implementation for Finder.iter_modules().

package_filter defines the target package to return results for. The empty string denotes top-level packages only.

Source

pub fn package_distribution_names( &self, filter: impl Fn(&str) -> bool, ) -> Vec<&str>

Resolve the names of package distributions matching a name filter.

Source

pub fn resolve_package_distribution_resource( &self, package: &str, name: &str, ) -> Result<Option<Cow<'_, [u8]>>, Error>

Resolve data belonging to a package distribution resource.

Source

pub fn package_distribution_resource_name_is_directory( &self, package: &str, name: &str, ) -> bool

Whether a package distribution resource name is a directory.

Source

pub fn package_distribution_resources_list_directory<'slf>( &'slf self, package: &str, name: &str, ) -> Vec<&'slf str>

Obtain contents in a package distribution resources “directory.”

Source

pub fn resolve_in_memory_shared_library_data(&self, name: &str) -> Option<&[u8]>

Resolve content of a shared library to load from memory.

Source

pub fn resources_as_py_list<'p>( &self, py: Python<'p>, ) -> Result<&'p PyList, PyErr>

Convert indexed resources to a PyList.

Source

pub fn serialize_resources( &self, ignore_builtin: bool, ignore_frozen: bool, ) -> Result<Vec<u8>, Error>

Serialize resources contained in this data structure.

ignore_built and ignore_frozen specify whether to ignore built-in extension modules and frozen modules, respectively.

Trait Implementations§

Source§

impl<'a, X> Debug for PythonResourcesState<'a, X>
where X: Debug, [X]: ToOwned<Owned = Vec<X>>,

Source§

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

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

impl<'a> Default for PythonResourcesState<'a, u8>

Source§

fn default() -> PythonResourcesState<'a, u8>

Returns the “default value” for a type. Read more
Source§

impl<'a, 'config: 'a> TryFrom<&ResolvedOxidizedPythonInterpreterConfig<'config>> for PythonResourcesState<'a, u8>

Source§

type Error = NewInterpreterError

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

fn try_from( config: &ResolvedOxidizedPythonInterpreterConfig<'config>, ) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a, X> Freeze for PythonResourcesState<'a, X>

§

impl<'a, X> !RefUnwindSafe for PythonResourcesState<'a, X>

§

impl<'a, X> Send for PythonResourcesState<'a, X>
where X: Sync + Send,

§

impl<'a, X> Sync for PythonResourcesState<'a, X>
where X: Sync,

§

impl<'a, X> Unpin for PythonResourcesState<'a, X>
where X: Unpin,

§

impl<'a, X> UnwindSafe for PythonResourcesState<'a, X>

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> 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, 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<T> Ungil for T
where T: Send,