diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/py_compile.py | 2 | ||||
-rw-r--r-- | Lib/test/test_py_compile.py | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/py_compile.py b/Lib/py_compile.py index a0f4def..16dc0a0 100644 --- a/Lib/py_compile.py +++ b/Lib/py_compile.py @@ -112,6 +112,8 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1, the resulting file would be regular and thus not the same type of file as it was previously. """ + if os.environ.get('SOURCE_DATE_EPOCH'): + invalidation_mode = PycInvalidationMode.CHECKED_HASH if cfile is None: if optimize >= 0: optimization = optimize if optimize >= 1 else '' diff --git a/Lib/test/test_py_compile.py b/Lib/test/test_py_compile.py index bcb686c..8fc0b33 100644 --- a/Lib/test/test_py_compile.py +++ b/Lib/test/test_py_compile.py @@ -98,6 +98,18 @@ class PyCompileTests(unittest.TestCase): self.assertFalse(os.path.exists( importlib.util.cache_from_source(bad_coding))) + def test_source_date_epoch(self): + testtime = 123456789 + with support.EnvironmentVarGuard() as env: + env["SOURCE_DATE_EPOCH"] = str(testtime) + py_compile.compile(self.source_path, self.pyc_path) + self.assertTrue(os.path.exists(self.pyc_path)) + self.assertFalse(os.path.exists(self.cache_path)) + with open(self.pyc_path, 'rb') as fp: + flags = importlib._bootstrap_external._classify_pyc( + fp.read(), 'test', {}) + self.assertEqual(flags, 0b11) + @unittest.skipIf(sys.flags.optimize > 0, 'test does not work with -O') def test_double_dot_no_clobber(self): # http://bugs.python.org/issue22966 |