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: TarFile

Subclass of tarfile.TarFile that adds members to a second info tar if they match is_info(name).

Create this with conda_builder(...) which sets up the component archives, then wraps them into a .conda on exit.

Only useful for creating, not extracting .conda.

addfile(tarinfo, fileobj=None)

Add the TarInfo object tarinfo to the archive. If fileobj is 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 using gettarinfo().

If self.is_info(tarinfo.name) returns True, add tarinfo to self.info_tar instead.

info_tar: TarFile
is_info: Callable
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[[], ~zstd.ZstdCompressor] = <function <lambda>>, is_info: ~typing.Callable[[str], bool] = <function <lambda>>, encoding='utf-8') Iterator[CondaTarFile]

Produce a TarFile subclass used to build a .conda package. The subclass delegates addfile() to the info- component when is_info returns True.

When the context manager exits, {path}/{stem}.conda is 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