diff options
author | Harmen Stoppels <me@harmenstoppels.nl> | 2024-03-22 16:57:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 16:57:46 +0100 |
commit | 434836be81fe763c61b3c69de30d42c3b5d78e85 (patch) | |
tree | 6a381b50845a3851f251e4a0aed72f168ed5597b /lib | |
parent | 7b9b976f40565e967846d553a05e4669c90a316d (diff) | |
download | spack-434836be81fe763c61b3c69de30d42c3b5d78e85.tar.gz spack-434836be81fe763c61b3c69de30d42c3b5d78e85.tar.bz2 spack-434836be81fe763c61b3c69de30d42c3b5d78e85.tar.xz spack-434836be81fe763c61b3c69de30d42c3b5d78e85.zip |
python wheels: do not "expand" (#43317)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/llnl/url.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/test/llnl/url.py | 2 | ||||
-rw-r--r-- | lib/spack/spack/test/util/compression.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/util/compression.py | 18 |
4 files changed, 22 insertions, 10 deletions
diff --git a/lib/spack/llnl/url.py b/lib/spack/llnl/url.py index 28f3187dd9..9812af5eaa 100644 --- a/lib/spack/llnl/url.py +++ b/lib/spack/llnl/url.py @@ -12,7 +12,7 @@ from urllib.parse import urlsplit, urlunsplit # Archive extensions allowed in Spack PREFIX_EXTENSIONS = ("tar", "TAR") EXTENSIONS = ("gz", "bz2", "xz", "Z") -NO_TAR_EXTENSIONS = ("zip", "tgz", "tbz2", "tbz", "txz") +NO_TAR_EXTENSIONS = ("zip", "tgz", "tbz2", "tbz", "txz", "whl") # Add PREFIX_EXTENSIONS and EXTENSIONS last so that .tar.gz is matched *before* .tar or .gz ALLOWED_ARCHIVE_TYPES = ( @@ -403,7 +403,7 @@ def expand_contracted_extension_in_path( def compression_ext_from_compressed_archive(extension: str) -> Optional[str]: """Returns compression extension for a compressed archive""" extension = expand_contracted_extension(extension) - for ext in [*EXTENSIONS]: + for ext in EXTENSIONS: if ext in extension: return ext return None diff --git a/lib/spack/spack/test/llnl/url.py b/lib/spack/spack/test/llnl/url.py index 1afee9c05c..3e13e6a729 100644 --- a/lib/spack/spack/test/llnl/url.py +++ b/lib/spack/spack/test/llnl/url.py @@ -148,6 +148,8 @@ def test_strip_compression_extension(archive_and_expected): assert stripped == "Foo.zip" stripped = llnl.url.strip_compression_extension(archive, "zip") assert stripped == "Foo" + elif extension == "whl": + assert stripped == "Foo.whl" elif ( extension.lower() == "tar" or extension in llnl.url.CONTRACTION_MAP diff --git a/lib/spack/spack/test/util/compression.py b/lib/spack/spack/test/util/compression.py index ab38da78ac..f3660e4dda 100644 --- a/lib/spack/spack/test/util/compression.py +++ b/lib/spack/spack/test/util/compression.py @@ -29,7 +29,9 @@ ext_archive = {} ] # Spack does not use Python native handling for tarballs or zip # Don't test tarballs or zip in native test -native_archive_list = [key for key in ext_archive.keys() if "tar" not in key and "zip" not in key] +native_archive_list = [ + key for key in ext_archive.keys() if "tar" not in key and "zip" not in key and "whl" not in key +] @pytest.fixture @@ -71,7 +73,9 @@ def test_native_unpacking(tmpdir_factory, archive_file_and_extension): @pytest.mark.not_on_windows("Only Python unpacking available on Windows") @pytest.mark.parametrize( - "archive_file_and_extension", [(ext, True) for ext in ext_archive.keys()], indirect=True + "archive_file_and_extension", + [(ext, True) for ext in ext_archive.keys() if "whl" not in ext], + indirect=True, ) def test_system_unpacking(tmpdir_factory, archive_file_and_extension, compr_support_check): # actually run test diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index f25841ee70..08edc1949a 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -9,7 +9,7 @@ import io import os import shutil import sys -from typing import BinaryIO, Callable, Dict, List, Optional +from typing import Any, BinaryIO, Callable, Dict, List, Optional import llnl.url from llnl.util import tty @@ -157,6 +157,10 @@ def _system_gunzip(archive_file: str) -> str: return destination_abspath +def _do_nothing(archive_file: str) -> None: + return None + + def _unzip(archive_file: str) -> str: """Returns path to extracted zip archive. Extract Zipfile, searching for unzip system executable. If unavailable, search for 'tar' executable on system and use instead. @@ -283,7 +287,7 @@ def decompressor_for(path: str, extension: Optional[str] = None): return decompressor_for_nix(extension) -def decompressor_for_nix(extension: str) -> Callable[[str], str]: +def decompressor_for_nix(extension: str) -> Callable[[str], Any]: """Returns a function pointer to appropriate decompression algorithm based on extension type and unix specific considerations i.e. a reasonable expectation system utils like gzip, bzip2, and xz are available @@ -291,18 +295,19 @@ def decompressor_for_nix(extension: str) -> Callable[[str], str]: Args: extension: path of the archive file requiring decompression """ - extension_to_decompressor: Dict[str, Callable[[str], str]] = { + extension_to_decompressor: Dict[str, Callable[[str], Any]] = { "zip": _unzip, "gz": _gunzip, "bz2": _bunzip2, "Z": _system_unZ, # no builtin support for .Z files "xz": _lzma_decomp, + "whl": _do_nothing, } return extension_to_decompressor.get(extension, _system_untar) -def _determine_py_decomp_archive_strategy(extension: str) -> Optional[Callable[[str], str]]: +def _determine_py_decomp_archive_strategy(extension: str) -> Optional[Callable[[str], Any]]: """Returns appropriate python based decompression strategy based on extension type""" extension_to_decompressor: Dict[str, Callable[[str], str]] = { @@ -313,7 +318,7 @@ def _determine_py_decomp_archive_strategy(extension: str) -> Optional[Callable[[ return extension_to_decompressor.get(extension, None) -def decompressor_for_win(extension: str) -> Callable[[str], str]: +def decompressor_for_win(extension: str) -> Callable[[str], Any]: """Returns a function pointer to appropriate decompression algorithm based on extension type and Windows specific considerations @@ -323,7 +328,7 @@ def decompressor_for_win(extension: str) -> Callable[[str], str]: and files as Python does not provide support for the UNIX compress algorithm """ extension = llnl.url.expand_contracted_extension(extension) - extension_to_decompressor: Dict[str, Callable[[str], str]] = { + extension_to_decompressor: Dict[str, Callable[[str], Any]] = { # Windows native tar can handle .zip extensions, use standard unzip method "zip": _unzip, # if extension is standard tarball, invoke Windows native tar @@ -333,6 +338,7 @@ def decompressor_for_win(extension: str) -> Callable[[str], str]: # detected "Z": _system_unZ, "xz": _lzma_decomp, + "whl": _do_nothing, } decompressor = extension_to_decompressor.get(extension) |