From d7aeec665a95407872bc7975a114b69474118399 Mon Sep 17 00:00:00 2001 From: Gabriel Dugny Date: Mon, 1 Apr 2024 13:14:44 +0200 Subject: [PATCH] build: move to tox (#29) * chore: add pre-commits * build: add tox * build: test macos and Windows * chore: test tox-uv * chore: move tox-uv * chore: fixup --- .github/workflows/ci.yml | 36 ++-- .gitignore | 1 + .pre-commit-config.yaml | 29 ++++ .tool-versions | 4 +- pdm.lock | 155 ++++++++++++++++-- pyproject.toml | 111 +++++++------ scripts/db_md.py | 2 +- src/sync_pre_commit_lock/config.py | 4 +- tests/conftest.py | 11 +- tests/fixtures/poetry_project/pyproject.toml | 4 +- tests/test_pdm/test_pdm_plugin.py | 3 + .../test_pdm/test_pdm_sync_pre_commit_hook.py | 3 + tests/test_poetry/test_poetry_plugin.py | 3 + tox.ini | 70 ++++++++ 14 files changed, 345 insertions(+), 91 deletions(-) create mode 100644 tox.ini diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 516cf99..cde8a84 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,15 @@ 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: [""] + os: [ubuntu-latest] + include: + - os: macOS-latest + python-version: '3.12' + pdm-version: "" + - os: windows-latest + python-version: '3.12' + pdm-version: "" steps: - uses: actions/checkout@v4 @@ -30,13 +38,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 @@ -50,24 +57,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: @@ -86,3 +80,9 @@ 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 + with: + upload-name-suffix: -${{ matrix.python-version }}-${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 2f1b035..b600e1d 100644 --- a/.gitignore +++ b/.gitignore @@ -163,3 +163,4 @@ cython_debug/ junit .pdm-build src/sync_pre_commit_lock/_version.py +requirements-tox.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ebd585b..f73aa0e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,29 @@ repos: - id: check-merge-conflict - id: fix-byte-order-marker + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.0 + hooks: + - id: check-github-workflows + args: ["--verbose"] + + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + args: ["--write-changes", "--skip=pdm.lock"] + + - repo: https://github.com/tox-dev/tox-ini-fmt + rev: "1.3.1" + hooks: + - id: tox-ini-fmt + + - repo: https://github.com/tox-dev/pyproject-fmt + rev: "1.7.0" + hooks: + - id: pyproject-fmt + additional_dependencies: ["tox>=4.14.1"] + - repo: local hooks: - id: export-supported-packages-to-readme @@ -28,3 +51,9 @@ repos: hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + - repo: https://github.com/pdm-project/pdm + rev: 2.13.2 + hooks: + - id: pdm-lock-check diff --git a/.tool-versions b/.tool-versions index adba6f9..85c75d3 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -pdm 2.12.2 -python 3.12.1 +pdm 2.13.2 +python 3.12.2 3.11.8 3.10.13 3.9.18 diff --git a/pdm.lock b/pdm.lock index 2fdaa7f..d1a1e0d 100644 --- a/pdm.lock +++ b/pdm.lock @@ -2,10 +2,10 @@ # It is not intended for manual editing. [metadata] -groups = ["default", "dev", "pdm", "poetry"] +groups = ["default", "dev", "pdm", "poetry", "testtox"] strategy = ["cross_platform"] lock_version = "4.4.1" -content_hash = "sha256:5a8a58b218ffd5101ab2236628fbf64cf9cd2e56e505a084336c7ee2b1547007" +content_hash = "sha256:383f100ac3c0fe151ab6d27f4239d2c4dcabe9bcb6d004181a66885e9adc656b" [[package]] name = "anyio" @@ -79,6 +79,16 @@ files = [ {file = "cachecontrol-0.14.0.tar.gz", hash = "sha256:7db1195b41c81f8274a7bbd97c956f44e8348265a1bc7641c37dfebc39f0c938"}, ] +[[package]] +name = "cachetools" +version = "5.3.3" +requires_python = ">=3.7" +summary = "Extensible memoizing collections and decorators" +files = [ + {file = "cachetools-5.3.3-py3-none-any.whl", hash = "sha256:0abad1021d3f8325b2fc1d2e9c8b9c9d57b04c3932657a72465447332c24d945"}, + {file = "cachetools-5.3.3.tar.gz", hash = "sha256:ba29e2dfa0b8b556606f097407ed1aa62080ee108ab0dc5ec9d6a723a007d105"}, +] + [[package]] name = "certifi" version = "2024.2.2" @@ -154,6 +164,16 @@ files = [ {file = "cfgv-3.4.0.tar.gz", hash = "sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560"}, ] +[[package]] +name = "chardet" +version = "5.2.0" +requires_python = ">=3.7" +summary = "Universal encoding detector for Python 3" +files = [ + {file = "chardet-5.2.0-py3-none-any.whl", hash = "sha256:e1cf59446890a00105fe7b7912492ea04b6e6f06d4b742b2c788469e34c82970"}, + {file = "chardet-5.2.0.tar.gz", hash = "sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7"}, +] + [[package]] name = "charset-normalizer" version = "3.3.2" @@ -659,15 +679,15 @@ files = [ [[package]] name = "jaraco-classes" -version = "3.3.1" +version = "3.4.0" requires_python = ">=3.8" summary = "Utility functions for Python class constructs" dependencies = [ "more-itertools", ] files = [ - {file = "jaraco.classes-3.3.1-py3-none-any.whl", hash = "sha256:86b534de565381f6b3c1c830d13f931d7be1a75f0081c57dff615578676e2206"}, - {file = "jaraco.classes-3.3.1.tar.gz", hash = "sha256:cb28a5ebda8bc47d8c8015307d93163464f9f2b91ab4006e09ff0ce07e8bfb30"}, + {file = "jaraco.classes-3.4.0-py3-none-any.whl", hash = "sha256:f662826b6bed8cace05e7ff873ce0f9283b5c924470fe664fff1c2f00f581790"}, + {file = "jaraco.classes-3.4.0.tar.gz", hash = "sha256:47a024b51d0239c0dd8c8540c6c7f484be3b8fcf0b2d85c13825780d3b3f3acd"}, ] [[package]] @@ -853,27 +873,27 @@ files = [ [[package]] name = "pbs-installer" -version = "2024.3.27" +version = "2024.4.1" requires_python = ">=3.8" summary = "Installer for Python Build Standalone" files = [ - {file = "pbs_installer-2024.3.27-py3-none-any.whl", hash = "sha256:6299ca01a91cc87033fa4176106a977da16e2484b4094ef4bacb576f822c0392"}, - {file = "pbs_installer-2024.3.27.tar.gz", hash = "sha256:30a368d14710a5e38a57401006b4c1061f030ed06d42d69c8f5e8dd20ee25d58"}, + {file = "pbs_installer-2024.4.1-py3-none-any.whl", hash = "sha256:762e1b5b95a48389051205c48fcd4635e946b48ab3252d2c79a8a77dc87e91ff"}, + {file = "pbs_installer-2024.4.1.tar.gz", hash = "sha256:1f2aca82511fb9e1973b14708d7386780a8c56d111b680ae5786b3f430fa918a"}, ] [[package]] name = "pbs-installer" -version = "2024.3.27" +version = "2024.4.1" extras = ["install"] requires_python = ">=3.8" summary = "Installer for Python Build Standalone" dependencies = [ - "pbs-installer==2024.3.27", + "pbs-installer==2024.4.1", "zstandard>=0.21.0", ] files = [ - {file = "pbs_installer-2024.3.27-py3-none-any.whl", hash = "sha256:6299ca01a91cc87033fa4176106a977da16e2484b4094ef4bacb576f822c0392"}, - {file = "pbs_installer-2024.3.27.tar.gz", hash = "sha256:30a368d14710a5e38a57401006b4c1061f030ed06d42d69c8f5e8dd20ee25d58"}, + {file = "pbs_installer-2024.4.1-py3-none-any.whl", hash = "sha256:762e1b5b95a48389051205c48fcd4635e946b48ab3252d2c79a8a77dc87e91ff"}, + {file = "pbs_installer-2024.4.1.tar.gz", hash = "sha256:1f2aca82511fb9e1973b14708d7386780a8c56d111b680ae5786b3f430fa918a"}, ] [[package]] @@ -1040,12 +1060,12 @@ files = [ [[package]] name = "pycparser" -version = "2.21" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.22" +requires_python = ">=3.8" summary = "C parser in Python" files = [ - {file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"}, - {file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"}, + {file = "pycparser-2.22-py3-none-any.whl", hash = "sha256:c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc"}, + {file = "pycparser-2.22.tar.gz", hash = "sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6"}, ] [[package]] @@ -1058,6 +1078,20 @@ files = [ {file = "pygments-2.17.2.tar.gz", hash = "sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367"}, ] +[[package]] +name = "pyproject-api" +version = "1.6.1" +requires_python = ">=3.8" +summary = "API to interact with the python pyproject.toml based projects" +dependencies = [ + "packaging>=23.1", + "tomli>=2.0.1; python_version < \"3.11\"", +] +files = [ + {file = "pyproject_api-1.6.1-py3-none-any.whl", hash = "sha256:4c0116d60476b0786c88692cf4e325a9814965e2469c5998b830bba16b183675"}, + {file = "pyproject_api-1.6.1.tar.gz", hash = "sha256:1817dc018adc0d1ff9ca1ed8c60e1623d5aaca40814b953af14a9cf9a5cae538"}, +] + [[package]] name = "pyproject-hooks" version = "1.0.0" @@ -1446,6 +1480,70 @@ files = [ {file = "tomlkit-0.12.4.tar.gz", hash = "sha256:7ca1cfc12232806517a8515047ba66a19369e71edf2439d0f5824f91032b6cc3"}, ] +[[package]] +name = "tox" +version = "4.14.2" +requires_python = ">=3.8" +summary = "tox is a generic virtualenv management and test command line tool" +dependencies = [ + "cachetools>=5.3.2", + "chardet>=5.2", + "colorama>=0.4.6", + "filelock>=3.13.1", + "packaging>=23.2", + "platformdirs>=4.1", + "pluggy>=1.3", + "pyproject-api>=1.6.1", + "tomli>=2.0.1; python_version < \"3.11\"", + "virtualenv>=20.25", +] +files = [ + {file = "tox-4.14.2-py3-none-any.whl", hash = "sha256:2900c4eb7b716af4a928a7fdc2ed248ad6575294ed7cfae2ea41203937422847"}, + {file = "tox-4.14.2.tar.gz", hash = "sha256:0defb44f6dafd911b61788325741cc6b2e12ea71f987ac025ad4d649f1f1a104"}, +] + +[[package]] +name = "tox-gh" +version = "1.3.1" +requires_python = ">=3.7" +summary = "Seamless integration of tox into GitHub Actions." +dependencies = [ + "tox>=4.6", +] +files = [ + {file = "tox_gh-1.3.1-py3-none-any.whl", hash = "sha256:c671c62ce23ae519a557c3da81e9aa7e35b3a66c69bad71908e595921f83e82d"}, + {file = "tox_gh-1.3.1.tar.gz", hash = "sha256:594af90b740c14735c41b914b41db2d2aa0360929a1746af32bda4b9fef9bf3d"}, +] + +[[package]] +name = "tox-pdm" +version = "0.7.2" +requires_python = ">=3.7" +summary = "A plugin for tox that utilizes PDM as the package manager and installer" +dependencies = [ + "tomli; python_version < \"3.11\"", + "tox>=4.0", +] +files = [ + {file = "tox_pdm-0.7.2-py3-none-any.whl", hash = "sha256:12f6215416b7acd00a80a9e7128f3dc3e3c89308d60707f5d0a24abdf83ac104"}, + {file = "tox_pdm-0.7.2.tar.gz", hash = "sha256:a841a7e1e942a71805624703b9a6d286663bd6af79bba6130ba756975c315308"}, +] + +[[package]] +name = "tox-uv" +version = "1.7.0" +requires_python = ">=3.8" +summary = "Integration of uv with tox." +dependencies = [ + "packaging>=23.2", + "tox<5,>=4.14", + "uv<1,>=0.1.15", +] +files = [ + {file = "tox_uv-1.7.0-py3-none-any.whl", hash = "sha256:2915128b487ac720e27f8a6dc9597aa6925b62235c6041553055ced710943ea7"}, + {file = "tox_uv-1.7.0.tar.gz", hash = "sha256:0278f38f305ad0515f4d2620c70a848ef4d135a3d9eb778878d1ac8cbdd8528e"}, +] + [[package]] name = "trove-classifiers" version = "2024.3.25" @@ -1509,6 +1607,31 @@ files = [ {file = "urllib3-2.2.1.tar.gz", hash = "sha256:d0570876c61ab9e520d776c38acbbb5b05a776d3f9ff98a5c8fd5162a444cf19"}, ] +[[package]] +name = "uv" +version = "0.1.26" +requires_python = ">=3.8" +summary = "An extremely fast Python package installer and resolver, written in Rust." +files = [ + {file = "uv-0.1.26-py3-none-linux_armv6l.whl", hash = "sha256:15ed1e79e880a3fd3a17ddfd80aac6419b29072aa6578ad9fbd556b88162352a"}, + {file = "uv-0.1.26-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:56eab3304ba1cc5a1d3f090dab675a446f161e1104470e98c051109402394545"}, + {file = "uv-0.1.26-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ea6cfdc48167d13b33517e8a649a4226caead6e698c625bf0c30fab01fa8f6ca"}, + {file = "uv-0.1.26-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8052718335e727f091d9d51d86f2929ee314f99c18aba0ee5e5da6e746047933"}, + {file = "uv-0.1.26-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f927f7345556515c08096533a335c9d1d82e2847bf12d952f64f1965a18c50fd"}, + {file = "uv-0.1.26-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:d54625acfc50d141e3cafbc72ca4c95f7159ffb08330df4603ffd33ad1ee8df7"}, + {file = "uv-0.1.26-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a32eb98aeb97a75a10e9220580add9fe90beaacf1a0b4e5a7c3f7da2182de0a2"}, + {file = "uv-0.1.26-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:334bcd2099aac0060964beda45294cd6bfacb188ce2724b638423c3e26e05954"}, + {file = "uv-0.1.26-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf3c7337dc56185b4ac8c7844b3cabcc4f1a013be7cb0dc2eb16e028a19b1054"}, + {file = "uv-0.1.26-py3-none-manylinux_2_28_aarch64.whl", hash = "sha256:0e97e4fd57718c4669a549d96ef61efaed23e426d6606829a02ec6e8718f3c37"}, + {file = "uv-0.1.26-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:ce256a973071109e718acd8e5b03761fd97dfbf25f49cdab7f918d5548f86882"}, + {file = "uv-0.1.26-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:af8f8bff2253b65f55a3e8e3adfb7ac393fcd62e860a8d67658ce7bb2c7dcb0d"}, + {file = "uv-0.1.26-py3-none-musllinux_1_2_i686.whl", hash = "sha256:f7e1455857f82f75f41e8238ba411546d7ace335164a489e576afd9f79cd562f"}, + {file = "uv-0.1.26-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:872248a82d70049586c6755200e9a2a9e83edef96b9f1b703e62badadfccae1c"}, + {file = "uv-0.1.26-py3-none-win32.whl", hash = "sha256:1fb2ca59343db6bf92cda733dfb51ac946c1306e7e88e032bc02db3077545c0d"}, + {file = "uv-0.1.26-py3-none-win_amd64.whl", hash = "sha256:d8497292b6846b047b0a46bab5bcaadc0df7823bdcac15ecbe3aa7ba78c06607"}, + {file = "uv-0.1.26.tar.gz", hash = "sha256:8e2424445e269ff0f1855dfc5371e026ad7b49d5a9889c5e5c081af824991488"}, +] + [[package]] name = "virtualenv" version = "20.25.1" diff --git a/pyproject.toml b/pyproject.toml index a527ff3..203455f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,56 +1,55 @@ [build-system] -requires = ["pdm-backend"] build-backend = "pdm.backend" +requires = [ + "pdm-backend", +] [project] name = "sync-pre-commit-lock" -dynamic = ["version"] description = "PDM plugin to sync your pre-commit versions with your lockfile, and install them, all automatically." -authors = [{ name = "Gabriel Dugny", email = "sync-pre-commit-lock@dugny.me" }] -dependencies = [ - "tomli>=2.0.0; python_version < \"3.11\"", - "strictyaml>=1.7.3", -] -requires-python = ">=3.9" readme = "README.md" license = { file = "LICENSE" } +authors = [{ name = "Gabriel Dugny", email = "sync-pre-commit-lock@dugny.me" }] +requires-python = ">=3.9" classifiers = [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Environment :: Console", - "Environment :: Plugins", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Typing :: Typed", + "Development Status :: 3 - Alpha", + "Environment :: Console", + "Environment :: Plugins", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Typing :: Typed", +] +dynamic = [ + "version", +] +dependencies = [ + "strictyaml>=1.7.3", + 'tomli>=2; python_version < "3.11"', + 'typing-extensions; python_version < "3.10"', +] +[project.optional-dependencies] +pdm = [ + "pdm>=2.7.4", +] +poetry = [ + "poetry>=1.6", ] - [project.urls] -"Homepage" = "https://github.com/GabDug/sync-pre-commit-lock" -"Changelog" = "https://github.com/GabDug/sync-pre-commit-lock/releases" "Bug Tracker" = "https://github.com/GabDug/sync-pre-commit-lock/issues" - +"Changelog" = "https://github.com/GabDug/sync-pre-commit-lock/releases" +"Homepage" = "https://github.com/GabDug/sync-pre-commit-lock" [project.entry-points.pdm] pdm-sync-pre-commit-lock = "sync_pre_commit_lock.pdm_plugin:register_pdm_plugin" - [project.entry-points."poetry.application.plugin"] poetry-sync-pre-commit-lock = "sync_pre_commit_lock.poetry_plugin:SyncPreCommitLockPlugin" -[project.optional-dependencies] -poetry = [ - "poetry>=1.6.0", -] -pdm = [ - "pdm>=2.7.4", -] - - [tool.pdm] plugins = [ "-e ." @@ -65,13 +64,13 @@ write_template = "__version__: str = \"{}\"\n" fmt = {cmd="ruff format .", help="Run ruff formatter"} lint-mypy = {cmd="mypy src", help="Run mypy type checker"} # XXX(dugab): run mypy on tests as well -lint-ruff = {cmd="ruff .", help="Run ruff linter"} +lint-ruff = {cmd="ruff check .", help="Run ruff linter"} test-cov = {cmd="pytest --junitxml=junit/test-results.xml --cov --cov-report=xml --cov-report=html --cov-report=term-missing", help="Run tests with coverage"} [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", @@ -80,6 +79,16 @@ 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", + "tox-uv>=1.7.0" +] +testtox = [ + "pytest>=8.1.1", + "pytest-cov>=5.0.0", + "pytest-mock>=3.14.0", + "PyYAML>=6.0.1", ] [tool.ruff] @@ -90,27 +99,25 @@ respect-gitignore = true extend-select = ["Q000", "TCH", "I001", "S", "T", "PTH", "PYI", "RET", "D209", "D202", "EM101"] extend-ignore =["S101"] -[tool.mypy] -files = ["src"] -strict = true - -[[tool.mypy.overrides]] -module = "strictyaml" -ignore_missing_imports = true - [tool.pytest.ini_options] 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:", @@ -122,3 +129,11 @@ exclude_lines = [ "except ImportError:", "# nocov", ] + +[tool.mypy] +files = ["src"] +strict = true + +[[tool.mypy.overrides]] +module = "strictyaml" +ignore_missing_imports = true diff --git a/scripts/db_md.py b/scripts/db_md.py index 14b73ff..b54c00e 100644 --- a/scripts/db_md.py +++ b/scripts/db_md.py @@ -56,7 +56,7 @@ def import_db() -> PackageRepoMapping: This function imports the database module located at 'src/sync_pre_commit_lock/db.py' and returns the DEPENDENCY_MAPPING dictionary from the imported module. - We don't import direcly because pre-commit may not have the Python environment configured. + We don't import directly because pre-commit may not have the Python environment configured. Returns: dict: The DEPENDENCY_MAPPING dictionary from the imported database module. diff --git a/src/sync_pre_commit_lock/config.py b/src/sync_pre_commit_lock/config.py index 897dd0a..5e90c40 100644 --- a/src/sync_pre_commit_lock/config.py +++ b/src/sync_pre_commit_lock/config.py @@ -64,9 +64,9 @@ class Metadata(TypedDict, total=False): toml: str """Map the `toml` field""" env: str - """Optionnaly map the environment variable suffix""" + """Optionally map the environment variable suffix""" cast: Callable[[str], Any] - """Optionnaly provide a cast function for environment variable""" + """Optionally provide a cast function for environment variable""" @dataclass diff --git a/tests/conftest.py b/tests/conftest.py index b8a4da4..253aab6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,8 @@ -pytest_plugins = [ - "pdm.pytest", -] +try: + import pdm # noqa: F401 +except ImportError: + pass +else: + pytest_plugins = [ + "pdm.pytest", + ] diff --git a/tests/fixtures/poetry_project/pyproject.toml b/tests/fixtures/poetry_project/pyproject.toml index edbbb37..7da188d 100644 --- a/tests/fixtures/poetry_project/pyproject.toml +++ b/tests/fixtures/poetry_project/pyproject.toml @@ -15,5 +15,7 @@ black = "^23.3.0" isort = "^5.12.0" [build-system] -requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" +requires = [ + "poetry-core", +] diff --git a/tests/test_pdm/test_pdm_plugin.py b/tests/test_pdm/test_pdm_plugin.py index c93bf32..736d283 100644 --- a/tests/test_pdm/test_pdm_plugin.py +++ b/tests/test_pdm/test_pdm_plugin.py @@ -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 diff --git a/tests/test_pdm/test_pdm_sync_pre_commit_hook.py b/tests/test_pdm/test_pdm_sync_pre_commit_hook.py index 6f349a5..5d467e6 100644 --- a/tests/test_pdm/test_pdm_sync_pre_commit_hook.py +++ b/tests/test_pdm/test_pdm_sync_pre_commit_hook.py @@ -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 diff --git a/tests/test_poetry/test_poetry_plugin.py b/tests/test_poetry/test_poetry_plugin.py index a78a37f..f4719a3 100644 --- a/tests/test_poetry/test_poetry_plugin.py +++ b/tests/test_poetry/test_poetry_plugin.py @@ -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 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..fff4d3b --- /dev/null +++ b/tox.ini @@ -0,0 +1,70 @@ +[tox] +requires = + tox>=4.2 +env_list = + clean + report + py{312, 311, 310, 39}-pdm{213, 212, 211, 210, 29, 28, 27} + py{312, 311, 310, 39}-poetry{18, 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, 18}: COVERAGE_FILE = .coverage.{envname} +commands = + pytest --cov --cov-append --cov-report=term-missing {posargs:-vv} --cov-config=pyproject.toml +allowlist_externals = + coverage + pdm + pytest +depends = + report: py{312, 311, 310, 39}-pdm{213, 212, 211, 210, 29, 28, 27} + report: 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{18, 17, 16}: clean + +[testenv:clean] +skip_install = true +commands = + coverage erase + pdm export --dev --group testtox -o requirements-tox.txt +groups = + testtox + +[testenv:report] +skip_install = true +deps = + -r requirements-tox.txt +commands = + coverage combine + coverage report + coverage html + coverage xml + +[testenv:py{39,310,311,312}-pdm{27,28,29,210,211,212,213}] +package = editable +deps = + -r requirements-tox.txt + 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 + +[testenv:py{312, 311, 310, 39}-poetry{16, 17, 18}] +package = editable +deps = + -r requirements-tox.txt + poetry16: poetry<1.7,>=1.6 + poetry17: poetry<1.8,>=1.7 + poetry18: poetry<1.9,>=1.8 + +[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