Skip to content

Commit

Permalink
Make sdist deterministic by setting gzip mtime to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Oct 24, 2020
1 parent 727907d commit 7004040
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def build(self, target_dir=None): # type: (Path) -> Path
target = target_dir / "{}-{}.tar.gz".format(
self._package.pretty_name, self._meta.version
)
gz = GzipFile(target.as_posix(), mode="wb")
gz = GzipFile(target.as_posix(), mode="wb", mtime=0)
tar = tarfile.TarFile(
target.as_posix(), mode="w", fileobj=gz, format=tarfile.PAX_FORMAT
)
Expand Down
16 changes: 16 additions & 0 deletions tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import ast
import gzip
import shutil
import tarfile

Expand Down Expand Up @@ -587,3 +588,18 @@ def test_sdist_disable_setup_py():
"my-package-1.2.3/PKG-INFO",
"my-package-1.2.3/my_package/__init__.py",
}


def test_sdist_mtime_zero():
poetry = Factory().create_poetry(project("module1"))

builder = SdistBuilder(poetry)
builder.build()

sdist = fixtures_dir / "module1" / "dist" / "module1-0.1.tar.gz"

assert sdist.exists()

with gzip.open(str(sdist), "rb") as gz:
gz.read(100)
assert gz.mtime == 0

0 comments on commit 7004040

Please sign in to comment.