##// END OF EJS Templates
Merge pull request #12539 from rushabh-v/retar...
Merge pull request #12539 from rushabh-v/retar use pathlib.Path in retar.py

File last commit:

r25998:90b78848
r26006:6c34e4a3 merge
Show More
retar.py
68 lines | 1.6 KiB | text/x-python | PythonLexer
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 """
Un-targz and retargz a targz file to ensure reproducible build.
usage:
$ export SOURCE_DATE_EPOCH=$(date +%s)
...
$ python retar.py <tarfile.gz>
The process of creating an sdist can be non-reproducible:
- directory created during the process get a mtime of the creation date;
- gziping files embed the timestamp of fo zip creation.
This will untar-retar; ensuring that all mtime > SOURCE_DATE_EPOCH will be set
equal to SOURCE_DATE_EPOCH.
"""
import tarfile
import sys
import os
import gzip
import io
rushabh-v
use pathlib.Path in retar.py
r25998 from pathlib import Path
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 if len(sys.argv) > 2:
raise ValueError("Too many arguments")
timestamp = int(os.environ["SOURCE_DATE_EPOCH"])
rushabh-v
use pathlib.Path in retar.py
r25998 path = Path(sys.argv[1])
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 old_buf = io.BytesIO()
rushabh-v
use pathlib.Path in retar.py
r25998 with open(path, "rb") as f:
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 old_buf.write(f.read())
old_buf.seek(0)
old = tarfile.open(fileobj=old_buf, mode="r:gz")
buf = io.BytesIO()
new = tarfile.open(fileobj=buf, mode="w", format=tarfile.GNU_FORMAT)
for i, m in enumerate(old):
data = None
# mutation does not work, copy
if m.name.endswith('.DS_Store'):
continue
m2 = tarfile.TarInfo(m.name)
m2.mtime = min(timestamp, m.mtime)
m2.size = m.size
m2.type = m.type
m2.linkname = m.linkname
Matthias Bussonnier
fix conda build
r25866 m2.mode = m.mode
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 if m.isdir():
Matthias Bussonnier
Fix retaring process for twine....
r25795 new.addfile(m2)
else:
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 data = old.extractfile(m)
new.addfile(m2, data)
new.close()
old.close()
buf.seek(0)
rushabh-v
use pathlib.Path in retar.py
r25998 with open(path, "wb") as f:
Matthias Bussonnier
Update the release process to attempt reproducible builds....
r25769 with gzip.GzipFile('', "wb", fileobj=f, mtime=timestamp) as gzf:
gzf.write(buf.read())
Matthias Bussonnier
Fix retaring process for twine....
r25795
# checks the archive is valid.
rushabh-v
use pathlib.Path in retar.py
r25998 archive = tarfile.open(path)
Matthias Bussonnier
Fix retaring process for twine....
r25795 names = archive.getnames()