From 5b12568c4f17fb9914be9e903eff3aad007049ef Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 28 Apr 2021 17:00:58 +0200 Subject: Make Spack able to apply gz compressed remote patches (#22823) Modified ncbi-rmblastn to retrieve patches from remote --- lib/spack/spack/fetch_strategy.py | 2 ++ lib/spack/spack/util/compression.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py index ff41c759ea..b5ce8495e3 100644 --- a/lib/spack/spack/fetch_strategy.py +++ b/lib/spack/spack/fetch_strategy.py @@ -467,6 +467,8 @@ class URLFetchStrategy(FetchStrategy): tarball_container = os.path.join(self.stage.path, "spack-expanded-archive") + # Below we assume that the command to decompress expand the + # archive in the current working directory mkdirp(tarball_container) with working_dir(tarball_container): decompress(self.archive_file) diff --git a/lib/spack/spack/util/compression.py b/lib/spack/spack/util/compression.py index 2f190e94e1..a1a0e1d6f3 100644 --- a/lib/spack/spack/util/compression.py +++ b/lib/spack/spack/util/compression.py @@ -22,6 +22,22 @@ def allowed_archive(path): return any(path.endswith(t) for t in ALLOWED_ARCHIVE_TYPES) +def _gunzip(archive_file): + """Like gunzip, but extracts in the current working directory + instead of in-place. + + Args: + archive_file (str): absolute path of the file to be decompressed + """ + import gzip + decompressed_file = os.path.basename(archive_file.strip('.gz')) + working_dir = os.getcwd() + destination_abspath = os.path.join(working_dir, decompressed_file) + with gzip.open(archive_file, "rb") as f_in: + with open(destination_abspath, "wb") as f_out: + f_out.write(f_in.read()) + + def decompressor_for(path, extension=None): """Get the appropriate decompressor for a path.""" if ((extension and re.match(r'\.?zip$', extension)) or @@ -30,8 +46,7 @@ def decompressor_for(path, extension=None): unzip.add_default_arg('-q') return unzip if extension and re.match(r'gz', extension): - gunzip = which('gunzip', required=True) - return gunzip + return _gunzip if extension and re.match(r'bz2', extension): bunzip2 = which('bunzip2', required=True) return bunzip2 -- cgit v1.2.3-70-g09d2