pub struct ZipAppBuilder { /* private fields */ }
Expand description
Interface for building .zip file based Python applications.
This type implements functionality provided by the Python stdlib zipapp
module. It is used to produce zip files containing Python resources
(notably module source and bytecode) that Python interpreters can execute
as standalone applications.
The zip archives can contain a shebang line (#!<interpreter>
) denoting
a program to use to execute the zipapp. This is typically python
or some
such variant.
Implementations§
Source§impl ZipAppBuilder
impl ZipAppBuilder
Sourcepub fn interpreter(&self) -> Option<&str>
pub fn interpreter(&self) -> Option<&str>
Obtain the interpreter to use in the shebang line.
Sourcepub fn set_interpreter(&mut self, v: impl ToString)
pub fn set_interpreter(&mut self, v: impl ToString)
Set the interpreter to use in the shebang line.
Sourcepub fn modified_time(&self) -> OffsetDateTime
pub fn modified_time(&self) -> OffsetDateTime
Obtain the modified time for files in the wheel archive.
Sourcepub fn set_modified_time(&mut self, v: OffsetDateTime)
pub fn set_modified_time(&mut self, v: OffsetDateTime)
Set the modified time for files in the wheel archive.
Sourcepub fn set_bytecode_compiler(&mut self, v: Box<dyn PythonBytecodeCompiler>)
pub fn set_bytecode_compiler(&mut self, v: Box<dyn PythonBytecodeCompiler>)
Set the Python bytecode compiler to use to turn source code into bytecode.
Sourcepub fn optimize_level(&self) -> BytecodeOptimizationLevel
pub fn optimize_level(&self) -> BytecodeOptimizationLevel
Obtain the bytecode optimization level used when generating Python bytecode.
Sourcepub fn set_optimize_level(&mut self, v: BytecodeOptimizationLevel)
pub fn set_optimize_level(&mut self, v: BytecodeOptimizationLevel)
Set the bytecode optimization level used when generating Python bytecode.
Sourcepub fn add_file_entry(
&mut self,
path: impl AsRef<Path>,
entry: impl Into<FileEntry>,
) -> Result<()>
pub fn add_file_entry( &mut self, path: impl AsRef<Path>, entry: impl Into<FileEntry>, ) -> Result<()>
Add a file to the zip archive.
This is the lowest level mechanism to add an entry to the zip archive. The path/file will be added without modification.
Sourcepub fn add_python_module_source(
&mut self,
source: &PythonModuleSource,
prefix: &str,
) -> Result<()>
pub fn add_python_module_source( &mut self, source: &PythonModuleSource, prefix: &str, ) -> Result<()>
Add Python module source code to the archive.
This only adds source code, not bytecode.
Sourcepub fn add_python_module_source_and_bytecode(
&mut self,
source: &PythonModuleSource,
prefix: &str,
) -> Result<()>
pub fn add_python_module_source_and_bytecode( &mut self, source: &PythonModuleSource, prefix: &str, ) -> Result<()>
Add Python module source and corresponding bytecode to the archive.
This will automatically compile bytecode at the specified optimization level given the source code provided.
Sourcepub fn add_python_module_bytecode(
&mut self,
bytecode: &PythonModuleBytecode,
prefix: &str,
) -> Result<()>
pub fn add_python_module_bytecode( &mut self, bytecode: &PythonModuleBytecode, prefix: &str, ) -> Result<()>
Add Python module bytecode, without corresponding source code.
Sourcepub fn add_main(&mut self, module: &str, func: &str, prefix: &str) -> Result<()>
pub fn add_main(&mut self, module: &str, func: &str, prefix: &str) -> Result<()>
Define the function called when the zip-based application is executed.
This defines a __main__.py[c]
that invokes the func
function in the module
module.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ZipAppBuilder
impl !RefUnwindSafe for ZipAppBuilder
impl !Send for ZipAppBuilder
impl !Sync for ZipAppBuilder
impl Unpin for ZipAppBuilder
impl !UnwindSafe for ZipAppBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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