From 5753c6b3bf62fbcb5e9dd645e4e1c66d9140c426 Mon Sep 17 00:00:00 2001 From: tongwentao Date: Thu, 22 Oct 2026 22:10:58 +0800 Subject: [PATCH 1/3] fix: print results when running ulid as a module --- CHANGELOG.rst | 8 ++++++++ tests/test_cli.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ ulid/__main__.py | 6 +++--- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e353870..9736b66 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,14 @@ Changelog Versions follow `Semantic Versioning `_ +Unreleased +---------- + +Fixed +~~~~~ +* Print generated and converted values when using ``python -m ulid``, matching the + ``ulid`` console command. + `4.0.1`_ - 2026-07-20 --------------------- Changed diff --git a/tests/test_cli.py b/tests/test_cli.py index 48984df..73af0ba 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,6 @@ +import subprocess +import sys + import pytest import ulid.__main__ as cli @@ -79,3 +82,49 @@ def test_build(option: str): ulid_out = ULID.from_str(output) if includes_timestamp: assert ulid_out.datetime == ulid.datetime + + +@pytest.mark.parametrize( + ("args", "stdin", "expected"), + [ + (["build", "--from-int", "0"], None, "00000000000000000000000000\n"), + (["build", "--from-int", "-"], "0\n", "00000000000000000000000000\n"), + (["show", "--int", "00000000000000000000000000"], None, "0\n"), + (["show", "--int", "-"], "00000000000000000000000000\n", "0\n"), + ], +) +def test_module_outputs_result(args: list[str], stdin: str | None, expected: str) -> None: + result = subprocess.run( + [sys.executable, "-m", "ulid", *args], + input=stdin, + capture_output=True, + text=True, + check=True, + timeout=10, + ) + assert result.stdout == expected + assert result.stderr == "" + + +@pytest.mark.parametrize("args", [[], ["--help"]]) +def test_module_help(args: list[str]) -> None: + result = subprocess.run( + [sys.executable, "-m", "ulid", *args], + capture_output=True, + text=True, + check=True, + timeout=10, + ) + assert result.stdout.startswith("usage: python -m ulid") + assert not result.stdout.endswith("None\n") + assert result.stderr == "" + + +def test_console_entrypoint( + monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str] +) -> None: + monkeypatch.setattr(sys, "argv", ["ulid", "build", "--from-int", "0"]) + cli.entrypoint() + captured = capsys.readouterr() + assert captured.out == "00000000000000000000000000\n" + assert captured.err == "" diff --git a/ulid/__main__.py b/ulid/__main__.py index 2c10bef..fc25d43 100644 --- a/ulid/__main__.py +++ b/ulid/__main__.py @@ -163,10 +163,10 @@ def show(args: argparse.Namespace) -> str: ).strip() -def entrypoint() -> None: # pragma: no cover - if (value := main(sys.argv[1:])) is not None: +def entrypoint(prog: str | None = None) -> None: # pragma: no cover + if (value := main(sys.argv[1:], prog)) is not None: print(value) # noqa: T201 if __name__ == "__main__": # pragma: no cover - main(sys.argv[1:], "python -m ulid") + entrypoint("python -m ulid") From 5649c3236b969101543a3fdb81bf70f7105e6e75 Mon Sep 17 00:00:00 2001 From: tongwentao Date: Sat, 24 Oct 2026 10:19:39 +0800 Subject: [PATCH 2/3] build: keep distribution metadata compatible with package checks --- CHANGELOG.rst | 2 ++ pyproject.toml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9736b66..4a99e88 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,8 @@ Fixed ~~~~~ * Print generated and converted values when using ``python -m ulid``, matching the ``ulid`` console command. +* Build distributions with core metadata 2.4, keeping them compatible with the + package validation tools used in CI. `4.0.1`_ - 2026-07-20 --------------------- diff --git a/pyproject.toml b/pyproject.toml index 1574860..318679a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,10 +50,12 @@ ulid = "ulid.__main__:entrypoint" source = "vcs" [tool.hatch.build.targets.wheel] +core-metadata-version = "2.4" packages = [ "ulid", ] [tool.hatch.build.targets.sdist] +core-metadata-version = "2.4" exclude = [ ".flox", ] From 0f618f9c197ef6172bb404295db49295d7a8bcd8 Mon Sep 17 00:00:00 2001 From: tongwentao Date: Tue, 27 Oct 2026 15:04:16 +0800 Subject: [PATCH 3/3] build: remove obsolete core metadata overrides --- pyproject.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 64a9b5b..bc16c83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,12 +49,10 @@ ulid = "ulid.__main__:entrypoint" source = "vcs" [tool.hatch.build.targets.wheel] -core-metadata-version = "2.4" packages = [ "ulid", ] [tool.hatch.build.targets.sdist] -core-metadata-version = "2.4" exclude = [ ".flox", ]