Struct pyembed::PythonResourcesState
source · pub struct PythonResourcesState<'a, X>where
[X]: ToOwned<Owned = Vec<X, Global>>,{ /* private fields */ }
Expand description
Defines Python resources available for import.
Implementations§
source§impl<'a> PythonResourcesState<'a, u8>
impl<'a> PythonResourcesState<'a, u8>
sourcepub fn new_from_env() -> Result<PythonResourcesState<'a, u8>, &'static str>
pub fn new_from_env() -> Result<PythonResourcesState<'a, u8>, &'static str>
Construct an instance from environment state.
sourcepub fn current_exe(&self) -> &Path
pub fn current_exe(&self) -> &Path
Obtain the path of the current executable.
sourcepub fn set_current_exe(&mut self, path: PathBuf)
pub fn set_current_exe(&mut self, path: PathBuf)
Set the path of the current executable.
sourcepub fn set_origin(&mut self, path: PathBuf)
pub fn set_origin(&mut self, path: PathBuf)
Set the source path that relative paths are relative to.
sourcepub fn index_data(&mut self, data: &'a [u8]) -> Result<(), &'static str>
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.
sourcepub fn index_path_memory_mapped(
&mut self,
path: impl AsRef<Path>
) -> Result<(), String>
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.
sourcepub fn index_pyobject(&mut self, py: Python<'_>, obj: &PyAny) -> Result<(), PyErr>
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.
sourcepub fn index_interpreter_builtin_extension_modules(
&mut self
) -> Result<(), &'static str>
pub fn index_interpreter_builtin_extension_modules(
&mut self
) -> Result<(), &'static str>
Load builtin
modules from the Python interpreter.
sourcepub fn index_interpreter_frozen_modules(&mut self) -> Result<(), &'static str>
pub fn index_interpreter_frozen_modules(&mut self) -> Result<(), &'static str>
Load frozen
modules from the Python interpreter.
sourcepub fn index_interpreter_builtins(&mut self) -> Result<(), &'static str>
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.
sourcepub fn has_resource(&self, name: &str) -> bool
pub fn has_resource(&self, name: &str) -> bool
Says whether a named resource exists.
sourcepub fn add_resource<'resource>(
&mut self,
resource: Resource<'resource, u8>
) -> Result<(), &'static str>where
'resource: 'a,
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.
sourcepub fn resolve_importable_module(
&self,
name: &str,
optimize_level: BytecodeOptimizationLevel
) -> Option<ImportablePythonModule<'_, u8>>
pub fn resolve_importable_module(
&self,
name: &str,
optimize_level: BytecodeOptimizationLevel
) -> Option<ImportablePythonModule<'_, u8>>
Attempt to resolve an importable Python module.
sourcepub fn get_package_resource_file<'p>(
&self,
py: Python<'p>,
package: &str,
resource_name: &str
) -> Result<Option<&'p PyAny>, PyErr>
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.
sourcepub fn is_package_resource(&self, package: &str, resource_name: &str) -> bool
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.
sourcepub fn package_resource_names<'p>(
&self,
py: Python<'p>,
package: &str
) -> Result<&'p PyAny, PyErr>
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.
sourcepub fn is_package_resource_directory(&self, package: &str, name: &str) -> bool
pub fn is_package_resource_directory(&self, package: &str, name: &str) -> bool
Whether the given resource name is a directory with resources.
sourcepub fn package_resources_list_directory(
&self,
package: &str,
name: &str
) -> Vec<String, Global> ⓘ
pub fn package_resources_list_directory(
&self,
package: &str,
name: &str
) -> Vec<String, Global> ⓘ
Resolve package resources in a directory.
sourcepub fn resolve_resource_data_from_path<'p>(
&self,
py: Python<'p>,
path: &str
) -> Result<&'p PyAny, PyErr>
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.
sourcepub fn pkgutil_modules_infos<'p>(
&self,
py: Python<'p>,
package_filter: Option<&str>,
prefix: Option<String>,
optimize_level: BytecodeOptimizationLevel
) -> Result<&'p PyList, PyErr>
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.
sourcepub fn package_distribution_names(
&self,
filter: impl Fn(&str) -> bool
) -> Vec<&str, Global> ⓘ
pub fn package_distribution_names(
&self,
filter: impl Fn(&str) -> bool
) -> Vec<&str, Global> ⓘ
Resolve the names of package distributions matching a name filter.
sourcepub fn resolve_package_distribution_resource(
&self,
package: &str,
name: &str
) -> Result<Option<Cow<'_, [u8]>>, Error>
pub fn resolve_package_distribution_resource(
&self,
package: &str,
name: &str
) -> Result<Option<Cow<'_, [u8]>>, Error>
Resolve data belonging to a package distribution resource.
sourcepub fn package_distribution_resource_name_is_directory(
&self,
package: &str,
name: &str
) -> bool
pub fn package_distribution_resource_name_is_directory(
&self,
package: &str,
name: &str
) -> bool
Whether a package distribution resource name is a directory.
sourcepub fn package_distribution_resources_list_directory<'slf>(
&'slf self,
package: &str,
name: &str
) -> Vec<&'slf str, Global> ⓘ
pub fn package_distribution_resources_list_directory<'slf>(
&'slf self,
package: &str,
name: &str
) -> Vec<&'slf str, Global> ⓘ
Obtain contents in a package distribution resources “directory.”
Resolve content of a shared library to load from memory.