Always provide the same date and time in 'Py_GetBuildInfo'. This is the information shown at the REPL and in 'sys.version'. We cannot pass it in CPPFLAGS due to whitespace in the DATE string. --- Modules/getbuildinfo.c +++ Modules/getbuildinfo.c @@ -4,6 +4,10 @@ #include #endif +/* Deterministic date and time. */ +#define DATE "Jan 1 1970" +#define TIME "00:00:01" + #ifndef DATE #ifdef __DATE__ #define DATE __DATE__ --- Lib/importlib/_bootstrap.py +++ Lib/importlib/_bootstrap.py @@ -1443,7 +1443,8 @@ class SourceLoader(_LoaderBasics): Implementing this method allows the loader to read bytecode files. Raises IOError when the path cannot be handled. """ - return {'mtime': self.path_mtime(path)} + return {'mtime': float(_os.environ.get(b'SOURCE_DATE_EPOCH', + st.st_mtime))} def _cache_bytecode(self, source_path, cache_path, data): """Optional method which writes data (bytes) to a file path (a str). @@ -1580,7 +1581,10 @@ class SourceFileLoader(FileLoader, SourceLoader): def path_stats(self, path): """Return the metadata for the path.""" st = _path_stat(path) - return {'mtime': st.st_mtime, 'size': st.st_size} + return { + 'mtime': float(_os.environ.get(b'SOURCE_DATE_EPOCH', st.st_mtime)), + 'size': st.st_size + } def _cache_bytecode(self, source_path, bytecode_path, data): # Adapt between the two APIs