From 1aa21b86db3503ed46683fa7af748d7aa1e853e1 Mon Sep 17 00:00:00 2001 From: Dominic Davis-Foster Date: Mon, 18 Mar 2024 16:24:57 +0000 Subject: [PATCH] Update tests for latest hatchling. --- .github/workflows/python_ci.yml | 26 ++++---- .github/workflows/python_ci_linux.yml | 26 ++++---- .github/workflows/python_ci_macos.yml | 24 ++++---- repo_helper.yml | 41 +++++++++---- tests/test_errors.py | 53 +++++++++++++++++ tox.ini | 85 +++++++++++++++++++-------- 6 files changed, 179 insertions(+), 76 deletions(-) diff --git a/.github/workflows/python_ci.yml b/.github/workflows/python_ci.yml index f250e6a..2630064 100644 --- a/.github/workflows/python_ci.yml +++ b/.github/workflows/python_ci.yml @@ -22,24 +22,24 @@ jobs: runs-on: "windows-2019" continue-on-error: ${{ matrix.config.experimental }} env: - USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10,3.11,3.12,3.13.0-alpha.4,pypy-3.6,pypy-3.7,pypy-3.8,pypy-3.9' + USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10,3.11,3.12,3.13.0-alpha.5,pypy-3.6,pypy-3.7,pypy-3.8,pypy-3.9' strategy: fail-fast: False matrix: config: - - {python-version: "3.6", testenvs: "py36,build", experimental: False} - - {python-version: "3.7", testenvs: "py37,build", experimental: False} - - {python-version: "3.8", testenvs: "py38,build", experimental: False} - - {python-version: "3.9", testenvs: "py39,build", experimental: False} - - {python-version: "3.10", testenvs: "py310,build", experimental: False} - - {python-version: "3.11", testenvs: "py311,build", experimental: False} - - {python-version: "3.12", testenvs: "py312,build", experimental: False} - - {python-version: "3.13.0-alpha.4", testenvs: "py313-dev,build", experimental: True} - - {python-version: "pypy-3.6", testenvs: "pypy36", experimental: False} - - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False} - - {python-version: "pypy-3.8", testenvs: "pypy38,build", experimental: False} - - {python-version: "pypy-3.9", testenvs: "pypy39,build", experimental: True} + - {python-version: "3.6", testenvs: "py36-hatchlinglatest,build", experimental: False} + - {python-version: "3.7", testenvs: "py37-hatchlinglatest,build", experimental: False} + - {python-version: "3.8", testenvs: "py38-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.9", testenvs: "py39-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.10", testenvs: "py310-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.11", testenvs: "py311-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.12", testenvs: "py312-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.13.0-alpha.5", testenvs: "py313-dev-hatchling{1.21,latest},build", experimental: True} + - {python-version: "pypy-3.6", testenvs: "pypy36-hatchlinglatest", experimental: False} + - {python-version: "pypy-3.7", testenvs: "pypy37-hatchlinglatest,build", experimental: False} + - {python-version: "pypy-3.8", testenvs: "pypy38-hatchling{1.21,latest},build", experimental: False} + - {python-version: "pypy-3.9", testenvs: "pypy39-hatchling{1.21,latest},build", experimental: True} steps: - name: Checkout 🛎️ diff --git a/.github/workflows/python_ci_linux.yml b/.github/workflows/python_ci_linux.yml index e6919f5..1c42ae4 100644 --- a/.github/workflows/python_ci_linux.yml +++ b/.github/workflows/python_ci_linux.yml @@ -23,24 +23,24 @@ jobs: runs-on: "ubuntu-20.04" continue-on-error: ${{ matrix.config.experimental }} env: - USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10,3.11,3.12,3.13.0-alpha.4,pypy-3.6,pypy-3.7,pypy-3.8,pypy-3.9' + USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10,3.11,3.12,3.13.0-alpha.5,pypy-3.6,pypy-3.7,pypy-3.8,pypy-3.9' strategy: fail-fast: False matrix: config: - - {python-version: "3.6", testenvs: "py36,build", experimental: False} - - {python-version: "3.7", testenvs: "py37,build", experimental: False} - - {python-version: "3.8", testenvs: "py38,build", experimental: False} - - {python-version: "3.9", testenvs: "py39,build", experimental: False} - - {python-version: "3.10", testenvs: "py310,build", experimental: False} - - {python-version: "3.11", testenvs: "py311,build", experimental: False} - - {python-version: "3.12", testenvs: "py312,build", experimental: False} - - {python-version: "3.13.0-alpha.4", testenvs: "py313-dev,build", experimental: True} - - {python-version: "pypy-3.6", testenvs: "pypy36,build", experimental: False} - - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False} - - {python-version: "pypy-3.8", testenvs: "pypy38,build", experimental: False} - - {python-version: "pypy-3.9", testenvs: "pypy39,build", experimental: True} + - {python-version: "3.6", testenvs: "py36-hatchlinglatest,build", experimental: False} + - {python-version: "3.7", testenvs: "py37-hatchlinglatest,build", experimental: False} + - {python-version: "3.8", testenvs: "py38-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.9", testenvs: "py39-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.10", testenvs: "py310-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.11", testenvs: "py311-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.12", testenvs: "py312-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.13.0-alpha.5", testenvs: "py313-dev-hatchling{1.21,latest},build", experimental: True} + - {python-version: "pypy-3.6", testenvs: "pypy36-hatchlinglatest,build", experimental: False} + - {python-version: "pypy-3.7", testenvs: "pypy37-hatchlinglatest,build", experimental: False} + - {python-version: "pypy-3.8", testenvs: "pypy38-hatchling{1.21,latest},build", experimental: False} + - {python-version: "pypy-3.9", testenvs: "pypy39-hatchling{1.21,latest},build", experimental: True} steps: - name: Checkout 🛎️ diff --git a/.github/workflows/python_ci_macos.yml b/.github/workflows/python_ci_macos.yml index 906a585..fad76cb 100644 --- a/.github/workflows/python_ci_macos.yml +++ b/.github/workflows/python_ci_macos.yml @@ -22,23 +22,23 @@ jobs: runs-on: "macos-latest" continue-on-error: ${{ matrix.config.experimental }} env: - USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10,3.11,3.12,3.13.0-alpha.4,pypy-3.7,pypy-3.8,pypy-3.9' + USING_COVERAGE: '3.6,3.7,3.8,3.9,3.10,3.11,3.12,3.13.0-alpha.5,pypy-3.7,pypy-3.8,pypy-3.9' strategy: fail-fast: False matrix: config: - - {python-version: "3.6", testenvs: "py36,build", experimental: False} - - {python-version: "3.7", testenvs: "py37,build", experimental: False} - - {python-version: "3.8", testenvs: "py38,build", experimental: False} - - {python-version: "3.9", testenvs: "py39,build", experimental: False} - - {python-version: "3.10", testenvs: "py310,build", experimental: False} - - {python-version: "3.11", testenvs: "py311,build", experimental: False} - - {python-version: "3.12", testenvs: "py312,build", experimental: False} - - {python-version: "3.13.0-alpha.4", testenvs: "py313-dev,build", experimental: True} - - {python-version: "pypy-3.7", testenvs: "pypy37,build", experimental: False} - - {python-version: "pypy-3.8", testenvs: "pypy38,build", experimental: False} - - {python-version: "pypy-3.9", testenvs: "pypy39,build", experimental: True} + - {python-version: "3.6", testenvs: "py36-hatchlinglatest,build", experimental: False} + - {python-version: "3.7", testenvs: "py37-hatchlinglatest,build", experimental: False} + - {python-version: "3.8", testenvs: "py38-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.9", testenvs: "py39-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.10", testenvs: "py310-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.11", testenvs: "py311-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.12", testenvs: "py312-hatchling{1.21,latest},build", experimental: False} + - {python-version: "3.13.0-alpha.5", testenvs: "py313-dev-hatchling{1.21,latest},build", experimental: True} + - {python-version: "pypy-3.7", testenvs: "pypy37-hatchlinglatest,build", experimental: False} + - {python-version: "pypy-3.8", testenvs: "pypy38-hatchling{1.21,latest},build", experimental: False} + - {python-version: "pypy-3.9", testenvs: "pypy39-hatchling{1.21,latest},build", experimental: True} steps: - name: Checkout 🛎️ diff --git a/repo_helper.yml b/repo_helper.yml index 89ad7fd..235469c 100644 --- a/repo_helper.yml +++ b/repo_helper.yml @@ -22,18 +22,30 @@ conda_channels: # Versions to run tests for python_versions: - - '3.6' - - '3.7' - - '3.8' - - '3.9' - - "3.10" - - "3.11" - - "3.12" - - 3.13-dev - - pypy36 - - pypy37 - - pypy38 - - pypy39 + '3.6': + matrix_exclude: + hatchling: + - 1.21 + '3.7': + matrix_exclude: + hatchling: + - 1.21 + '3.8': + '3.9': + "3.10": + "3.11": + "3.12": + 3.13-dev: + pypy36: + matrix_exclude: + hatchling: + - 1.21 + pypy37: + matrix_exclude: + hatchling: + - 1.21 + pypy38: + pypy39: classifiers: - 'Development Status :: 4 - Beta' @@ -50,3 +62,8 @@ keywords: entry_points: hatch: - requirements_txt = hatch_requirements_txt + +third_party_version_matrix: + hatchling: + - 1.21 + - latest diff --git a/tests/test_errors.py b/tests/test_errors.py index f470ec0..56a58f3 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -3,9 +3,14 @@ # 3rd party import pytest +from domdf_python_tools.compat import importlib_metadata from domdf_python_tools.paths import PathPlus, in_directory from hatchling.build import build_sdist, build_wheel from packaging.requirements import InvalidRequirement +from packaging.version import Version + +_hatchling_version = Version(importlib_metadata.version("hatchling")) +hatchling_version = (_hatchling_version.major, _hatchling_version.minor) pyproject_toml = """ [project] @@ -66,6 +71,7 @@ def test_missing_invalid_requirements(tmp_pathplus: PathPlus, build_func: Callab wheel_file = build_func(dist_dir) +@pytest.mark.xfail(hatchling_version >= (1, 22), reason="Metadata hooks no longer called if dynamic not set") @pytest.mark.parametrize("build_func", [build_wheel, build_sdist]) def test_not_dynamic_but_files_defined(tmp_pathplus: PathPlus, build_func: Callable): @@ -86,6 +92,29 @@ def test_not_dynamic_but_files_defined(tmp_pathplus: PathPlus, build_func: Calla wheel_file = build_func(dist_dir) +@pytest.mark.parametrize("build_func", [build_wheel, build_sdist]) +def test_not_in_dynamic_but_files_defined(tmp_pathplus: PathPlus, build_func: Callable): + + dist_dir = tmp_pathplus / "dist" + dist_dir.maybe_make() + + (tmp_pathplus / "pyproject.toml").write_clean( + pyproject_toml.replace('dynamic = ["dependencies"]', 'dynamic = ["classifiers"]') + ) + (tmp_pathplus / "requirements.txt").write_lines(["Foo", "bar", "# fizz", "baz>1"]) + (tmp_pathplus / "README.md").touch() + (tmp_pathplus / "LICENSE").touch() + (tmp_pathplus / "demo").maybe_make() + (tmp_pathplus / "demo" / "__init__.py").touch() + + with in_directory(tmp_pathplus), pytest.raises(ValueError, match=( + r"^Cannot specify 'files' in \[tool.hatch.metadata.hooks.requirements_txt\] " + r"when 'dependencies' is not listed in 'project.dynamic'.$" + )): + wheel_file = build_func(dist_dir) + + +@pytest.mark.xfail(hatchling_version >= (1, 22), reason="Metadata hooks no longer called if dynamic not set") @pytest.mark.parametrize("build_func", [build_wheel, build_sdist]) def test_not_dynamic_but_filename_defined(tmp_pathplus: PathPlus, build_func: Callable): @@ -109,6 +138,30 @@ def test_not_dynamic_but_filename_defined(tmp_pathplus: PathPlus, build_func: Ca build_func(dist_dir) +@pytest.mark.xfail(hatchling_version >= (1, 22), reason="Metadata hooks no longer called if dynamic not set") +@pytest.mark.parametrize("build_func", [build_wheel, build_sdist]) +def test_not_in_dynamic_but_filename_defined(tmp_pathplus: PathPlus, build_func: Callable): + + dist_dir = tmp_pathplus / "dist" + dist_dir.maybe_make() + + new_pyproject_toml = pyproject_toml.replace('dynamic = ["dependencies"]', 'dynamic = ["classifiers"]').replace( + 'files = ["requirements.txt"]', 'filename = "requirements.txt"' + ) + (tmp_pathplus / "pyproject.toml").write_clean(new_pyproject_toml) + (tmp_pathplus / "requirements.txt").write_lines(["Foo", "bar", "# fizz", "baz>1"]) + (tmp_pathplus / "README.md").touch() + (tmp_pathplus / "LICENSE").touch() + (tmp_pathplus / "demo").maybe_make() + (tmp_pathplus / "demo" / "__init__.py").touch() + + with in_directory(tmp_pathplus), pytest.raises(ValueError, match=( + r"^Cannot specify 'filename' in \[tool.hatch.metadata.hooks.requirements_txt\] " + r"when 'dependencies' is not listed in 'project.dynamic'.$" + )): + build_func(dist_dir) + + @pytest.mark.parametrize("build_func", [build_wheel, build_sdist]) def test_optional_not_dynamic(tmp_pathplus: PathPlus, build_func: Callable): diff --git a/tox.ini b/tox.ini index b1f5482..0e7ba76 100644 --- a/tox.ini +++ b/tox.ini @@ -22,18 +22,18 @@ [tox] envlist = - py36 - py37 - py38 - py39 - py310 - py311 - py312 - py313-dev - pypy36 - pypy37 - pypy38 - pypy39 + py36-hatchlinglatest + py37-hatchlinglatest + py38-hatchling{1.21,latest} + py39-hatchling{1.21,latest} + py310-hatchling{1.21,latest} + py311-hatchling{1.21,latest} + py312-hatchling{1.21,latest} + py313-dev-hatchling{1.21,latest} + pypy36-hatchlinglatest + pypy37-hatchlinglatest + pypy38-hatchling{1.21,latest} + pypy39-hatchling{1.21,latest} mypy build skip_missing_interpreters = True @@ -46,27 +46,30 @@ requires = [envlists] test = - py36 - py37 - py38 - py39 - py310 - py311 - py312 - py313-dev - pypy36 - pypy37 - pypy38 - pypy39 + py36-hatchlinglatest + py37-hatchlinglatest + py38-hatchling{1.21,latest} + py39-hatchling{1.21,latest} + py310-hatchling{1.21,latest} + py311-hatchling{1.21,latest} + py312-hatchling{1.21,latest} + py313-dev-hatchling{1.21,latest} + pypy36-hatchlinglatest + pypy37-hatchlinglatest + pypy38-hatchling{1.21,latest} + pypy39-hatchling{1.21,latest} qa = mypy, lint -cov = py37, coverage +cov = py37-hatchlinglatest, coverage [testenv] setenv = PYTHONDEVMODE=1 PIP_DISABLE_PIP_VERSION_CHECK=1 SETUPTOOLS_USE_DISTUTILS=stdlib -deps = -r{toxinidir}/tests/requirements.txt +deps = + -r{toxinidir}/tests/requirements.txt + hatchling1.21: hatchling~=1.21.0 + hatchlinglatest: hatchling commands = python --version python -m pytest --cov=hatch_requirements_txt -r aR tests/ {posargs} @@ -228,3 +231,33 @@ timeout = 300 filterwarnings = error ignore:can't resolve package from __spec__ or __package__, falling back on __name__ and __path__:ImportWarning + +[testenv:py312-hatchling{1.21,latest}] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + +[testenv:py313-dev-hatchling{1.21,latest}] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + +[testenv:py312-hatchling{1.21.1,latest}] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + +[testenv:py313-dev-hatchling{1.21.1,latest}] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + +[testenv:py312-hatchling{0.21.0,1.21.1,latest}] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1 + +[testenv:py313-dev-hatchling{0.21.0,1.21.1,latest}] +setenv = + PYTHONDEVMODE=1 + PIP_DISABLE_PIP_VERSION_CHECK=1