Skip to content

Commit

Permalink
Refactor rules concerning warning vs info in wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Oct 6, 2024
1 parent 3c6099a commit 8f7374b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def _get_zipfile_date_time() -> ZipInfoTimestamp:
try:
_env_date = time.gmtime(int(os.environ["SOURCE_DATE_EPOCH"]))[:6]
except ValueError:
logger.info(
logger.warning(
"SOURCE_DATE_EPOCH environment variable value"
" is not an int, setting zipinfo date to default=%s",
default,
Expand All @@ -517,11 +517,12 @@ def _get_zipfile_date_time() -> ZipInfoTimestamp:
return default
else:
if _env_date[0] < 1980:
logger.info(
logger.warning(
"zipinfo date can't be earlier than 1980,"
" setting zipinfo date to default=%s",
default,
)
return default
return _env_date

def _write_entry_points(self, fp: TextIO) -> None:
Expand Down
79 changes: 63 additions & 16 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


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

fixtures_dir = Path(__file__).parent / "fixtures"
Expand Down Expand Up @@ -489,36 +490,82 @@ def test_generated_script_file(tmp_path: Path) -> None:
assert "generated_script_file-0.1.data/scripts/script.sh" in z.namelist()


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

caplog.set_level(logging.INFO)
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))

whl = module_path / "dist" / "my_package-1.2.3-py3-none-any.whl"

default_date_time = (2016, 1, 1, 0, 0, 0)

with zipfile.ZipFile(str(whl)) as z:
assert z.getinfo("my_package-1.2.3.dist-info/WHEEL").date_time == (
2016,
1,
1,
0,
0,
0,
assert (
z.getinfo("my_package-1.2.3.dist-info/WHEEL").date_time == default_date_time
)

assert (
"SOURCE_DATE_EPOCH environment variable not set,"
f" setting zipinfo date to default={default_date_time}"
) in caplog.messages


def test_dist_info_date_time_value_from_envvar(monkeypatch: MonkeyPatch) -> None:
monkeypatch.setenv("SOURCE_DATE_EPOCH", "1727883000")
expected_date_time = (2024, 10, 2, 15, 30, 0)
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))

whl = module_path / "dist" / "my_package-1.2.3-py3-none-any.whl"

with zipfile.ZipFile(str(whl)) as z:
assert z.getinfo("my_package-1.2.3.dist-info/WHEEL").date_time == (
2024,
10,
2,
15,
30,
0,
assert (
z.getinfo("my_package-1.2.3.dist-info/WHEEL").date_time
== expected_date_time
)


def test_dist_info_date_time_value_from_envvar_not_int(
monkeypatch: MonkeyPatch, caplog: LogCaptureFixture
) -> None:
monkeypatch.setenv("SOURCE_DATE_EPOCH", "october")
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))

whl = module_path / "dist" / "my_package-1.2.3-py3-none-any.whl"

default_date_time = (2016, 1, 1, 0, 0, 0)

with zipfile.ZipFile(str(whl)) as z:
assert (
z.getinfo("my_package-1.2.3.dist-info/WHEEL").date_time == default_date_time
)

assert (
"SOURCE_DATE_EPOCH environment variable value"
f" is not an int, setting zipinfo date to default={default_date_time}"
) in caplog.messages


def test_dist_info_date_time_value_from_envvar_older_than_1980(
monkeypatch: MonkeyPatch, caplog: LogCaptureFixture
) -> None:
monkeypatch.setenv("SOURCE_DATE_EPOCH", "1000")
module_path = fixtures_dir / "complete"
WheelBuilder.make(Factory().create_poetry(module_path))

whl = module_path / "dist" / "my_package-1.2.3-py3-none-any.whl"

default_date_time = (2016, 1, 1, 0, 0, 0)

with zipfile.ZipFile(str(whl)) as z:
assert (
z.getinfo("my_package-1.2.3.dist-info/WHEEL").date_time == default_date_time
)

assert (
"zipinfo date can't be earlier than 1980,"
f" setting zipinfo date to default={default_date_time}"
) in caplog.messages

0 comments on commit 8f7374b

Please # to comment.