From 27e7d0e789a62f9833efd9bb394cd3c0a96cd542 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:27:20 +0200 Subject: [PATCH 01/10] Bump mypy, use ruff in pre-commit config - Mypy to explicit v1.9.0. - Replace black v23.7.0 with ruff v0.3.5 for both linting and formatting. - Apply "ruff format ." to 1 file. - Move ruff config to current preferred keys in pyproject.toml. --- .pre-commit-config.yaml | 21 ++++++--------------- iam_units/currency.py | 1 + pyproject.toml | 6 ++---- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 88fba14..937a1dc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,25 +1,16 @@ repos: -- repo: local +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.9.0 hooks: - id: mypy - name: mypy - always_run: true - require_serial: true - pass_filenames: false - - language: python - entry: bash -c "mypy $0 $@" additional_dependencies: - - mypy - numpy - pint - pytest - args: ["."] -- repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.7.0 - hooks: - - id: black + args: [] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.287 + rev: v0.3.5 hooks: - id: ruff + - id: ruff-format + args: [ --check ] diff --git a/iam_units/currency.py b/iam_units/currency.py index b3e3cb3..d7420f8 100644 --- a/iam_units/currency.py +++ b/iam_units/currency.py @@ -3,6 +3,7 @@ See the inline comments (NB) for possible extensions of this code; also iam_units.update.currency. """ + from typing import Union try: diff --git a/pyproject.toml b/pyproject.toml index d7704af..dc54d64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,12 +34,10 @@ homepage = "https://github.com/IAMconsortium/units" update = ["globalwarmingpotentials"] tests = ["numpy", "pandas", "pytest", "pytest-cov"] -[tool.ruff] +[tool.ruff.lint] +mccabe.max-complexity = 7 select = ["C9", "E", "F", "I", "W"] -[tool.ruff.mccabe] -max-complexity = 7 - [tool.setuptools.packages] find = {} From 881da7235c8b7fabe7c9eb0e417624a645473e53 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:31:35 +0200 Subject: [PATCH 02/10] Bump versions in "test" CI workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - actions/checkout v3 → v4. - actions/setup-python v4 → v5. - codecov/codecov-action v3 → v4. - pre-commit/action v3.0.0 → v3.0.1. Also, add dependabot config for GitHub Actions. --- .github/dependabot.yml | 19 +++++++++++++++++++ .github/workflows/test.yaml | 14 ++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..391416f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +version: 2 +updates: +- package-ecosystem: "github-actions" + # Only update major versions + ignore: + - dependency-name: "*" + update-types: + - "version-update:semver-minor" + - "version-update:semver-patch" + # Below config mirrors the example at + # https://github.com/dependabot/dependabot-core/blob/main/.github/dependabot.yml + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + time: "16:00" + groups: + all-actions: + patterns: [ "*" ] diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cf7c626..82bbc50 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -25,9 +25,9 @@ jobs: name: pint${{ matrix.pint-version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: "3.x" cache: pip @@ -47,7 +47,9 @@ jobs: --cov=iam_units --cov-report=xml - name: Upload test coverage to Codecov.io - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} pre-commit: name: Code quality @@ -55,10 +57,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 - name: Force recreation of pre-commit virtual environment for mypy if: github.event_name == 'schedule' # Comment this line to run on a PR run: gh cache delete $(gh cache list -L 999 | cut -f2 | grep pre-commit) env: { GH_TOKEN: "${{ github.token }}" } - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 From 7192d0e952fffa3da5b2f17b55076b4af60db3a7 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:32:51 +0200 Subject: [PATCH 03/10] Add Python 3.12 to classifiers --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index dc54d64..65bd856 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Information Analysis", ] From 448dd269ab4a3a1e735df75335e8e59a77662770 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:34:21 +0200 Subject: [PATCH 04/10] Add pint version from pyproject.toml to CI matrix - Specify maximum version of numpy compatible with pint 0.11. - Add fail-fast: false to allow other jobs to complete. --- .github/workflows/test.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 82bbc50..608b36f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,12 +16,15 @@ jobs: matrix: pint-version: # Force specific version of pint + - "==0.11 'numpy < 1.23'" # Earliest shown in pyproject.toml - "==0.17" - "==0.18" - "==0.19.1" # No change, i.e. latest - "" + fail-fast: false + name: pint${{ matrix.pint-version }} steps: @@ -37,7 +40,7 @@ jobs: run: | python -m pip install --upgrade pip pip install .[tests] - # Force a specific version of pint + # Force a specific version of pint and perhaps other deps pip install pint${{ matrix.pint-version }} - name: Test From 93b47d334d866d6f2a56a02e13dd76dc48b25230 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:38:25 +0200 Subject: [PATCH 05/10] =?UTF-8?q?Cache=20loaded=20registry=20on=20pint=20?= =?UTF-8?q?=E2=89=A50.19?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iam_units/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/iam_units/__init__.py b/iam_units/__init__.py index c94cdb1..4de251c 100644 --- a/iam_units/__init__.py +++ b/iam_units/__init__.py @@ -16,8 +16,14 @@ ] -# Package registry using definitions.txt -registry = pint.UnitRegistry() +try: + # Use a registry cache + registry = pint.UnitRegistry(cache_folder=":auto:") +except TypeError: + # Pint <0.19; cache_folder argument is unavailable + registry = pint.UnitRegistry() + +# Load definitions.txt registry.load_definitions(str(Path(__file__).parent / "data" / "definitions.txt")) From 7ccf2f7566acac02ea84c9890768314e62f785a7 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:44:14 +0200 Subject: [PATCH 06/10] Update copyright year in README Adjust ReST for badges to render properly on GitHub. --- README.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 26b8c48..484faa8 100644 --- a/README.rst +++ b/README.rst @@ -1,15 +1,16 @@ Unit definitions for integrated-assessment research *************************************************** +|pypi| |gha| -.. image:: https://img.shields.io/pypi/v/iam-units.svg +.. |pypi| image:: https://img.shields.io/pypi/v/iam-units.svg :target: https://pypi.python.org/pypi/iam-units/ :alt: PyPI version -.. image:: https://github.com/IAMconsortium/units/actions/workflows/test.yaml/badge.svg +.. |gha| image:: https://github.com/IAMconsortium/units/actions/workflows/test.yaml/badge.svg :target: https://github.com/IAMconsortium/units/actions/workflows/test.yaml :alt: Build status -© 2020–2023 `IAM-units authors`_; licensed under the `GNU GPL version 3`_. +© 2020–2024 `IAM-units authors`_; licensed under the `GNU GPL version 3`_. The file `definitions.txt`_ gives `Pint`_-compatible definitions of energy, climate, and related units to supplement the SI and other units included in Pint's `default_en.txt`_. These definitions are used by: From e85541bb1fa95477a29c37519d3e821bedf2737b Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 18:58:01 +0200 Subject: [PATCH 07/10] Add Codecov badge to README --- README.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 484faa8..43e39f7 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,6 @@ Unit definitions for integrated-assessment research *************************************************** -|pypi| |gha| +|pypi| |gha| |coverage| .. |pypi| image:: https://img.shields.io/pypi/v/iam-units.svg :target: https://pypi.python.org/pypi/iam-units/ @@ -10,6 +10,10 @@ Unit definitions for integrated-assessment research :target: https://github.com/IAMconsortium/units/actions/workflows/test.yaml :alt: Build status +.. |coverage| image:: https://codecov.io/gh/IAMconsortium/units/graph/badge.svg?token=L0H171CF9O + :target: https://codecov.io/gh/IAMconsortium/units + :alt: Test coverage + © 2020–2024 `IAM-units authors`_; licensed under the `GNU GPL version 3`_. The file `definitions.txt`_ gives `Pint`_-compatible definitions of energy, climate, and related units to supplement the SI and other units included in Pint's `default_en.txt`_. From b1b0b1327e6fdc312f050757c3b03e61af1a1ca7 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 19:00:48 +0200 Subject: [PATCH 08/10] Run iam_units.update in CI to measure coverage --- .github/workflows/test.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 608b36f..8fa4310 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -49,6 +49,11 @@ jobs: -rA -vv --color=yes \ --cov=iam_units --cov-report=xml + - name: Test update code + run: | + # Analogous to "python -m iam_units.update …" + coverage run --append -m iam_units.update emissions || exit 0 + - name: Upload test coverage to Codecov.io uses: codecov/codecov-action@v4 with: From d62c1c366948fa001eced71b0c6ab78e5885a47c Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 19:06:06 +0200 Subject: [PATCH 09/10] Drop Python 3.7 support (reached EOL 2023-06-27) --- iam_units/currency.py | 8 +------- pyproject.toml | 3 +-- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/iam_units/currency.py b/iam_units/currency.py index d7420f8..104c50e 100644 --- a/iam_units/currency.py +++ b/iam_units/currency.py @@ -4,13 +4,7 @@ iam_units.update.currency. """ -from typing import Union - -try: - from typing import Literal -except ImportError: - from typing_extensions import Literal # type: ignore [assignment] - +from typing import Literal, Union #: Exchange rate data for method=EXC, period=2005, from #: https://data.oecd.org/conversion/exchange-rates.htm diff --git a/pyproject.toml b/pyproject.toml index 65bd856..d630e92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,7 +17,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -26,7 +25,7 @@ classifiers = [ "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Information Analysis", ] -dependencies = ["pint >= 0.11", "typing_extensions; python_version < '3.8'"] +dependencies = ["pint >= 0.11"] [project.urls] homepage = "https://github.com/IAMconsortium/units" From d8e2abdf7f134f389efc552a9ee13fcc49750b2c Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Mon, 8 Apr 2024 19:13:39 +0200 Subject: [PATCH 10/10] Use earlier Python for earlier numpy in CI --- .github/workflows/test.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8fa4310..cfe76aa 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,25 +14,26 @@ jobs: strategy: matrix: - pint-version: + version: # Force specific version of pint - - "==0.11 'numpy < 1.23'" # Earliest shown in pyproject.toml - - "==0.17" - - "==0.18" - - "==0.19.1" + # Earliest shown in pyproject.toml + - { python: "3.10", pint: "==0.11 'numpy < 1.23'" } + - { python: "3.x", pint: "==0.17" } + - { python: "3.x", pint: "==0.18" } + - { python: "3.x", pint: "==0.19.1" } # No change, i.e. latest - - "" + - { python: "3.x", pint: "" } fail-fast: false - name: pint${{ matrix.pint-version }} + name: pint${{ matrix.version.pint }} steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: "3.x" + python-version: ${{ matrix.version.python }} cache: pip cache-dependency-path: "**/pyproject.toml" @@ -41,7 +42,7 @@ jobs: python -m pip install --upgrade pip pip install .[tests] # Force a specific version of pint and perhaps other deps - pip install pint${{ matrix.pint-version }} + pip install pint${{ matrix.version.pint }} - name: Test run: |