create module¶
Tools for creating .conda-format archives.
Uses tempfile.SpooledTemporaryFile to buffer pkg-*.tar and
info-*.tar, then compress directly into an open ZipFile at the end.
SpooledTemporaryFile buffers the first 10MB of the package and its metadata in
memory, but writes out to disk for larger packages.
Uses more disk space than conda-package-handling (temporary uncompressed
tarballs of the package contents) but accepts streams instead of just
files-on-the-filesystem.
- class conda_package_streaming.create.CondaTarFile(*args, info_tar: ~tarfile.TarFile, is_info=<function CondaTarFile.<lambda>>, **kwargs)¶
Bases:
TarFileSubclass of
tarfile.TarFilethat adds members to a secondinfotar if they matchis_info(name).Create this with
conda_builder(...)which sets up the component archives, then wraps them into a.condaon exit.Only useful for creating, not extracting
.conda.- addfile(tarinfo, fileobj=None)¶
Add the TarInfo object
tarinfoto the archive. Iffileobjis given, it should be a binary file, and tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by usinggettarinfo().If
self.is_info(tarinfo.name)returnsTrue, addtarinfotoself.info_tarinstead.
- conda_package_streaming.create.anonymize(tarinfo: TarInfo)¶
Pass to
tarfile.add(..., filter=anonymize)to anonymize uid/gid.Does not anonymize mtime or any other field.
- conda_package_streaming.create.conda_builder(stem, path, *, compressor: ~typing.Callable[[], ~zstandard.backend_c.ZstdCompressor] = <function <lambda>>, is_info: ~typing.Callable[[str], bool] = <function <lambda>>, encoding='utf-8') Iterator[CondaTarFile]¶
Produce a
TarFilesubclass used to build a.condapackage. The subclass delegatesaddfile()to theinfo-component whenis_inforeturns True.When the context manager exits,
{path}/{stem}.condais written with the component tar archives.- Parameters:
stem – output filename without extension
path – destination path for transmuted .conda package compressor: A function that creates instances of
zstandard.ZstdCompressor().encoding – passed to TarFile constructor. Keep default “utf-8” for valid .conda.
- Yields:
CondaTarFile