diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 662dff0c..6a7e9bac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: - name: Install the project run: pip install --no-binary=wheel . - name: Install test dependencies - run: pip install .[test] coverage[toml] + run: pip install .[test] coverage[toml] build flit - name: Test with pytest run: | coverage run -m pytest -W always diff --git a/tests/test_sdist.py b/tests/test_sdist.py new file mode 100644 index 00000000..07df95af --- /dev/null +++ b/tests/test_sdist.py @@ -0,0 +1,48 @@ +import os +import subprocess +import sys +import tarfile +from pathlib import Path + +import pytest + +pytest.importorskip("flit") +pytest.importorskip("build") + +# This test must be run from the source directory - okay to skip if not +DIR = os.path.abspath(os.path.dirname(__file__)) +MAIN_DIR = os.path.dirname(DIR) + + +def test_compare_sdists(monkeypatch, tmpdir): + monkeypatch.chdir(MAIN_DIR) + + sdist_build_dir = os.path.join(str(tmpdir), "bdir") + + subprocess.run( + [ + sys.executable, + "-m", + "build", + "--sdist", + "--no-isolation", + f"--outdir={sdist_build_dir}", + ], + check=True, + ) + + (sdist_build,) = Path(sdist_build_dir).glob("*.tar.gz") + + # Flit doesn't allow targeting directories, as far as I can tell + subprocess.run( + [sys.executable, "-m", "flit", "build", "--format=sdist"], check=True + ) + + (sdist_flit,) = Path("dist").glob("*.tar.gz") + + out = [set(), set()] + for i, sdist in enumerate([sdist_build, sdist_flit]): + with tarfile.open(str(sdist), "r:gz") as tar: + out[i] = set(tar.getnames()) + + assert out[0] == (out[1] - {"setup.py"}) diff --git a/tox.ini b/tox.ini index e7283981..ba6bdb15 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py37, py38, py39, py310, py311, pypy3, lint +envlist = py37, py38, py39, py310, py311, pypy3, lint, pkg minversion = 3.3.0 skip_missing_interpreters = true isolated_build = true @@ -20,3 +20,10 @@ basepython = python3 deps = pre-commit commands = pre-commit run --all-files --show-diff-on-failure skip_install = true + +[testenv:pkg] +basepython = python3 +deps = + build + flit +commands = {envpython} -b -m pytest tests/test_sdist.py {posargs}