Skip to content

Commit

Permalink
Make sdist determinisitic by setting gzip mtime to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Feb 28, 2019
1 parent 4a82287 commit 6814ad1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion poetry/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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
15 changes: 15 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 pytest
import re
import shutil
Expand Down Expand Up @@ -510,3 +511,17 @@ def test_proper_python_requires_if_three_digits_precision_version_specified():
parsed = p.parsestr(to_str(pkg_info))

assert parsed["Requires-Python"] == "==2.7.15"

def test_sdist_mtime_zero():
poetry = Poetry.create(project("module1"))

builder = SdistBuilder(poetry, NullEnv(), NullIO())
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 6814ad1

Please sign in to comment.