package_streaming module

Unpack conda packages without using a temporary file.

class conda_package_streaming.package_streaming.CondaComponent(*values)

Bases: Enum

info = 'info'
pkg = 'pkg'
class conda_package_streaming.package_streaming.TarfileNoSameOwner(*args, umask: int | None = None, **kwargs)

Bases: TarFile

chmod(tarinfo, targetpath)

Set file permissions of targetpath according to tarinfo, respecting umask.

chown(tarinfo, targetpath, numeric_owner)

Override chown to be a no-op, since we don’t want to preserve ownership here. (tarfile.TarFile only lets us toggle all of (chown, chmod, mtime))

conda_package_streaming.package_streaming.stream_conda_component(filename, fileobj=None, component: CondaComponent | str = CondaComponent.pkg, *, encoding='utf-8', zf: ZipFile | None = None) Generator[tuple[TarFile, TarInfo]]

Yield members from .conda’s embedded {component}- tarball. “info” or “pkg”.

For .tar.bz2 packages, yield all members.

Yields (tar, member) tuples. You must only use the current member to prevent tar seeks and scans.

To extract to disk, it’s possible to call tar.extractall(path) on the first result and then ignore the rest of this generator. extractall takes care of some directory permissions/mtime issues, compared to extract or writing out the file objects yourself.

Parameters:
  • filename – path or file-like object to the .conda or .tar.bz2 file

  • component – “pkg” or “info” component to extract

  • encoding – “utf-8” passed to TarFile.open(); can be changed for testing.

  • zf – optional pre-opened zipfile.ZipFile for .conda archives. When provided, reuses the already-opened ZipFile instead of parsing the central directory again. Callers that stream both the pkg and info components can open the zip once and pass it in both times, avoiding duplicate parsing. See #173.

conda_package_streaming.package_streaming.stream_conda_info(filename, fileobj=None) Generator[tuple[TarFile, TarInfo]]

Yield members from conda’s embedded info/ tarball.

For .tar.bz2 packages, yield all members.

Yields (tar, member) tuples. You must only use the current member to prevent tar seeks and scans.

To extract to disk, it’s possible to call tar.extractall(path) on the first result and then ignore the rest of this generator. extractall takes care of some directory permissions/mtime issues, compared to extract or writing out the file objects yourself.

conda_package_streaming.package_streaming.tar_generator(fileobj, tarfile_open=<bound method TarFile.open of <class 'conda_package_streaming.package_streaming.TarfileNoSameOwner'>>, closefd=False, *, encoding='utf-8') Generator[tuple[TarFile, TarInfo]]

Yield (tar, member) from fileobj.

Parameters:
  • fileobj – file-like object

  • encoding – “utf-8” passed to TarFile.open(); can be changed for testing.