- class starlark_pyoxidizer.PythonPackagingPolicy¶
When building a Python binary, there are various settings that control which Python resources are added, where they are imported from, and other various settings. This collection of settings is referred to as a Python Packaging Policy. These settings are represented by the
Whether to allow the collection of generic file resources.
If false, all collected/packaged resources must be instances of concrete resource types (
Fileinstances can be added to resource collectors.
Whether to allow loading of Python extension modules and shared libraries from memory at run-time.
Some platforms (notably Windows) allow opening shared libraries from a memory address. This mode of opening shared libraries allows libraries to be embedded in binaries without having to statically link them. However, not every library works correctly when loaded this way.
This flag defines whether to enable this feature where supported. Its true value can be ignored if the target platform doesn’t support loading shared library from memory.
Whether to add Python bytecode at optimization level 0 (the default optimization level the Python interpreter compiles bytecode for).
Whether to add Python bytecode at optimization level 1.
Whether to add Python bytecode at optimization level 2.
The filter to apply to determine which extension modules to add. The following values are recognized:
Every named extension module will be included.
Return only extension modules that are required to initialize a Python interpreter. This is a very small set and various functionality from the Python standard library will not work with this value.
Return only extension modules that don’t require any additional libraries.
Most common Python extension modules are included. Extension modules like
_ssl(links against OpenSSL) and
zlibare not included.
Return only extension modules that do not link against copyleft licensed libraries.
Not all Python distributions may annotate license info for all extensions or the libraries they link against. If license info is missing, the extension is not included because it could be copyleft licensed. Similarly, the mechanism for determining whether a license is copyleft is based on the SPDX license annotations, which could be wrong or out of date.
Whether file scanning should attempt to classify files and emit typed resources corresponding to the detected file type.
False, the file scanner does not attempt to classify the type of a file and this rich resource types are not emitted.
Whether file scanning should emit file resources for each seen file.
Fileinstances will not be emitted.
Can be used in conjunction with
Whether strongly typed, classified non-
Fileresources have their
add_includeattribute set to
Whether to add source code for Python modules in the Python distribution.
Whether to add Python package resources for Python packages in the Python distribution.
Fileresources have their
add_includeattribute set to
Whether to add source code for Python modules not in the Python distribution.
Whether to add Python resources related to tests.
Not all files associated with tests may be properly flagged as such. This is a best effort setting.
The location that resources should be added to by default.
The fallback location that resources should be added to if
dict<string, string>) (readonly)
Mapping of extension module name to variant name.
This mapping defines which preferred named variant of an extension module to use. Some Python distributions offer multiple variants of the same extension module. This mapping allows defining which variant of which extension to use when choosing among them.
Keys set on this dict are not reflected in the underlying policy. To set a key, call the
- register_resource_callback(f: Callable)¶
This method registers a Starlark function to be called when resource objects are created. The passed function receives 2 arguments: this
PythonPackagingPolicyinstance and the resource (e.g.
PythonModuleSource) that was created.
The purpose of the callback is to enable Starlark configuration files to mutate resources upon creation so they can globally influence how those resources are packaged.
- set_preferred_extension_module_variant(extension: str, variant: str)¶
This method will set a preferred Python extension module variant to use. See the documentation for
preferred_extension_module_variantsabove for more.
It accepts 2
stringarguments defining the extension module name and its preferred variant.
- set_resource_handling_mode(mode: str)¶
This method takes a string argument denoting the resource handling mode to apply to the policy. This string can have the following values:
Files are classified as typed resources and handled as such.
Only classified resources can be added by default.
Files are handled as raw files (as opposed to typed resources).
Only files can be added by default.
This method is effectively a convenience method for bulk-setting multiple attributes on the instance given a behavior mode.
classifywill configure the file scanner to emit classified resources, configure the
add_includeattribute to only be
Trueon classified resources, and will disable the addition of
Fileresources on resource collectors.
fileswill configure the file scanner to only emit
Fileresources, configure the
Fileand classified resources, and will allow resource collectors to add