From 24960ce00428edb2d8a77a773993ce63b2fe0e04 Mon Sep 17 00:00:00 2001 From: Yuzhong Zhang Date: Thu, 3 Sep 2026 21:36:22 +0000 Subject: [PATCH 1/4] fix: include tests/ (and tox.ini) in the flit sdist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #261 — flit_core sdists omitted the test suite while shipping tox.ini, so distro packagers could not run the project's tests from the PyPI source tarball. Explicitly include tests/ and tox.ini; keep docs/ and benchmarking/ excluded. --- pyproject.toml | 5 +++- .../test_sdist_includes_tests.py | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/test_packaging/test_sdist_includes_tests.py diff --git a/pyproject.toml b/pyproject.toml index 5ddae880..cbafe622 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,9 +81,12 @@ markdown-it = "markdown_it.cli.parse:main" name = "markdown_it" [tool.flit.sdist] +include = [ + "tests/", + "tox.ini", +] exclude = [ "docs/", - "tests/", "benchmarking/" ] diff --git a/tests/test_packaging/test_sdist_includes_tests.py b/tests/test_packaging/test_sdist_includes_tests.py new file mode 100644 index 00000000..6d42a883 --- /dev/null +++ b/tests/test_packaging/test_sdist_includes_tests.py @@ -0,0 +1,25 @@ +"""Regression for https://github.com/executablebooks/markdown-it-py/issues/261.""" + +from __future__ import annotations + +from pathlib import Path + + +def test_flit_sdist_includes_tests_directory() -> None: + """sdist must ship tests/ (and tox.ini) so downstream packagers can run them.""" + text = (Path(__file__).resolve().parents[2] / "pyproject.toml").read_text( + encoding="utf-8" + ) + # Locate the flit sdist table without requiring tomllib (3.10 CI). + start = text.index("[tool.flit.sdist]") + rest = text[start + len("[tool.flit.sdist]") :] + end = rest.find("\n[") + block = rest if end < 0 else rest[:end] + assert 'include = [' in block + assert '"tests/"' in block + assert '"tox.ini"' in block + # Still exclude heavy non-test trees. + assert '"docs/"' in block + assert '"benchmarking/"' in block + # Must not exclude tests anymore. + assert '"tests/"' not in block.split("exclude", 1)[-1] From 4719ce38e523c2712a009a7e75b47d80099a7da6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Sep 2026 21:36:42 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_packaging/test_sdist_includes_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_packaging/test_sdist_includes_tests.py b/tests/test_packaging/test_sdist_includes_tests.py index 6d42a883..f7687cd8 100644 --- a/tests/test_packaging/test_sdist_includes_tests.py +++ b/tests/test_packaging/test_sdist_includes_tests.py @@ -15,7 +15,7 @@ def test_flit_sdist_includes_tests_directory() -> None: rest = text[start + len("[tool.flit.sdist]") :] end = rest.find("\n[") block = rest if end < 0 else rest[:end] - assert 'include = [' in block + assert "include = [" in block assert '"tests/"' in block assert '"tox.ini"' in block # Still exclude heavy non-test trees. From 4e73dfdf803774ff61727f1fc50aa717f1fc3e40 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 9 Sep 2026 12:01:56 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A7=AA=20TEST:=20Assert=20sdist=20con?= =?UTF-8?q?tents=20by=20building=20the=20sdist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the pyproject.toml text-grep with a test that builds the sdist with flit_core and asserts that tests/, tox.ini and the package itself are members of the tarball, and that docs/ and benchmarking/ are not. The test skips when flit_core is unavailable, or when not run from a source checkout. --- .../test_sdist_includes_tests.py | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/test_packaging/test_sdist_includes_tests.py b/tests/test_packaging/test_sdist_includes_tests.py index f7687cd8..b16118a3 100644 --- a/tests/test_packaging/test_sdist_includes_tests.py +++ b/tests/test_packaging/test_sdist_includes_tests.py @@ -3,23 +3,26 @@ from __future__ import annotations from pathlib import Path +import tarfile +import pytest -def test_flit_sdist_includes_tests_directory() -> None: - """sdist must ship tests/ (and tox.ini) so downstream packagers can run them.""" - text = (Path(__file__).resolve().parents[2] / "pyproject.toml").read_text( - encoding="utf-8" - ) - # Locate the flit sdist table without requiring tomllib (3.10 CI). - start = text.index("[tool.flit.sdist]") - rest = text[start + len("[tool.flit.sdist]") :] - end = rest.find("\n[") - block = rest if end < 0 else rest[:end] - assert "include = [" in block - assert '"tests/"' in block - assert '"tox.ini"' in block - # Still exclude heavy non-test trees. - assert '"docs/"' in block - assert '"benchmarking/"' in block - # Must not exclude tests anymore. - assert '"tests/"' not in block.split("exclude", 1)[-1] +ROOT = Path(__file__).resolve().parents[2] + + +def test_sdist_contents(tmp_path: Path) -> None: + """The sdist must ship tests/ and tox.ini, so downstream packagers can run them.""" + flit_sdist = pytest.importorskip("flit_core.sdist") + if not (ROOT / "pyproject.toml").is_file(): + pytest.skip("not running from a source checkout") + + builder = flit_sdist.SdistBuilder.from_ini_path(ROOT / "pyproject.toml") + with tarfile.open(builder.build(tmp_path)) as tar: + # strip the leading `markdown_it-/` component + names = {name.split("/", 1)[1] for name in tar.getnames() if "/" in name} + + assert "markdown_it/__init__.py" in names + assert "tests/test_api/test_main.py" in names + assert "tox.ini" in names + # heavy, non-essential trees are still excluded + assert not [name for name in names if name.startswith(("docs/", "benchmarking/"))] From 1564a2e20acf4c08b7578b2698e38f23d2be5574 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Wed, 9 Sep 2026 12:23:56 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A7=AA=20TEST:=20Make=20the=20sdist?= =?UTF-8?q?=20test=20run=20in=20CI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pip builds the package in an isolated environment, so flit_core was not importable in the test jobs and tests/test_packaging skipped there (CI reported "1000 passed, 1 skipped"). Adding flit_core to the testing extra lets the assertion actually run. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index cbafe622..df44491f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ rtd = [ ] testing = [ "coverage", + "flit_core>=3.4,<5", # lets tests/test_packaging build the sdist "pytest", "pytest-cov", "pytest-regressions",