Skip to content

Commit

Permalink
Refactor rules concerning warning vs info in sdists
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Oct 6, 2024
1 parent 93f7526 commit 3c6099a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/poetry/core/masonry/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,10 @@ def _get_archive_mtime() -> int:
try:
return int(source_date_epoch)
except ValueError:
logger.info(
logger.warning(
"SOURCE_DATE_EPOCH environment variable is not an int,"
" using mtime=0"
)
return 0
logger.info(
"SOURCE_DATE_EPOCH environment variable is not set," " using mtime=0"
)
logger.info("SOURCE_DATE_EPOCH environment variable is not set, using mtime=0")
return 0
28 changes: 27 additions & 1 deletion tests/masonry/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@


if TYPE_CHECKING:
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock import MockerFixture

Expand Down Expand Up @@ -702,7 +703,10 @@ def test_split_source() -> None:
assert "" in ns["package_dir"] and "module_b" in ns["package_dir"]


def test_sdist_members_mtime_default() -> None:
def test_sdist_members_mtime_default(caplog: LogCaptureFixture) -> None:
import logging

caplog.set_level(logging.INFO)
poetry = Factory().create_poetry(project("module1"))

builder = SdistBuilder(poetry)
Expand All @@ -716,6 +720,10 @@ def test_sdist_members_mtime_default() -> None:
for tarinfo in tar.getmembers():
assert tarinfo.mtime == 0

assert (
"SOURCE_DATE_EPOCH environment variable is not set," " using mtime=0"
) in caplog.messages


def test_sdist_mtime_set_from_envvar(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setenv("SOURCE_DATE_EPOCH", "1727883000")
Expand All @@ -731,3 +739,21 @@ def test_sdist_mtime_set_from_envvar(monkeypatch: MonkeyPatch) -> None:
with tarfile.open(str(sdist), "r") as tar:
for tarinfo in tar.getmembers():
assert tarinfo.mtime == 1727883000


def test_sdist_mtime_set_from_envvar_not_int(
monkeypatch: MonkeyPatch, caplog: LogCaptureFixture
) -> None:
monkeypatch.setenv("SOURCE_DATE_EPOCH", "october")
poetry = Factory().create_poetry(project("module1"))

builder = SdistBuilder(poetry)
builder.build()

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

assert sdist.exists()

assert (
"SOURCE_DATE_EPOCH environment variable is not an " "int, using mtime=0"
) in caplog.messages

0 comments on commit 3c6099a

Please # to comment.