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

Fix .conda extension replacement; improve typing #257

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions news/251-extension-str-replace
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Enhancements

* <news item>

### Bug fixes

* Replace `.conda` or `.tar.bz2` extensions from end of string only instead of
`str.replace(...)` (#251)

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
19 changes: 19 additions & 0 deletions news/improve-typing
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* Improve type annotations on an internal function (#257)
9 changes: 5 additions & 4 deletions src/conda_package_handling/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,11 @@ def transmute(in_file, out_ext, out_folder=None, processes=1, **kw):
out_folder = _os.path.dirname(in_file) or _os.getcwd()

flist = set(_glob(in_file))
if in_file.endswith(".tar.bz2"):
flist = flist - set(_glob(in_file.replace(".tar.bz2", out_ext)))
elif in_file.endswith(".conda"):
flist = flist - set(_glob(in_file.replace(".conda", out_ext)))
for in_ext in SUPPORTED_EXTENSIONS:
if in_file.endswith(in_ext):
replacement = in_file[: -len(in_ext)] + out_ext
flist = flist - set(_glob(replacement))
break

failed_files = {}
with _get_executor(processes) as executor:
Expand Down
2 changes: 1 addition & 1 deletion src/conda_package_handling/conda_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create(
out_folder = os.path.dirname(out_fn)
out_fn = os.path.basename(out_fn)
conda_pkg_fn = os.path.join(out_folder, out_fn)
file_id = out_fn.replace(".conda", "")
file_id = out_fn[: -len(".conda")]
pkg_files = utils.filter_info_files(file_list, prefix)
# preserve order
pkg_files_set = set(pkg_files)
Expand Down
7 changes: 4 additions & 3 deletions src/conda_package_handling/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from __future__ import annotations

import io
import tarfile
from contextlib import redirect_stdout
from tarfile import TarError, TarFile, TarInfo
from typing import Iterator
from tarfile import TarError
from typing import Generator
from zipfile import BadZipFile

from conda_package_streaming.extract import exceptions as cps_exceptions
Expand All @@ -20,7 +21,7 @@ def _stream_components(
filename: str,
components: list[str],
dest_dir: str = "",
) -> Iterator[tuple[TarFile, TarInfo]]:
) -> Generator[Generator[tuple[tarfile.TarFile, tarfile.TarInfo]]]:
if str(filename).endswith(".tar.bz2"):
assert components == ["pkg"]

Expand Down
Loading