Skip to content

Commit 96fa9cb

Browse files
committed
remove call to system-wide gunzip. Use python version instead. Fixes astropy#1538
1 parent 54e6b58 commit 96fa9cb

1 file changed

Lines changed: 11 additions & 29 deletions

File tree

‎astroquery/utils/system_tools.py‎

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import subprocess
44
import os
55

6-
76
# Import DEVNULL for py3 or py3
87
try:
98
from subprocess import DEVNULL
@@ -12,31 +11,7 @@
1211

1312
# Check availability of some system tools
1413
# Exceptions are raised if not found
15-
__is_gzip_found = False
16-
for test_cmd in (["gzip", "-V"], ["7z"]):
17-
try:
18-
subprocess.call(test_cmd, stdout=DEVNULL, stderr=DEVNULL)
19-
except OSError:
20-
pass
21-
else:
22-
__is_gzip_found = test_cmd[0]
23-
24-
25-
if __is_gzip_found == 'gzip':
26-
def _unzip_cmd(filename):
27-
return ["gzip", "-d", "{0}".format(filename)]
28-
elif __is_gzip_found == '7z':
29-
def _unzip_cmd(filename):
30-
return ["7z", "x",
31-
"{0}".format(filename),
32-
"-o{0}".format(os.path.split(filename)[0])]
33-
else:
34-
print("gzip was not found on your system! You should solve this issue for "
35-
"astroquery.eso to be at its best!\n"
36-
"On POSIX system: make sure gzip is installed and in your path!"
37-
"On Windows: same for 7-zip (http://www.7-zip.org)!")
38-
39-
14+
4015
def gunzip(filename):
4116
""" Decompress a file with gzip.
4217
@@ -50,9 +25,16 @@ def gunzip(filename):
5025
Name of the decompressed file (or input filename if gzip is not
5126
available).
5227
"""
53-
# ".fz" denotes RICE rather than gzip compression
54-
if __is_gzip_found and not filename.endswith('.fz'):
55-
subprocess.call(_unzip_cmd(filename), stdout=DEVNULL, stderr=DEVNULL)
28+
import shutil
29+
import gzip
30+
31+
# @EP 09/01/20: system-wide 'gzip' was removed, Python gzip used instead.
32+
# See #1538 : https://github.com/astropy/astroquery/issues/1538
33+
34+
if not filename.endswith('.fz'):
35+
with gzip.open(filename, 'rb') as f_in:
36+
with open(filename.rsplit(".", 1)[0], 'wb') as f_out:
37+
shutil.copyfileobj(f_in, f_out)
5638
return filename.rsplit(".", 1)[0]
5739
else:
5840
return filename

0 commit comments

Comments
 (0)