Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extraction even if <prefix>name.conda has been added to the original name of the file. #85

Closed
wants to merge 9 commits into from
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
[//]: # (current developments)

## 0.11.0

* Relax `package_streaming.stream_conda_component` to find inner component
archives even if a prefix `<prefix>name-1.0-a_0.conda` has been added to the
`.conda` filename.
(https://github.com/conda/conda-package-handling/issues/230)

## 0.10.0 (2024-06)

* Use zip64 extensions when converting .tar.bz2 to .conda, if uncompressed size
Expand Down
13 changes: 10 additions & 3 deletions conda_package_streaming/package_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@ def stream_conda_component(

zf = zipfile.ZipFile(fileobj or filename)
file_id, _, _ = os.path.basename(filename).rpartition(".")
component_name = f"{component}-{file_id}"

# deal with file_id possibly having a <subdir>_ prefix... compensates for
# web downloads from anaconda.org having the platform as a prefix
component_prefix = f"{component}-"
component_suffix = f"{file_id}.tar.zst"
component_filename = [
info for info in zf.infolist() if info.filename.startswith(component_name)
info
for info in zf.infolist()
if info.filename.startswith(component_prefix)
and component_suffix.endswith(info.filename.split("-", 1)[-1])
]
if not component_filename:
raise LookupError(f"didn't find {component_name} component in {filename}")
raise LookupError(f"didn't find {component} component in {filename}")
assert len(component_filename) == 1
reader = zstandard.ZstdDecompressor().stream_reader(
zf.open(component_filename[0])
Expand Down
13 changes: 13 additions & 0 deletions tests/test_streaming.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import io
import json
import os
import shutil
import tarfile

import pytest

from conda_package_streaming import package_streaming


@pytest.mark.parametrize("subdir", ["linux-64", "noarch", "win-32", "osx-arm64"])
def test_package_streaming_with_subdir_prefix(conda_paths, tmp_path, subdir):
"""Regression test for https://github.com/conda/conda-package-handling/issues/230"""
for path in conda_paths:
copied_file = tmp_path / f"{subdir}_{os.path.basename(path)}"
shutil.copyfile(path, copied_file)

if str(path).endswith(".conda"):
package_streaming.stream_conda_component(copied_file, component="info")


def test_package_streaming(conda_paths):
for path in conda_paths:
if str(path).endswith(".conda"):
Expand Down
Loading