Skip to content

Commit

Permalink
Fix .conda extension replacement; improve typing (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
dholth authored Aug 27, 2024
1 parent e8cb10f commit 65a13e9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
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

0 comments on commit 65a13e9

Please sign in to comment.