diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 75ca1e2..fe470a1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,17 +5,6 @@ on: tags: [ "*" ] pull_request: jobs: - lint: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - run: python -m pip install --upgrade pip wheel - - run: pip install tox - - run: tox -elint tests: name: ${{ matrix.name }} runs-on: ubuntu-latest @@ -24,7 +13,7 @@ jobs: matrix: include: - { name: '3.10', python: '3.10', tox: py310 } - - { name: '3.12', python: '3.12', tox: py312 } + - { name: '3.11', python: '3.11', tox: py311 } - { name: 'min', python: '3.10', tox: min } steps: - name: "Set up OpenModelica Compiler" @@ -63,8 +52,20 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml + # this duplicates pre-commit.ci, so only run it on tags + # it guarantees that linting is passing prior to a release + lint-pre-release: + if: startsWith(github.ref, 'refs/tags') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.0.0 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + - run: python -m pip install tox + - run: python -m tox -e lint release: - needs: [ lint, tests ] + needs: [ tests, lint-pre-release ] name: PyPI release if: startsWith(github.ref, 'refs/tags') runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9df0612..e7c0443 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,19 +1,10 @@ -ci: - skip: [pip-compile] - repos: -- repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.2 hooks: - - id: pyupgrade - args: [--py310-plus] -- repo: https://github.com/psf/black - rev: 23.3.0 + - id: ruff + - id: ruff-format +- repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.2 hooks: - - id: black - language_version: python3 -- repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - additional_dependencies: [flake8-bugbear==23.1.14] \ No newline at end of file + - id: check-github-workflows diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..417332d --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,25 @@ +fix = true +show-fixes = true +output-format = "full" + +[format] +docstring-code-format = true + +[lint] +ignore = [] +select = [ + "B", # flake8-bugbear + "E", # pycodestyle error + "F", # pyflakes + "I", # isort + "UP", # pyupgrade + "W", # pycodestyle warning +] + +[lint.isort] +section-order = ["future", "standard-library", "testing", "science", "corrai", "third-party", "first-party", "local-folder"] + +[lint.isort.sections] +testing = ["pytest"] +science = ["numpy", "pandas", "OMPython"] +corrai = ["corrai"] diff --git a/modelitool/combitabconvert.py b/modelitool/combitabconvert.py index 5a22261..d03f00a 100644 --- a/modelitool/combitabconvert.py +++ b/modelitool/combitabconvert.py @@ -1,4 +1,5 @@ import datetime as dt + import pandas as pd diff --git a/modelitool/corrai_connector.py b/modelitool/corrai_connector.py index 249c6f1..fdf77fa 100644 --- a/modelitool/corrai_connector.py +++ b/modelitool/corrai_connector.py @@ -1,6 +1,8 @@ -import pandas as pd import numpy as np +import pandas as pd + from corrai.base.parameter import Parameter + from modelitool.simulate import OMModel diff --git a/modelitool/simulate.py b/modelitool/simulate.py index 595ae99..06fe47f 100644 --- a/modelitool/simulate.py +++ b/modelitool/simulate.py @@ -3,12 +3,11 @@ from pathlib import Path import pandas as pd -from OMPython import ModelicaSystem -from OMPython import OMCSessionZMQ +from OMPython import ModelicaSystem, OMCSessionZMQ + from corrai.base.model import Model -from modelitool.combitabconvert import df_to_combitimetable -from modelitool.combitabconvert import seconds_to_datetime +from modelitool.combitabconvert import df_to_combitimetable, seconds_to_datetime class OMModel(Model): diff --git a/modelitool/weather.py b/modelitool/weather.py index acc32f7..4085690 100644 --- a/modelitool/weather.py +++ b/modelitool/weather.py @@ -1,6 +1,9 @@ -import requests import json + import pandas as pd + +import requests + from .combitabconvert import get_dymo_time_index # TODO diff --git a/requirements/install-min.txt b/requirements/install-min.txt index 71cdc8a..39e5f05 100644 --- a/requirements/install-min.txt +++ b/requirements/install-min.txt @@ -1,4 +1,4 @@ pandas>=1.5.0 numpy>=1.17.3 -OMPython>=3.4.0 -corrai>=0.3.0 \ No newline at end of file +OMPython>=3.5.2 +corrai>=0.3.0 diff --git a/setup.cfg b/setup.cfg index 8a7ac44..f395107 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,3 @@ -[flake8] -max-line-length = 88 -extend-ignore = E203,B028 - [bumpversion] current_version = 0.1.0 commit = True @@ -15,4 +11,4 @@ replace = version="{new_version}" [bumpversion:file:corrai/__init__.py] search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" \ No newline at end of file +replace = __version__ = "{new_version}" diff --git a/setup.py b/setup.py index 3dbbcab..20d084d 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """Modelitool""" -from setuptools import setup, find_packages +from setuptools import find_packages, setup # Get the long description from the README file with open("README.md", encoding="utf-8") as f: @@ -31,7 +31,7 @@ install_requires=[ "pandas>=1.5.0", "numpy>=1.17.3", - "OMPython>=3.4.0", + "OMPython>=3.5.2", "corrai>=0.3.0", ], packages=find_packages(exclude=["tests*"]), diff --git a/tests/test_combitabconvert.py b/tests/test_combitabconvert.py index 46fd569..8c94a44 100644 --- a/tests/test_combitabconvert.py +++ b/tests/test_combitabconvert.py @@ -1,13 +1,15 @@ -import pandas as pd - -from modelitool.combitabconvert import df_to_combitimetable -from modelitool.combitabconvert import seconds_to_datetime -from modelitool.combitabconvert import datetime_to_seconds - from datetime import timedelta import pytest +import pandas as pd + +from modelitool.combitabconvert import ( + datetime_to_seconds, + df_to_combitimetable, + seconds_to_datetime, +) + class TestCombitabconvert: def test_get_dymo_time_index(self): diff --git a/tests/test_corrai_connector.py b/tests/test_corrai_connector.py index 571c55c..cf7467a 100644 --- a/tests/test_corrai_connector.py +++ b/tests/test_corrai_connector.py @@ -1,15 +1,16 @@ -import numpy as np -import pandas as pd from pathlib import Path import pytest -from sklearn.metrics import mean_squared_error, mean_absolute_error -from modelitool.simulate import OMModel +import numpy as np +import pandas as pd + from corrai.base.parameter import Parameter -from modelitool.corrai_connector import ModelicaFunction +from sklearn.metrics import mean_absolute_error, mean_squared_error +from modelitool.corrai_connector import ModelicaFunction +from modelitool.simulate import OMModel PACKAGE_DIR = Path(__file__).parent / "TestLib" diff --git a/tests/test_simulate.py b/tests/test_simulate.py index c1927ab..117d295 100644 --- a/tests/test_simulate.py +++ b/tests/test_simulate.py @@ -1,13 +1,12 @@ from pathlib import Path -import numpy as np -import pytest - -from modelitool.simulate import OMModel -from modelitool.simulate import load_library, library_contents +import pytest +import numpy as np import pandas as pd +from modelitool.simulate import OMModel, library_contents, load_library + PACKAGE_DIR = Path(__file__).parent / "TestLib" @@ -72,8 +71,8 @@ def test_load_and_print_library(self, simul, capfd): try: load_library(libpath) assert True - except ValueError: - raise AssertionError("library not loaded, failed test") + except ValueError as exc: + raise AssertionError("library not loaded, failed test") from exc library_contents(libpath) out, err = capfd.readouterr() diff --git a/tox.ini b/tox.ini index 14b2f6c..8f9f981 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint,py310,py311,py312,min +envlist = lint,py310,py311,min skip_missing_interpreters = True [testenv] @@ -22,6 +22,6 @@ deps = pre-commit skip_install = true commands = - pre-commit run pyupgrade --all-files --show-diff-on-failure - pre-commit run black --all-files --show-diff-on-failure - pre-commit run flake8 --all-files --show-diff-on-failure \ No newline at end of file + pre-commit run ruff --all-files --show-diff-on-failure + pre-commit run ruff-format --all-files --show-diff-on-failure + pre-commit run check-github-workflows --all-files --show-diff-on-failure