Skip to content

Commit

Permalink
Update tests for latest hatchling.
Browse files Browse the repository at this point in the history
  • Loading branch information
domdfcoding committed Mar 18, 2024
1 parent 191a2ce commit 1aa21b8
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 76 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/python_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 🛎️
Expand Down
26 changes: 13 additions & 13 deletions .github/workflows/python_ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 🛎️
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/python_ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 🛎️
Expand Down
41 changes: 29 additions & 12 deletions repo_helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -50,3 +62,8 @@ keywords:
entry_points:
hatch:
- requirements_txt = hatch_requirements_txt

third_party_version_matrix:
hatchling:
- 1.21
- latest
53 changes: 53 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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):

Expand All @@ -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):

Expand All @@ -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):

Expand Down
85 changes: 59 additions & 26 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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

0 comments on commit 1aa21b8

Please sign in to comment.