1 Honor the 'SOURCE_DATE_EPOCH' environment variable to allow for
4 --- a/Lib/py_compile.py
5 +++ b/Lib/py_compile.py
6 @@ -105,7 +105,10 @@ def compile(file, cfile=None, dfile=None, doraise=False):
8 with open(file, 'U') as f:
10 - timestamp = long(os.fstat(f.fileno()).st_mtime)
11 + if 'SOURCE_DATE_EPOCH' in os.environ:
12 + timestamp = long(os.environ['SOURCE_DATE_EPOCH'])
14 + timestamp = long(os.fstat(f.fileno()).st_mtime)
15 except AttributeError:
16 timestamp = long(os.stat(file).st_mtime)
18 diff --git a/Python/import.c b/Python/import.c
19 index e47ce63..7eecf9c 100644
22 @@ -945,6 +945,11 @@ write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat, t
23 /* Now write the true mtime (as a 32-bit field) */
25 assert(mtime <= 0xFFFFFFFF);
26 + if (Py_GETENV("SOURCE_DATE_EPOCH") != NULL) {
27 + const char *epoch = Py_GETENV("SOURCE_DATE_EPOCH");
28 + mtime = atoi(epoch);
31 PyMarshal_WriteLongToFile((long)mtime, fp, Py_MARSHAL_VERSION);