transmute module

Convert .tar.bz2 to .conda

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.

conda_package_streaming.transmute.transmute(package, path, *, compressor: LegacyCompressorOrFactory | None = None, compression_level: int | None = None, compression_threads: int | None = None, is_info: Callable[[str], bool] = <function <lambda>>) Path

Convert .tar.bz2 conda package to .conda-format under path.

Parameters:
  • package – path to .tar.bz2 conda package

  • path – destination path for transmuted .conda package

  • compressor – Legacy zstandard compressor object (or factory returning one) with stream_writer(...). Mutually exclusive with compression_level and compression_threads.

  • compression_level – zstd compression level for compression.zstd or backports.zstd code path. Defaults to ZSTD_COMPRESS_LEVEL if not specified and compressor is None.

  • compression_threads – Number of zstd worker threads for compression.zstd or backports.zstd code path. Defaults to ZSTD_COMPRESS_THREADS if not specified and compressor is None.

  • is_info – A function that returns True if a file belongs in the info component of a .conda package. conda-package-handling (not this package conda-package-streaming) uses a set of regular expressions to keep expected items in the info- component, while other items starting with info/ wind up in the pkg- component.

Returns:

Path to transmuted package.

conda_package_streaming.transmute.transmute_stream(stem, path, *, compressor: LegacyCompressorOrFactory | None = None, compression_level: int | None = None, compression_threads: int | None = None, is_info: Callable[[str], bool] = <function <lambda>>, package_stream: Iterator[tuple[tarfile.TarFile, tarfile.TarInfo]])

Convert (TarFile, TarInfo) iterator like those produced by stream_conda_component to .conda-format under path. Allows for more creative data sources.

e.g. recompress .conda:

transmute_stream(
    ...,
    package_stream=itertools.chain(
        stream_conda_component("package.conda", component=CondaComponent.pkg),
        stream_conda_component("package.conda", component=CondaComponent.info),
    ),
)

This example could move files between the pkg- and info- components depending on the is_info function.

Parameters:
  • stem – output filename without extension

  • path – destination path for transmuted .conda package

  • compressor – Legacy zstandard compressor object (or factory returning one) with stream_writer(...). Mutually exclusive with compression_level and compression_threads.

  • compression_level – zstd compression level for compression.zstd or backports.zstd code path. Defaults to ZSTD_COMPRESS_LEVEL if not specified and compressor is None.

  • compression_threads – Number of zstd worker threads for compression.zstd or backports.zstd code path. Defaults to ZSTD_COMPRESS_THREADS if not specified and compressor is None.

  • is_info – A function that returns True if a file belongs in the info component of a .conda package. conda-package-handling (not this package conda-package-streaming) uses a set of regular expressions to keep expected items in the info- component, while other items starting with info/ wind up in the pkg- component.

  • package_stream – Iterator of (Tarfile, TarInfo) tuples.

Returns:

Path to transmuted package.

conda_package_streaming.transmute.transmute_tar_bz2(package: str, path) Path

Convert .conda package to .tar.bz2 format under path.

Can recompress .tar.bz2 packages.

Parameters:
  • package – path to .conda or .tar.bz2 package.

  • path – destination path for transmuted package.

Returns:

Path to transmuted package.