diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 5b91c05..a87d178 100644 --- Lib/importlib/_bootstrap.py +++ Lib/importlib/_bootstrap.py @@ -666,8 +666,15 @@ def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None): def _code_to_bytecode(code, mtime=0, source_size=0): """Compile a code object into bytecode for writing out to a byte-compiled file.""" + """os and locale are required for the SOURCE_DATE_EPOCH + deterministic timestamp conditional.""" + import os + import locale data = bytearray(MAGIC_NUMBER) - data.extend(_w_long(mtime)) + if os.getenv('SOURCE_DATE_EPOCH'): + data.extend(_w_long(locale.atoi(os.getenv('SOURCE_DATE_EPOCH')))) + else: + data.extend(_w_long(mtime)) data.extend(_w_long(source_size)) data.extend(marshal.dumps(code)) return data