Skip to content

Commit

Permalink
Merge pull request #156 from khaeru/ci/2025-w03
Browse files Browse the repository at this point in the history
Miscellaneous CI updates
  • Loading branch information
khaeru authored Jan 15, 2025
2 parents 2cae4bb + d3d4215 commit 765404e
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 54 deletions.
33 changes: 27 additions & 6 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
name: Build package / publish

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
tags: [ "v*" ]
release:
types: [ published ]
# Check that package can be built even on PRs
pull_request:
branches: [ main ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
python-version: "3.13"
# Uncomment for testing
# UV_PUBLISH_URL: https://test.pypi.org/legacy/


jobs:
publish:
uses: iiasa/actions/.github/workflows/publish.yaml@main
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
environment:
name: publish
permissions:
id-token: write
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
cache-dependency-glob: "**/pyproject.toml"
python-version: ${{ env.python-version }}
- run: uv build
- run: uv publish --trusted-publishing=always
if: >-
github.event_name == 'release' || (
github.event_name == 'push'
&& startsWith(github.ref, 'refs/tags')
)
37 changes: 17 additions & 20 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ on:
schedule:
- cron: "0 5 * * *"

# Cancel previous runs that have not completed
concurrency:
concurrency: # Cancel previous runs that have not completed
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

Expand Down Expand Up @@ -51,31 +50,30 @@ jobs:
with:
fetch-depth: ${{ env.depth }}

- uses: actions/setup-python@v5
- name: Set up uv, Python
uses: astral-sh/setup-uv@v5
with:
cache-dependency-glob: "**/pyproject.toml"
python-version: ${{ matrix.python.version }}
cache: pip
cache-dependency-path: "**/pyproject.toml"

- uses: ts-graphviz/setup-graphviz@v2
with:
macos-skip-brew-update: true

- name: Install the Python package and dependencies
run: pip install --upgrade --upgrade-strategy=eager .[tests] ${{ matrix.python.extras }}
- name: Install the package and dependencies
run: uv pip install .[tests] ${{ matrix.python.extras }}

- name: Run test suite using pytest
- name: Run tests
run: |
pytest genno \
--trace-config --color=yes --verbose \
uv run --no-sync \
pytest \
--trace-config --color=yes --durations=20 -ra --verbose \
--cov-report=xml --cov-report=term \
--numprocesses auto
--numprocesses=auto
shell: bash

- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

pre-commit:
name: Code quality
Expand All @@ -84,14 +82,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: 3.x }
- run: python -m pip install pre-commit && python -m pip freeze --local
- uses: astral-sh/setup-uv@v5
with:
cache-dependency-glob: "**/pyproject.toml"
python-version: "3.12" # TEMPORARY work around https://github.com/python/mypy/issues/18216
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Force recreation of pre-commit virtual environment for mypy
if: github.event_name == 'schedule' # Comment this line to run on a PR
run: pre-commit clean
- run: pre-commit run --all-files --color=always --show-diff-on-failure
lookup-only: ${{ github.event_name == 'schedule' }} # Set 'true' to recreate cache
- run: uvx pre-commit run --all-files --color=always --show-diff-on-failure
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
rev: v1.14.1
hooks:
- id: mypy
pass_filenames: false
additional_dependencies:
- importlib_resources
- lxml-stubs
Expand All @@ -18,9 +19,8 @@ repos:
- types-python-dateutil
- types-requests
- xarray
args: []
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.9.1
hooks:
- id: ruff
- id: ruff-format
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The package name is warning, by reference, to the adage “When you hold a hamme
License
=======

Copyright © 2018–2024 genno contributors.
Copyright © 2018–2025 genno contributors.

Licensed under the GNU General Public License, version 3.0.

Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# -- Project information ---------------------------------------------------------------

project = "genno"
copyright = "2018–2024, Genno contributors"
copyright = "2018–%Y, Genno contributors"
author = "Genno contributors"


Expand Down
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Packages that extend :mod:`genno` include:
License
=======

Copyright © 2018–2024 genno contributors.
Copyright © 2018–2025 genno contributors.

Licensed under the GNU General Public License, version 3.0.

Expand Down
6 changes: 3 additions & 3 deletions genno/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def _log_or_raise(exc: Exception, default_level: str, message: str):
_log_or_raise(e, "warning", repr(e))
else:
if keys := list(iter_keys(result)):
log.info(f"Add {repr(keys[0])} + {len(keys)-1} partial sums")
log.info(f"Add {repr(keys[0])} + {len(keys) - 1} partial sums")


@handles("alias")
Expand Down Expand Up @@ -288,7 +288,7 @@ def combine(c: Computer, info):

added = iter_keys(c.add(key, task, strict=True, sums=True))

log.info(f"Add {repr(key)} + {len(list(added))-1} partial sums")
log.info(f"Add {repr(key)} + {len(list(added)) - 1} partial sums")
log.debug(" as combination of")
log.debug(f" {repr(quantities)}")

Expand Down Expand Up @@ -354,7 +354,7 @@ def general(c: Computer, info):
added = c.add(key, _seq(task), strict=True, sums=info.get("sums", False))

if isinstance(added, tuple):
log.info(f" + {len(added)-1} partial sums")
log.info(f" + {len(added) - 1} partial sums")


@handles("report")
Expand Down
2 changes: 1 addition & 1 deletion genno/core/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def assert_quantity(*args):
for i, arg in enumerate(args):
if not isinstance(arg, BaseQuantity):
raise TypeError(
f"arg #{i+1} ({repr(arg)[:20]}) is not Quantity; likely an incorrect key"
f"arg #{i + 1} ({repr(arg)[:20]}) is not Quantity; likely an incorrect key"
)


Expand Down
6 changes: 3 additions & 3 deletions genno/core/sparsedataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def __init__(

attrs = collect_attrs(data, attrs, kwargs)

assert 0 == len(
kwargs
), f"Unrecognized kwargs {kwargs.keys()} to SparseDataArray()"
assert 0 == len(kwargs), (
f"Unrecognized kwargs {kwargs.keys()} to SparseDataArray()"
)

if isinstance(data, int):
data = float(data)
Expand Down
6 changes: 3 additions & 3 deletions genno/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ def assert_qty_allclose(

def assert_units(qty: "AnyQuantity", exp: str) -> None:
"""Assert that `qty` has units `exp`."""
assert (
qty.units / qty.units._REGISTRY(exp)
).dimensionless, f"Units '{qty.units:~}'; expected {repr(exp)}"
assert (qty.units / qty.units._REGISTRY(exp)).dimensionless, (
f"Units '{qty.units:~}'; expected {repr(exp)}"
)


def random_qty(shape: dict[str, int], **kwargs) -> "AnyQuantity":
Expand Down
7 changes: 4 additions & 3 deletions genno/tests/core/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def test_computationerror_format(caplog):
Use Computer.describe\(...\) to trace the computation\.
Computation traceback:
File ".*", line 4, in fail
'x' \+ 3.4 # Raises TypeError(\n.*)?
TypeError: can only concatenate str \(not "float"\) to str.*"""
File ".*", line 5, in fail
"x" \+ 3.4 # Raises TypeError.*
TypeError: can only concatenate str \(not "float"\) to str.*""",
re.DOTALL,
)


Expand Down
8 changes: 5 additions & 3 deletions genno/tests/data/exceptions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"source": [
"import genno\n",
"\n",
"\n",
"def fail():\n",
" 'x' + 3.4 # Raises TypeError\n",
" \"x\" + 3.4 # Raises TypeError\n",
"\n",
"\n",
"c = genno.Computer()\n",
"c.add('test', (fail,))\n",
"c.get('test')"
"c.add(\"test\", (fail,))\n",
"c.get(\"test\")"
]
}
],
Expand Down
24 changes: 18 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build-system]
requires = ["build", "setuptools-scm"]
requires = ["hatchling", "versioningit"]
build-backend = "hatchling.build"

[project]
dynamic = ["version"]
Expand Down Expand Up @@ -56,7 +57,10 @@ tests = [
"pytest-rerunfailures",
"pytest-xdist",
]
sparse = ["sparse >= 0.12"]
sparse = [
"numba >= 0.54", # Override >= 0.49 as of sparse 0.15.4
"sparse >= 0.12",
]

[project.urls]
homepage = "https://github.com/khaeru/genno"
Expand All @@ -75,6 +79,16 @@ exclude_also = [
"return NotImplemented",
]

[tool.hatch]
version.source = "versioningit"

[tool.mypy]
files = [
"conftest.py",
"doc",
"genno",
]

[[tool.mypy.overrides]]
# Packages/modules for which no type hints are available
module = [
Expand Down Expand Up @@ -111,7 +125,5 @@ ignore = ["E501", "W191"]
# - .core.computer.add_queue: 11
mccabe.max-complexity = 10

[tool.setuptools.packages]
find = {}

[tool.setuptools_scm]
[tool.versioningit]
default-version = "0.1.dev1" # Match setuptools-scm

0 comments on commit 765404e

Please sign in to comment.