From f6d8780107ee01c406cd907b4042a0a9dc1e14da Mon Sep 17 00:00:00 2001 From: Ben Thompson Date: Mon, 3 Aug 2020 12:48:01 -0400 Subject: [PATCH] Fix case where compiled extension doesn't exist. --- VERSION | 2 +- cppimport/checksum.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 3dc245c..6c37f33 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -20.08.04 +20.08.04.2 diff --git a/cppimport/checksum.py b/cppimport/checksum.py index e89b45e..ba971c6 100644 --- a/cppimport/checksum.py +++ b/cppimport/checksum.py @@ -24,14 +24,19 @@ def calc_cur_checksum(file_lst, module_data): return hashlib.md5(text).hexdigest() def load_checksum_trailer(module_data): - with open(module_data['ext_path'], 'rb') as f: - f.seek(-_FMT.size, 2) - json_len, tag = _FMT.unpack(f.read(_FMT.size)) - if tag != _TAG: - cppimport.config.quiet_print("Missing trailer tag") - return None, None - f.seek(-(_FMT.size + json_len), 2) - json_s = f.read(json_len) + try: + with open(module_data['ext_path'], 'rb') as f: + f.seek(-_FMT.size, 2) + json_len, tag = _FMT.unpack(f.read(_FMT.size)) + if tag != _TAG: + cppimport.config.quiet_print("Missing trailer tag") + return None, None + f.seek(-(_FMT.size + json_len), 2) + json_s = f.read(json_len) + except FileNotFoundError: + cppimport.config.quiet_print("Failed to find compiled extension; rebuilding.") + return None, None + try: deps, old_checksum = json.loads(json_s) except ValueError: