Commit 04cf0f8b authored by Robert Bradshaw's avatar Robert Bradshaw Committed by GitHub

Merge pull request #1554 from ogrisel/py3-cache

Fix cythonize(source_filename, cache=True) under Python 3
parents c9bcf1be 9d29358c
...@@ -111,7 +111,8 @@ def nonempty(it, error_msg="expected non-empty iterator"): ...@@ -111,7 +111,8 @@ def nonempty(it, error_msg="expected non-empty iterator"):
@cached_function @cached_function
def file_hash(filename): def file_hash(filename):
path = os.path.normpath(filename.encode("UTF-8")) path = os.path.normpath(filename.encode("UTF-8"))
m = hashlib.md5(str(len(path)) + ":") prefix = (str(len(path)) + ":").encode("UTF-8")
m = hashlib.md5(prefix)
m.update(path) m.update(path)
f = open(filename, 'rb') f = open(filename, 'rb')
try: try:
...@@ -565,13 +566,13 @@ class DependencyTree(object): ...@@ -565,13 +566,13 @@ class DependencyTree(object):
def transitive_fingerprint(self, filename, extra=None): def transitive_fingerprint(self, filename, extra=None):
try: try:
m = hashlib.md5(__version__) m = hashlib.md5(__version__.encode('UTF-8'))
m.update(file_hash(filename)) m.update(file_hash(filename).encode('UTF-8'))
for x in sorted(self.all_dependencies(filename)): for x in sorted(self.all_dependencies(filename)):
if os.path.splitext(x)[1] not in ('.c', '.cpp', '.h'): if os.path.splitext(x)[1] not in ('.c', '.cpp', '.h'):
m.update(file_hash(x)) m.update(file_hash(x).encode('UTF-8'))
if extra is not None: if extra is not None:
m.update(str(extra)) m.update(str(extra).encode('UTF-8'))
return m.hexdigest() return m.hexdigest()
except IOError: except IOError:
return None return None
......
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