Commit 2997c9d4 authored by Stefan Behnel's avatar Stefan Behnel

avoid hard dependency on gzip module

parent 1b05e8bd
...@@ -3,7 +3,13 @@ from Cython import __version__ ...@@ -3,7 +3,13 @@ from Cython import __version__
from glob import glob from glob import glob
import re, os, sys import re, os, sys
import gzip try:
import gzip
gzip_open = gz.open
gzip_ext = '.gz'
except ImportError:
gzip_open = open
gzip_ext = ''
import shutil import shutil
import subprocess import subprocess
...@@ -647,12 +653,12 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None): ...@@ -647,12 +653,12 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None):
# Cython-generated c files are highly compressible. # Cython-generated c files are highly compressible.
# (E.g. a compression ratio of about 10 for Sage). # (E.g. a compression ratio of about 10 for Sage).
fingerprint_file = join_path( fingerprint_file = join_path(
options.cache, "%s-%s.gz" % (os.path.basename(c_file), fingerprint)) options.cache, "%s-%s%s" % (os.path.basename(c_file), fingerprint, gzip_ext))
if os.path.exists(fingerprint_file): if os.path.exists(fingerprint_file):
if not quiet: if not quiet:
print("Found compiled %s in cache" % pyx_file) print("Found compiled %s in cache" % pyx_file)
os.utime(fingerprint_file, None) os.utime(fingerprint_file, None)
g = gzip.open(fingerprint_file) g = gzip_open(fingerprint_file, 'rb')
try: try:
f = open(c_file, 'wb') f = open(c_file, 'wb')
try: try:
...@@ -681,7 +687,7 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None): ...@@ -681,7 +687,7 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None):
if fingerprint: if fingerprint:
f = open(c_file, 'rb') f = open(c_file, 'rb')
try: try:
g = gzip.open(fingerprint_file, 'wb') g = gzip_open(fingerprint_file, 'wb')
try: try:
shutil.copyfileobj(f, g) shutil.copyfileobj(f, g)
finally: finally:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment