pub struct PythonResourceCollector { /* private fields */ }
Expand description

Type used to collect Python resources so they can be serialized.

We often want to turn Python resource primitives (module source, bytecode, etc) into a collection of Resource so they can be serialized to the Python packed resources format. This type exists to facilitate doing this.

This type is not only responsible for tracking resources but also for enforcing policies on where those resources can be loaded from and what types of resources are allowed. This includes tracking the licensing metadata for indexed resources.

Implementations

Construct a new instance of the collector.

The instance is associated with a resources policy to validate that added resources conform with rules.

We also pass a Python bytecode cache tag, which is used to derive filenames.

Obtain locations that resources can be loaded from.

Obtain a set of all top-level Python module names registered with the collector.

The returned values correspond to packages or single file modules without children modules.

Validate that a resource add in the specified location is allowed.

Apply a filter function on resources in this collection and mutate in place.

If the filter function returns true, the item will be preserved.

Obtain an iterator over the resources in this collector.

Generate a summary of licensing information for resources in the collection.

Register a licensed software component to this collection.

Add Python module source with a specific location.

Add Python module source using an add context to influence operation.

All of the context’s properties are respected. This includes doing nothing if include is false, not adding source if store_source is false, and automatically deriving a bytecode request if the optimize_level_* fields are set.

This method is a glorified proxy to other add_* methods: it simply contains the logic for expanding the context’s wishes into function calls.

Add Python module bytecode to the specified location.

Add Python module bytecode using an add context.

This takes the context’s fields into consideration when adding the resource. If include is false, this is a no-op. The context must also have an optimize_level_* field set corresponding with the optimization level of the passed bytecode, or this is a no-op.

Add Python module bytecode derived from source code to the collection.

Add Python module bytecode from source using an add context to influence operations.

This method respects the settings of the context, including include and the optimize_level_* fields.

PythonModuleBytecodeFromSource defines an explicit bytecode optimization level, so this method can result in at most 1 bytecode request being added to the collection.

Add resource data to a given location.

Resource data belongs to a Python package and has a name and bytes data.

Add a Python package resource using an add context.

The fields from the context will be respected. This includes not doing anything if include is false.

Add a Python package distribution resource to a given location.

Add a Python package distribution resource using an add context.

The fields from the context will be respected. This includes not doing anything if include is false.

Add a Python extension module using an add context.

Add a built-in extension module.

Built-in extension modules are statically linked into the binary and cannot have their location defined.

Add a Python extension module shared library that should be imported from memory.

Add a shared library to be loaded from a location.

Searches for Python sources for references to file.

file usage can be problematic for in-memory modules. This method searches for its occurrences and returns module names having it present.

Compiles resources into a finalized collection.

This will take all resources collected so far and convert them into a collection of Resource plus extra file install rules.

Missing parent packages will be added automatically.

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

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

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

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.