Skip to content

Commit

Permalink
Merge pull request #165 from SomberNight/202203_zipfile_timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
vsajip committed May 6, 2022
2 parents f7bc8a0 + d3d26bb commit d074f06
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion distlib/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import re
import struct
import sys
import time
from zipfile import ZipInfo

from .compat import sysconfig, detect_encoding, ZipFile
from .resources import finder
Expand Down Expand Up @@ -249,7 +251,13 @@ def _write_script(self, names, shebang, script_bytes, filenames, ext):
launcher = self._get_launcher('w')
stream = BytesIO()
with ZipFile(stream, 'w') as zf:
zf.writestr('__main__.py', script_bytes)
source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
if source_date_epoch:
date_time = time.gmtime(int(source_date_epoch))[:6]
zinfo = ZipInfo(filename='__main__.py', date_time=date_time)
zf.writestr(zinfo, script_bytes)
else:
zf.writestr('__main__.py', script_bytes)
zip_data = stream.getvalue()
script_bytes = launcher + shebang + zip_data
for name in names:
Expand Down

0 comments on commit d074f06

Please sign in to comment.