From 7004040c64afb47c4fff1baa4fa07e73d3822d28 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Sat, 24 Oct 2020 13:03:01 -0400 Subject: [PATCH] Make sdist deterministic by setting gzip mtime to 0 --- poetry/core/masonry/builders/sdist.py | 2 +- tests/masonry/builders/test_sdist.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/poetry/core/masonry/builders/sdist.py b/poetry/core/masonry/builders/sdist.py index 981b63b2a..5e954cafa 100644 --- a/poetry/core/masonry/builders/sdist.py +++ b/poetry/core/masonry/builders/sdist.py @@ -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 ) diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index 02f0a65ca..5c39eb57a 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import ast +import gzip import shutil import tarfile @@ -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