Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements and housekeeping for 2024-W15 #48

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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: [ "*" ]
41 changes: 26 additions & 15 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,62 @@ jobs:

strategy:
matrix:
pint-version:
version:
# Force specific version of pint
- "==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: "" }

name: pint${{ matrix.pint-version }}
fail-fast: false

name: pint${{ matrix.version.pint }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
python-version: ${{ matrix.version.python }}
cache: pip
cache-dependency-path: "**/pyproject.toml"

- name: Install
run: |
python -m pip install --upgrade pip
pip install .[tests]
# Force a specific version of pint
pip install pint${{ matrix.pint-version }}
# Force a specific version of pint and perhaps other deps
pip install pint${{ matrix.version.pint }}

- name: Test
run: |
pytest iam_units \
-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@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

pre-commit:
name: Code quality

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
21 changes: 6 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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 ]
11 changes: 8 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
Unit definitions for integrated-assessment research
***************************************************
|pypi| |gha| |coverage|

.. 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`_.
.. |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`_.
These definitions are used by:
Expand Down
10 changes: 8 additions & 2 deletions iam_units/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))


Expand Down
7 changes: 1 addition & 6 deletions iam_units/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
See the inline comments (NB) for possible extensions of this code; also
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
Expand Down
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"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"
Expand All @@ -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 = {}

Expand Down
Loading