diff --git a/news/251-extension-str-replace b/news/251-extension-str-replace new file mode 100644 index 00000000..294e4eb7 --- /dev/null +++ b/news/251-extension-str-replace @@ -0,0 +1,20 @@ +### Enhancements + +* + +### Bug fixes + +* Replace `.conda` or `.tar.bz2` extensions from end of string only instead of + `str.replace(...)` (#251) + +### Deprecations + +* + +### Docs + +* + +### Other + +* diff --git a/news/improve-typing b/news/improve-typing new file mode 100644 index 00000000..0e177fed --- /dev/null +++ b/news/improve-typing @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* Improve type annotations on an internal function (#257) diff --git a/src/conda_package_handling/api.py b/src/conda_package_handling/api.py index c8d572f3..47881ce4 100644 --- a/src/conda_package_handling/api.py +++ b/src/conda_package_handling/api.py @@ -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: diff --git a/src/conda_package_handling/conda_fmt.py b/src/conda_package_handling/conda_fmt.py index 5c363b4b..5342d622 100644 --- a/src/conda_package_handling/conda_fmt.py +++ b/src/conda_package_handling/conda_fmt.py @@ -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) diff --git a/src/conda_package_handling/streaming.py b/src/conda_package_handling/streaming.py index 4f367a43..f05f981a 100644 --- a/src/conda_package_handling/streaming.py +++ b/src/conda_package_handling/streaming.py @@ -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 @@ -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"]