Skip to content

Commit

Permalink
build: add tox
Browse files Browse the repository at this point in the history
  • Loading branch information
GabDug committed Apr 1, 2024
1 parent ba72a74 commit 91b84ba
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 33 deletions.
26 changes: 8 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
# Empty is latest, head is latest from GitHub
pdm-version: ["", "head", "2.7.4", "2.8.2", "2.9.3", "2.10.4", "2.11.2", "2.12.2"]
pdm-version: [""]

steps:
- uses: actions/checkout@v4
Expand All @@ -30,13 +30,12 @@ jobs:
with:
cache: true
python-version: ${{ matrix.python-version }} # Version range or exact version of a Python version to use, the same as actions/setup-python
architecture: x64 # The target architecture (x86, x64) of the Python interpreter. the same as actions/setup-python
version: ${{ matrix.pdm-version }} # The version of PDM to install. Leave it as empty to use the latest version from PyPI, or 'head' to use the latest version from GitHub
prerelease: true # Allow prerelease versions of PDM to be installed
enable-pep582: false # Enable PEP 582 package loading globally
allow-python-prereleases: true # Allow prerelease versions of Python to be installed. For example if only 3.12-dev is available, 3.12 will fall back to 3.12-dev
- name: Set Cache Variables
id: set_variables
shell: bash
run: |
echo "PIP_CACHE=$(pip cache dir)" >> $GITHUB_OUTPUT
echo "PDM_CACHE=$(pdm config cache_dir)" >> $GITHUB_OUTPUT
Expand All @@ -50,24 +49,11 @@ jobs:

- name: Install dependencies
run: |
pdm config venv.with_pip True
pdm install -G :all --dev
pdm venv activate in-project
source .venv/bin/activate
# Get the pip command to run depending on matrix.pdm-version
# We force reinstall of pdm in the virtualenv
if [[ "${{ matrix.pdm-version }}" == "head" ]]; then
pip install "pdm @ git+https://github.com/pdm-project/pdm"
elif [[ "${{ matrix.pdm-version }}" == "" ]]; then
pip install pdm
else
pip install pdm==${{ matrix.pdm-version }}
fi
- name: Run Test with tox
run: pdm run tox

- name: Test with pytest
run: |
pdm run test-cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand All @@ -86,3 +72,7 @@ jobs:
pdm build
# Do not upload to PyPI, here we only want to check that the build works
# XXX Check valid wheels?


- name: Check Python package
uses: hynek/build-and-inspect-python-package@v2
101 changes: 92 additions & 9 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dynamic = [
dependencies = [
"strictyaml>=1.7.3",
'tomli>=2; python_version < "3.11"',
'typing-extensions; python_version < "3.10"',
]
[project.optional-dependencies]
pdm = [
Expand Down Expand Up @@ -69,7 +70,7 @@ test-cov = {cmd="pytest --junitxml=junit/test-results.xml --cov --cov-report=xml

[tool.pdm.dev-dependencies]
dev = [
"PyYAML>=6.0",
"PyYAML>=6.0.1",
"mypy>=1.4.1",
"ruff>=0.0.275",
"types-PyYAML>=6.0.12.10",
Expand All @@ -78,6 +79,15 @@ dev = [
"pytest-cov>=4.1.0",
"pre-commit>=3.3.3",
"tomli>=2.0.1",
"tox-gh>=1.3.1",
"tox-pdm>=0.7.2",
"tox>=4.14.2",
]
testtox = [
"pytest>=8.1.1",
"pytest-cov>=5.0.0",
"pytest-mock>=3.14.0",
"PyYAML>=6.0.1",
]

[tool.ruff]
Expand All @@ -93,14 +103,20 @@ minversion = "7.0"
testpaths = ["tests"]
norecursedirs = "*.egg .eggs dist build docs .tox .git __pycache__ node_modules .venv __pypackages__"

[tool.coverage.paths]
source =[
"src"
]
[tool.coverage.run]
branch = true
parallel = true
include = ["src/*"]
omit = ["*/tests/*"]
source = ["src", "tests"]

[tool.coverage.report]
fail_under = 92.0

show_missing = true
precision = 2
exclude_lines = [
"def __repr__",
"if TYPE_CHECKING:",
Expand Down
11 changes: 8 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
pytest_plugins = [
"pdm.pytest",
]
try:
import pdm # noqa: F401
except ImportError:
pass
else:
pytest_plugins = [
"pdm.pytest",
]
3 changes: 3 additions & 0 deletions tests/test_pdm/test_pdm_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from unittest import mock

import pytest

pdm_module = pytest.importorskip("pdm")
# ruff: noqa: E402
from pdm.cli.hooks import HookManager
from pdm.core import Core
from pdm.models.candidates import Candidate
Expand Down
3 changes: 3 additions & 0 deletions tests/test_pdm/test_pdm_sync_pre_commit_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from unittest.mock import MagicMock, patch

import pytest

pdm_module = pytest.importorskip("pdm")
# ruff: noqa: E402
from pdm.core import Core
from pdm.models.candidates import Candidate
from pdm.models.requirements import NamedRequirement
Expand Down
3 changes: 3 additions & 0 deletions tests/test_poetry/test_poetry_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from unittest.mock import MagicMock, patch

import pytest

poetry_module = pytest.importorskip("poetry")
# ruff: noqa: E402
from cleo.events.console_terminate_event import ConsoleTerminateEvent
from poetry.console.application import Application
from poetry.console.commands.install import InstallCommand
Expand Down
67 changes: 67 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[tox]
requires =
tox>=4.2
env_list =
report
clean
py{312, 311, 310, 39}-pdm{213, 212, 211, 210, 29, 28, 27}
py{312, 311, 310, 39}-poetry{17, 16}

[testenv]
set_env =
py{39,310,311,312}-pdm{27,28,29,210,211,212,213}: COVERAGE_FILE = .coverage.{envname}
py{39,310,311,312}-poetry{16, 17}: COVERAGE_FILE = .coverage.{envname}
commands =
pytest --cov --cov-append --cov-report=term-missing {posargs:-vv} --cov-config=pyproject.toml
depends =
report: py{312, 311, 310, 39}-pdm{213, 212, 211, 210, 29, 28, 27}
py{312, 311, 310, 39}-poetry{17, 16}
py{312, 311, 310, 39}-pdm{213, 212, 211, 210, 29, 28, 27}: clean
py{312, 311, 310, 39}-poetry{17, 16}: clean

[testenv:report]
skip_install = true
commands =
coverage combine
coverage report
coverage html
coverage xml
groups =
testtox

[testenv:clean]
skip_install = true
commands =
coverage erase
groups =
testtox

[testenv:py{39,310,311,312}-pdm{27,28,29,210,211,212,213}]
package = editable
deps =
pdm210: pdm<2.11,>=2.10
pdm211: pdm<2.12,>=2.11
pdm212: pdm<2.13,>=2.12
pdm213: pdm<2.14,>=2.13.2
pdm27: pdm<2.8,>=2.7
pdm28: pdm<2.9,>=2.8
pdm29: pdm<2.10,>=2.9
groups =
testtox

[testenv:py{312, 311, 310, 39}-poetry{16, 17, 18}]
package = editable
deps =
poetry16: poetry<1.7,>=1.6
poetry17: poetry<1.8,>=1.7
poetry18: poetry<1.9,>=1.8
groups =
testtox

[gh]
python =
3.9= py39-pdm{27,28,29,210,211,212,213},py39-poetry{16, 17, 18}, report, clean
3.10= py310-pdm{27,28,29,210,211,212,213}, py310-poetry{16, 17, 18}, report, clean
3.11= py311-pdm{27,28,29,210,211,212,213}, py311-poetry{16, 17, 18}, report, clean
3.12= py312-pdm{27,28,29,210,211,212,213}, py312-poetry{16, 17, 18}, report, clean
fail_on_no_env = True

0 comments on commit 91b84ba

Please sign in to comment.