From 75bd6a0b64afa0d65eaa5514566367cf72bbcf67 Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Sat, 25 Jan 2025 19:29:14 -0500 Subject: [PATCH 1/5] Improve GHA configuration in `test-pr.yml` I copied multiple improvements from `chiron-utils`'s GitHub Actions setup to this file: - Enable running on pushes, which makes testing CI changes easier - Remove all GitHub API permissions for security - Cancel running CI job if a change is pushed - Update used actions to non-deprecated versions - Factor out Python version for easier reuse - Use stricter configuration for shell to catch more bugs Improvements copied from https://github.com/ALLAN-DIP/chiron-utils/blob/3a795038e73a7099dd9012c2480df7d35f74e05e/.github/workflows/checks.yaml --- .github/workflows/test-pr.yml | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index ced22a3..1d50265 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -3,18 +3,40 @@ name: test-pr on: pull_request: branches: - - "main" + - main + push: + branches: + - main + - test-ci** + workflow_dispatch: # Enable workflow to be run manually + +# Disable all access to the GitHub API by default +# This default can be overridden for individual workflows and jobs +# Documentation: https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#permissions +permissions: {} + +# Cancel the currently running CI job if you push a change while CI is running +# Documentation: https://docs.github.com/en/actions/using-jobs/using-concurrency +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: test: runs-on: ubuntu-latest + name: Run tests + env: + PYTHON_VERSION: "3.7" + defaults: + run: + shell: bash -leo pipefail {0} steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set Up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: - python-version: "3.7" + python-version: ${{ env.PYTHON_VERSION }} - name: Install daidepp run: | pip install -e .[dev] From 4c201f307f26800e11f561f50e349efa52efc6c9 Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Sat, 25 Jan 2025 19:29:25 -0500 Subject: [PATCH 2/5] Pin OS and Python versions in `test-pr.yml` CI was broken because `ubuntu-latest` changed from Ubuntu 22.04 to 24.04, and the latter doesn't have Python 3.7. I pinned to using Ubuntu 22.04 so we can continue using Python 3.7. In addition, I pinned to the specific Python 3.7 patch release to limit possible breakage. --- .github/workflows/test-pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 1d50265..031290f 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -23,10 +23,10 @@ concurrency: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 # Needed for Python 3.7 name: Run tests env: - PYTHON_VERSION: "3.7" + PYTHON_VERSION: 3.7.17 defaults: run: shell: bash -leo pipefail {0} From 30462c505c821efe6ec58d800f418c49210dbb4e Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Fri, 24 Jan 2025 20:48:59 -0500 Subject: [PATCH 3/5] Improve test running This commit contains multiple related changes: - Update `dev` dependencies as much as possible - The pinned versions did not work with Python 3.11, but using the latest versions does not work with Python 3.7. The new versions work for both Python 3.7 and 3.11. - Pin `black` and `isort` versions - Unlike the other `dev` dependencies, which are specified with `==`, these two dependencies were specified with `>=`. I pinned these to specific versions to match the other dependencies and limit breakage. - Update `pip` in `test-pr.yml` - The version of `pip` shipped in GitHub Actions shows warnings that are fixed by upgrading to the latest supported version. --- .github/workflows/test-pr.yml | 1 + setup.cfg | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 031290f..606ad85 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -39,6 +39,7 @@ jobs: python-version: ${{ env.PYTHON_VERSION }} - name: Install daidepp run: | + pip install -U pip pip install -e .[dev] - name: Test run: | diff --git a/setup.cfg b/setup.cfg index 4c45ca3..d076ed8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,17 +21,17 @@ where = src [options.extras_require] dev = - black>=22.8.0 - docformatter==1.4 - isort>=5.10.1 - pydocstyle==6.1.1 - pylint==2.12.2 - pytest==7.0.0 - pytest-black==0.3.12 - pytest-cov==3.0.0 - pytest-dependency==0.5.1 - pytest-mypy==0.9.1 - pytest-timeout==2.1.0 + black==23.3.0 + docformatter==1.7.5 + isort==5.11.5 + pydocstyle==6.3.0 + pylint==2.17.7 + pytest==7.4.4 + pytest-black==0.6.0 + pytest-cov==4.1.0 + pytest-dependency==0.6.0 + pytest-mypy==0.10.3 + pytest-timeout==2.3.1 [isort] multi_line_output = 3 From 863632391043950a4a5703ecb794f0ed5972a9a8 Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Mon, 11 Nov 2024 19:03:48 -0500 Subject: [PATCH 4/5] Install `typing_extensions` if needed The `typing_extensions` module was imported but not listed as a requirement, so importing `daidepp` failed if `typing_extensions` wasn't installed for another reason. I have added it as an explicit requirement and only use it if `Literal` or `get_args` cannot be imported directly from the `typing` module. --- setup.cfg | 1 + src/daidepp/constants.py | 5 ++++- src/daidepp/grammar/grammar.py | 8 ++++++-- src/daidepp/grammar/grammar_utils.py | 6 +++++- src/daidepp/keywords/base_keywords.py | 5 ++++- src/daidepp/visitor.py | 6 +++++- tests/conftest.py | 6 +++++- 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index d076ed8..e050429 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,6 +15,7 @@ python_requires = >=3.7 install_requires = parsimonious==0.9.0 importlib-metadata>=1.4.0 ; python_version < "3.8" + typing_extensions>=3.10.0.0 ; python_version < "3.8" [options.packages.find] where = src diff --git a/src/daidepp/constants.py b/src/daidepp/constants.py index ecd918b..e9c231b 100644 --- a/src/daidepp/constants.py +++ b/src/daidepp/constants.py @@ -1,4 +1,7 @@ -from typing_extensions import Literal +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal Power = Literal["AUS", "ENG", "FRA", "GER", "ITA", "RUS", "TUR"] UnitType = Literal["AMY", "FLT"] diff --git a/src/daidepp/grammar/grammar.py b/src/daidepp/grammar/grammar.py index c798c61..68b94fd 100644 --- a/src/daidepp/grammar/grammar.py +++ b/src/daidepp/grammar/grammar.py @@ -5,9 +5,13 @@ from __future__ import annotations from typing import Dict, Tuple -from typing_extensions import get_args -from typing_extensions import Literal +try: + from typing import Literal + from typing import get_args +except ImportError: + from typing_extensions import Literal + from typing_extensions import get_args DAIDELevel = Literal[ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160 diff --git a/src/daidepp/grammar/grammar_utils.py b/src/daidepp/grammar/grammar_utils.py index 4bfae0c..6618b87 100644 --- a/src/daidepp/grammar/grammar_utils.py +++ b/src/daidepp/grammar/grammar_utils.py @@ -3,7 +3,11 @@ from typing import Dict, List, Optional, Set, Tuple, Union from parsimonious.grammar import Grammar -from typing_extensions import Literal + +try: + from typing import Literal +except ImportError: + from typing_extensions import Literal from daidepp.constants import PressKeywords from daidepp.grammar.grammar import ( diff --git a/src/daidepp/keywords/base_keywords.py b/src/daidepp/keywords/base_keywords.py index c36ac0d..ba2f7b6 100644 --- a/src/daidepp/keywords/base_keywords.py +++ b/src/daidepp/keywords/base_keywords.py @@ -3,7 +3,10 @@ from dataclasses import dataclass from typing import Optional, Tuple, Union -from typing_extensions import get_args +try: + from typing import get_args +except ImportError: + from typing_extensions import get_args from daidepp.constants import * from daidepp.keywords.daide_object import _DAIDEObject diff --git a/src/daidepp/visitor.py b/src/daidepp/visitor.py index 924ba99..a7beed8 100644 --- a/src/daidepp/visitor.py +++ b/src/daidepp/visitor.py @@ -2,7 +2,11 @@ from typing import Any from parsimonious.nodes import Node, NodeVisitor -from typing_extensions import get_args + +try: + from typing import get_args +except ImportError: + from typing_extensions import get_args from daidepp.constants import ProvinceNoCoast from daidepp.keywords.base_keywords import * diff --git a/tests/conftest.py b/tests/conftest.py index 4b623c0..8c63bb2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,9 @@ import pytest -from typing_extensions import get_args + +try: + from typing import get_args +except ImportError: + from typing_extensions import get_args from daidepp.grammar import create_daide_grammar from daidepp.grammar.grammar import DAIDELevel, MAX_DAIDE_LEVEL From 314520c79890efc43ef570e8dc612402ccd8f532 Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Mon, 27 Jan 2025 19:05:14 -0500 Subject: [PATCH 5/5] Simplify imports in `grammar.py` --- src/daidepp/grammar/grammar.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/daidepp/grammar/grammar.py b/src/daidepp/grammar/grammar.py index 68b94fd..dd8db31 100644 --- a/src/daidepp/grammar/grammar.py +++ b/src/daidepp/grammar/grammar.py @@ -7,11 +7,9 @@ from typing import Dict, Tuple try: - from typing import Literal - from typing import get_args + from typing import Literal, get_args except ImportError: - from typing_extensions import Literal - from typing_extensions import get_args + from typing_extensions import Literal, get_args DAIDELevel = Literal[ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160