Struct ZipAppBuilder

Source
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

Source

pub fn interpreter(&self) -> Option<&str>

Obtain the interpreter to use in the shebang line.

Source

pub fn set_interpreter(&mut self, v: impl ToString)

Set the interpreter to use in the shebang line.

Source

pub fn modified_time(&self) -> OffsetDateTime

Obtain the modified time for files in the wheel archive.

Source

pub fn set_modified_time(&mut self, v: OffsetDateTime)

Set the modified time for files in the wheel archive.

Source

pub fn set_bytecode_compiler(&mut self, v: Box<dyn PythonBytecodeCompiler>)

Set the Python bytecode compiler to use to turn source code into bytecode.

Source

pub fn optimize_level(&self) -> BytecodeOptimizationLevel

Obtain the bytecode optimization level used when generating Python bytecode.

Source

pub fn set_optimize_level(&mut self, v: BytecodeOptimizationLevel)

Set the bytecode optimization level used when generating Python bytecode.

Source

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.

Source

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.

Source

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.

Source

pub fn add_python_module_bytecode( &mut self, bytecode: &PythonModuleBytecode, prefix: &str, ) -> Result<()>

Add Python module bytecode, without corresponding source code.

Source

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.

Source

pub fn write_zip_app(&self, writer: &mut (impl Write + Seek)) -> Result<()>

Writes zip archive data to a writer.

This will emit a zip archive + optional leading shebang so it is runnable as a standalone executable file.

Source

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

Write the zip archive to a filesystem path.

Trait Implementations§

Source§

impl Default for ZipAppBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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.