From b2e3bdeee83df70e9d7c5d23d7bd63f133506f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Avil=C3=A9s?= Date: Wed, 27 Sep 2023 04:12:00 +0200 Subject: [PATCH 1/4] Change linter order in Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b17faf1..52db43e 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ unbehead: unbehead --check .PHONY: lint -lint: mypy ruff unbehead +lint: ruff unbehead mypy # -- testing ------------------------------------------------------------------- From fa9b74c17712a9056b16c00e26be896de5353ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Avil=C3=A9s?= Date: Wed, 27 Sep 2023 19:00:36 +0200 Subject: [PATCH 2/4] Enable CI workflows on stable branch --- .github/workflows/linting.yaml | 4 ++-- .github/workflows/testing.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index 26d70ed..780c46d 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -3,12 +3,12 @@ name: linting on: push: branches: - - devel - master + - stable pull_request: branches: - - devel - master + - stable jobs: setup: diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 72717cb..5162d5d 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -3,12 +3,12 @@ name: testing on: push: branches: - - devel - master + - stable pull_request: branches: - - devel - master + - stable jobs: setup: From 3f4e89024ccd6489384c2f4812652ff2620b193f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Avil=C3=A9s?= Date: Wed, 27 Sep 2023 03:28:51 +0200 Subject: [PATCH 3/4] Test all supported python versions --- .github/workflows/linting.yaml | 6 ++ .github/workflows/testing.yaml | 10 +++ .gitignore | 3 +- .python-version | 2 + README.md | 12 ++- poetry.lock | 142 +++++++++++++++++++++++++++++++-- pyproject.toml | 2 + tox.ini | 10 +++ 8 files changed, 177 insertions(+), 10 deletions(-) create mode 100644 tox.ini diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index 780c46d..d526219 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -23,6 +23,9 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' uses: actions/setup-python@v4 with: + # TODO: Remove explicit Python version once bug with .python-version file is solved + # https://github.com/actions/setup-python/issues/734 + python-version: '3.11' cache: 'poetry' - name: Install dependencies if: steps.python.outputs.cache-hit != 'true' @@ -41,6 +44,9 @@ jobs: id: python uses: actions/setup-python@v4 with: + # TODO: Remove explicit Python version once bug with .python-version file is solved + # https://github.com/actions/setup-python/issues/734 + python-version: '3.11' cache: 'poetry' - name: Install dependencies run: | diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 5162d5d..df3541f 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -13,6 +13,10 @@ on: jobs: setup: runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python-version: ['3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v3 - name: Install poetry @@ -23,6 +27,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' uses: actions/setup-python@v4 with: + python-version: ${{ matrix.python-version }} cache: 'poetry' - name: Install dependencies if: steps.python.outputs.cache-hit != 'true' @@ -32,6 +37,10 @@ jobs: test: needs: setup runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python-version: ['3.9', '3.10', '3.11'] steps: - uses: actions/checkout@v3 - name: Install poetry @@ -41,6 +50,7 @@ jobs: id: python uses: actions/setup-python@v4 with: + python-version: ${{ matrix.python-version }} cache: 'poetry' - name: Install package run: | diff --git a/.gitignore b/.gitignore index 99bb724..d23f78c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -# dependencies +# environments .venv/ +.tox/ # packaging dist/ diff --git a/.python-version b/.python-version index 2c07333..9ee447b 100644 --- a/.python-version +++ b/.python-version @@ -1 +1,3 @@ 3.11 +3.10 +3.9 diff --git a/README.md b/README.md index 010ca1f..4821868 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ git clone https://github.com/unconventionaldotdev/unbeheader cd unbeheader ``` -Before creating the virtualenv, you probably want to be using the same version of Python that the development of the project is targeting. This is the version specified in the `.python-version` file and you can install it with `pyenv`: +Before creating the virtualenv, you probably want to be using the same version of Python that the development of the project is targeting. This is the first version specified in the `.python-version` file and you can install it with `pyenv`: ```sh pyenv install @@ -160,14 +160,20 @@ unbehead This project uses GitHub Actions to run the tests and linter on every pull request to the `master` and `devel` branches. You are still encouraged to run the tests and linter locally before pushing your changes. +Linter checks can be run with: + +```sh +poetry run -- make lint +``` + Tests can be run with: ```sh poetry run -- make test ``` -Linter can be run with: +Tests can be run against all supported Python versions with: ```sh -poetry run -- make lint +tox ``` diff --git a/poetry.lock b/poetry.lock index dd1a3e7..d69bf0b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,26 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. + +[[package]] +name = "cachetools" +version = "5.3.1" +description = "Extensible memoizing collections and decorators" +optional = false +python-versions = ">=3.7" +files = [ + {file = "cachetools-5.3.1-py3-none-any.whl", hash = "sha256:95ef631eeaea14ba2e36f06437f36463aac3a096799e876ee55e5cdccb102590"}, + {file = "cachetools-5.3.1.tar.gz", hash = "sha256:dce83f2d9b4e1f732a8cd44af8e8fab2dbe46201467fc98b3ef8f269092bf62b"}, +] + +[[package]] +name = "chardet" +version = "5.2.0" +description = "Universal encoding detector for Python 3" +optional = false +python-versions = ">=3.7" +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 = "click" @@ -36,6 +58,17 @@ files = [ {file = "colorclass-2.2.2.tar.gz", hash = "sha256:6d4fe287766166a98ca7bc6f6312daf04a0481b1eda43e7173484051c0ab4366"}, ] +[[package]] +name = "distlib" +version = "0.3.7" +description = "Distribution utilities" +optional = false +python-versions = "*" +files = [ + {file = "distlib-0.3.7-py2.py3-none-any.whl", hash = "sha256:2e24928bc811348f0feb63014e97aaae3037f2cf48712d51ae61df7fd6075057"}, + {file = "distlib-0.3.7.tar.gz", hash = "sha256:9dafe54b34a028eafd95039d5e5d4851a13734540f1331060d31c9916e7147a8"}, +] + [[package]] name = "exceptiongroup" version = "1.1.2" @@ -50,6 +83,22 @@ files = [ [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "filelock" +version = "3.12.4" +description = "A platform independent file lock." +optional = false +python-versions = ">=3.8" +files = [ + {file = "filelock-3.12.4-py3-none-any.whl", hash = "sha256:08c21d87ded6e2b9da6728c3dff51baf1dcecf973b768ef35bcbc3447edb9ad4"}, + {file = "filelock-3.12.4.tar.gz", hash = "sha256:2e6f249f1f3654291606e046b09f1fd5eac39b360664c27f5aad072012f8bcbd"}, +] + +[package.extras] +docs = ["furo (>=2023.7.26)", "sphinx (>=7.1.2)", "sphinx-autodoc-typehints (>=1.24)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.3)", "diff-cover (>=7.7)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "pytest-timeout (>=2.1)"] +typing = ["typing-extensions (>=4.7.1)"] + [[package]] name = "iniconfig" version = "2.0.0" @@ -129,21 +178,55 @@ files = [ {file = "packaging-23.1.tar.gz", hash = "sha256:a392980d2b6cffa644431898be54b0045151319d1e7ec34f0cfed48767dd334f"}, ] +[[package]] +name = "platformdirs" +version = "3.10.0" +description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." +optional = false +python-versions = ">=3.7" +files = [ + {file = "platformdirs-3.10.0-py3-none-any.whl", hash = "sha256:d7c24979f292f916dc9cbf8648319032f551ea8c49a4c9bf2fb556a02070ec1d"}, + {file = "platformdirs-3.10.0.tar.gz", hash = "sha256:b45696dab2d7cc691a3226759c0d3b00c47c8b6e293d96f6436f733303f77f6d"}, +] + +[package.extras] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.1)", "sphinx-autodoc-typehints (>=1.24)"] +test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)"] + [[package]] name = "pluggy" -version = "1.2.0" +version = "1.3.0" description = "plugin and hook calling mechanisms for python" optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "pluggy-1.2.0-py3-none-any.whl", hash = "sha256:c2fd55a7d7a3863cba1a013e4e2414658b1d07b6bc57b3919e0c63c9abb99849"}, - {file = "pluggy-1.2.0.tar.gz", hash = "sha256:d12f0c4b579b15f5e054301bb226ee85eeeba08ffec228092f8defbaa3a4c4b3"}, + {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, + {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, ] [package.extras] dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] +[[package]] +name = "pyproject-api" +version = "1.6.1" +description = "API to interact with the python pyproject.toml based projects" +optional = false +python-versions = ">=3.8" +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.dependencies] +packaging = ">=23.1" +tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} + +[package.extras] +docs = ["furo (>=2023.8.19)", "sphinx (<7.2)", "sphinx-autodoc-typehints (>=1.24)"] +testing = ["covdefaults (>=2.3)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "setuptools (>=68.1.2)", "wheel (>=0.41.2)"] + [[package]] name = "pytest" version = "7.4.0" @@ -252,6 +335,33 @@ files = [ {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] +[[package]] +name = "tox" +version = "4.11.3" +description = "tox is a generic virtualenv management and test command line tool" +optional = false +python-versions = ">=3.8" +files = [ + {file = "tox-4.11.3-py3-none-any.whl", hash = "sha256:599af5e5bb0cad0148ac1558a0b66f8fff219ef88363483b8d92a81e4246f28f"}, + {file = "tox-4.11.3.tar.gz", hash = "sha256:5039f68276461fae6a9452a3b2c7295798f00a0e92edcd9a3b78ba1a73577951"}, +] + +[package.dependencies] +cachetools = ">=5.3.1" +chardet = ">=5.2" +colorama = ">=0.4.6" +filelock = ">=3.12.3" +packaging = ">=23.1" +platformdirs = ">=3.10" +pluggy = ">=1.3" +pyproject-api = ">=1.6.1" +tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} +virtualenv = ">=20.24.3" + +[package.extras] +docs = ["furo (>=2023.8.19)", "sphinx (>=7.2.4)", "sphinx-argparse-cli (>=1.11.1)", "sphinx-autodoc-typehints (>=1.24)", "sphinx-copybutton (>=0.5.2)", "sphinx-inline-tabs (>=2023.4.21)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +testing = ["build[virtualenv] (>=0.10)", "covdefaults (>=2.3)", "detect-test-pollution (>=1.1.1)", "devpi-process (>=1)", "diff-cover (>=7.7)", "distlib (>=0.3.7)", "flaky (>=3.7)", "hatch-vcs (>=0.3)", "hatchling (>=1.18)", "psutil (>=5.9.5)", "pytest (>=7.4)", "pytest-cov (>=4.1)", "pytest-mock (>=3.11.1)", "pytest-xdist (>=3.3.1)", "re-assert (>=1.1)", "time-machine (>=2.12)", "wheel (>=0.41.2)"] + [[package]] name = "types-pyyaml" version = "6.0.12.11" @@ -274,7 +384,27 @@ files = [ {file = "typing_extensions-4.8.0.tar.gz", hash = "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef"}, ] +[[package]] +name = "virtualenv" +version = "20.24.5" +description = "Virtual Python Environment builder" +optional = false +python-versions = ">=3.7" +files = [ + {file = "virtualenv-20.24.5-py3-none-any.whl", hash = "sha256:b80039f280f4919c77b30f1c23294ae357c4c8701042086e3fc005963e4e537b"}, + {file = "virtualenv-20.24.5.tar.gz", hash = "sha256:e8361967f6da6fbdf1426483bfe9fca8287c242ac0bc30429905721cefbff752"}, +] + +[package.dependencies] +distlib = ">=0.3.7,<1" +filelock = ">=3.12.2,<4" +platformdirs = ">=3.9.1,<4" + +[package.extras] +docs = ["furo (>=2023.7.26)", "proselint (>=0.13)", "sphinx (>=7.1.2)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=23.6)"] +test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23.1)", "pytest (>=7.4)", "pytest-env (>=0.8.2)", "pytest-freezer (>=0.4.8)", "pytest-mock (>=3.11.1)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)", "setuptools (>=68)", "time-machine (>=2.10)"] + [metadata] lock-version = "2.0" python-versions = ">=3.9.0" -content-hash = "566a285ab52db40a2b236723b716f3ebd104228c1c4c9a0121a3153231cf97f8" +content-hash = "29e675c4469e3c330b626963c411701fd267f745a49b0c5a4df3d81fe97bb12c" diff --git a/pyproject.toml b/pyproject.toml index 6a30dee..7a18c67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [virtualenvs] create = true in-project = true +prefer-active-python = true [tool.poetry] name = "unbeheader" @@ -37,6 +38,7 @@ click = ">=8" mypy = "^1.5.1" pytest = "^7.4.0" ruff = "^0.0.280" +tox = "^4.11.3" types-pyyaml = "^6.0.12.11" [build-system] diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..70a1e6b --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist = py{39,310,311} +no_package = true + +[testenv] +allowlist_externals = poetry +commands_pre = + poetry install -v +commands = + poetry run -- make test From 43fae2d2e90068887848a181fc17572385239082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Avil=C3=A9s?= Date: Wed, 27 Sep 2023 04:08:23 +0200 Subject: [PATCH 4/4] Fix import errors in Python 3.9 --- CHANGELOG.md | 1 + src/unbeheader/typing.py | 6 +++--- src/unbeheader/util.py | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b746dc..913d2f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v1.3.0 (unreleased) - Added support for `.header.yml` config files. +- Fixed compatibility with Python 3.9. ## v1.2.0 diff --git a/src/unbeheader/typing.py b/src/unbeheader/typing.py index 1003cc8..073ad70 100644 --- a/src/unbeheader/typing.py +++ b/src/unbeheader/typing.py @@ -6,10 +6,10 @@ from re import Pattern from typing import Any from typing import NamedTuple -from typing import TypeAlias -ConfigDict: TypeAlias = dict[str, Any] -PathCache: TypeAlias = dict[Path, bool] +# TODO: Use explicit TypeAlias when Python 3.9 is dropped +ConfigDict = dict[str, Any] +PathCache = dict[Path, bool] @dataclass diff --git a/src/unbeheader/util.py b/src/unbeheader/util.py index b918792..e34c6d0 100644 --- a/src/unbeheader/util.py +++ b/src/unbeheader/util.py @@ -1,6 +1,8 @@ # This file is part of Unbeheader. # Copyright (C) CERN & UNCONVENTIONAL +from __future__ import annotations + import re from pathlib import Path from re import Match