Skip to content

Commit

Permalink
Merge pull request #492 from iiasa/enh/pre-commit
Browse files Browse the repository at this point in the history
Use pre-commit to invoke ruff, mypy
  • Loading branch information
khaeru authored Sep 19, 2023
2 parents 3a5479c + 3333827 commit 565a546
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 48 deletions.
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/lint.yaml

This file was deleted.

23 changes: 20 additions & 3 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ concurrency:
cancel-in-progress: true

env:
# See description in lint.yml
depth: 100

jobs:
Expand All @@ -26,8 +25,7 @@ jobs:
- ubuntu-latest
- windows-latest
python-version:
- "3.7" # Earliest version supported by ixmp
- "3.8"
- "3.8" # Earliest version supported by ixmp
- "3.9"
- "3.10"
- "3.11" # Latest supported by ixmp
Expand Down Expand Up @@ -96,6 +94,9 @@ jobs:
- name: Install Python package and dependencies
# [docs] contains [tests], which contains [report,tutorial]
run: |
# Work around https://bugs.launchpad.net/lxml/+bug/2035206
pip install "lxml != 4.9.3"
pip install .[docs]
# commented: use with "pandas-version" in the matrix, above
Expand Down Expand Up @@ -134,3 +135,19 @@ jobs:

- name: Upload test coverage to Codecov.io
uses: codecov/codecov-action@v3

pre-commit:
name: Code quality

runs-on: ubuntu-latest

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

- name: Force recreation of pre-commit virtual environment for mypy
if: github.event_name == 'schedule'
run: gh cache list -L 999 | cut -f2 | grep pre-commit | xargs -I{} gh cache delete "{}" || true
env: { GH_TOKEN: "${{ github.token }}" }

- uses: pre-commit/[email protected]
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ rixmp/source/inst/docum/*.html
# pytest and related
.benchmarks
.coverage*
.pytest_cache
.mypy_cache
.pytest_cache
.ruff_cache
*.pid
coverage.xml
htmlcov
Expand Down
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
repos:
- repo: local
hooks:
- id: mypy
name: mypy
always_run: true
require_serial: true
pass_filenames: false

language: python
entry: bash -c ". ${PRE_COMMIT_MYPY_VENV:-/dev/null}/bin/activate 2>/dev/null; mypy $0 $@"
additional_dependencies:
- mypy
- genno
- GitPython
- nbclient
- pytest
- sphinx
- xarray
args: ["."]
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
hooks:
- id: ruff
1 change: 1 addition & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Next release
.. All changes
.. -----------
- Support for Python 3.7 is dropped (:pull:`492`).
- New :func:`.utils.discard_on_error` and matching argument to :meth:`.TimeSeries.transact` to avoid locking :class:`.TimeSeries` / :class:`.Scenario` on failed operations with :class:`.JDBCBackend` (:pull:`488`).

.. _v3.7.0:
Expand Down
5 changes: 5 additions & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ Use cases for installing ixmp directly include:
Install system dependencies
===========================

Python
------

Python version 3.8 or later is required.

GAMS (required)
---------------

Expand Down
6 changes: 1 addition & 5 deletions ixmp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import logging

try:
from importlib.metadata import PackageNotFoundError, version
except ImportError: # Python 3.7
from importlib_metadata import PackageNotFoundError, version # type: ignore
from importlib.metadata import PackageNotFoundError, version

from ixmp._config import config
from ixmp.backend import BACKENDS, IAMC_IDX, ItemType
Expand Down
28 changes: 16 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ requires = ["build", "setuptools-scm"]
dynamic = ["version"]
name = "ixmp"
description = "The ix modeling platform"
authors = [
{ name = "IIASA Energy, Climate, and Environment (ECE) program" },
]
authors = [{ name = "IIASA Energy, Climate, and Environment (ECE) program" }]
maintainers = [
{name = "Paul Natsuo Kishimoto", email = "[email protected]"},
{name = "Fridolin Glatter", email = "[email protected]"},
{ name = "Paul Natsuo Kishimoto", email = "[email protected]" },
{ name = "Fridolin Glatter", email = "[email protected]" },
]
readme = "README.md"
classifiers = [
Expand All @@ -22,7 +20,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",
Expand All @@ -31,11 +28,10 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
]
requires-python = ">=3.8"
dependencies = [
"click",
"genno <= 1.13; python_version < '3.8'",
"genno >= 1.16; python_version >= '3.8'",
"importlib_metadata; python_version < '3.8'",
"genno >= 1.16",
"JPype1 >= 1.2.1",
"openpyxl",
"pandas >= 1.2",
Expand Down Expand Up @@ -75,9 +71,7 @@ tests = [
ixmp = "ixmp.cli:main"

[tool.coverage.report]
omit = [
"ixmp/utils/sphinx_linkcode_github.py",
]
omit = ["ixmp/utils/sphinx_linkcode_github.py"]

[tool.isort]
profile = "black"
Expand Down Expand Up @@ -112,6 +106,16 @@ markers = [
"performance: ixmp performance test.",
]

[tool.ruff]
select = ["C9", "E", "F", "I", "W"]

[tool.ruff.mccabe]
# FIXME the following exceed this limit
# .backend.io.s_read_excel: 26
# .backend.jdbc.JDBCBackend.item_get_elements: 19
# .core.scenario.Scenario.add_set: 17
max-complexity = 15

[tool.setuptools.packages]
find = {}

Expand Down

0 comments on commit 565a546

Please sign in to comment.