Skip to content

Commit 0c2df4c

Browse files
committed
👷 Use ruff to lint
1 parent a53cf09 commit 0c2df4c

12 files changed

+68
-46
lines changed

‎.pre-commit-config.yaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
repos:
2-
- repo: https://github.com/asottile/pyupgrade
3-
rev: v3.3.1
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.4.2
44
hooks:
5-
- id: pyupgrade
6-
args: [--py310-plus]
7-
- repo: https://github.com/psf/black
8-
rev: 23.3.0
5+
- id: ruff
6+
- id: ruff-format
7+
- repo: https://github.com/python-jsonschema/check-jsonschema
8+
rev: 0.28.2
99
hooks:
10-
- id: black
11-
language_version: python3
12-
- repo: https://github.com/pycqa/flake8
13-
rev: 6.0.0
14-
hooks:
15-
- id: flake8
16-
additional_dependencies: [flake8-bugbear==23.1.14]
10+
- id: check-github-workflows

‎.ruff.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fix = true
2+
show-fixes = true
3+
output-format = "full"
4+
5+
[format]
6+
docstring-code-format = true
7+
8+
[lint]
9+
ignore = []
10+
select = [
11+
"B", # flake8-bugbear
12+
"E", # pycodestyle error
13+
"F", # pyflakes
14+
"I", # isort
15+
"UP", # pyupgrade
16+
"W", # pycodestyle warning
17+
]
18+
19+
[lint.isort]
20+
section-order = ["future", "standard-library", "testing", "science", "corrai", "third-party", "first-party", "local-folder"]
21+
22+
[lint.isort.sections]
23+
testing = ["pytest"]
24+
science = ["numpy", "pandas", "OMPython"]
25+
corrai = ["corrai"]

‎modelitool/combitabconvert.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime as dt
2+
23
import pandas as pd
34

45

‎modelitool/corrai_connector.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import pandas as pd
21
import numpy as np
2+
import pandas as pd
3+
34
from corrai.base.parameter import Parameter
5+
46
from modelitool.simulate import OMModel
57

68

‎modelitool/simulate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
from pathlib import Path
44

55
import pandas as pd
6-
from OMPython import ModelicaSystem
7-
from OMPython import OMCSessionZMQ
6+
from OMPython import ModelicaSystem, OMCSessionZMQ
7+
88
from corrai.base.model import Model
99

10-
from modelitool.combitabconvert import df_to_combitimetable
11-
from modelitool.combitabconvert import seconds_to_datetime
10+
from modelitool.combitabconvert import df_to_combitimetable, seconds_to_datetime
1211

1312

1413
class OMModel(Model):

‎modelitool/weather.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import requests
21
import json
2+
33
import pandas as pd
4+
5+
import requests
6+
47
from .combitabconvert import get_dymo_time_index
58

69
# TODO

‎setup.cfg

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[flake8]
2-
max-line-length = 88
3-
extend-ignore = E203,B028
4-
51
[bumpversion]
62
current_version = 0.1.0
73
commit = True
@@ -15,4 +11,4 @@ replace = version="{new_version}"
1511

1612
[bumpversion:file:corrai/__init__.py]
1713
search = __version__ = "{current_version}"
18-
replace = __version__ = "{new_version}"
14+
replace = __version__ = "{new_version}"

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
"""Modelitool"""
33

4-
from setuptools import setup, find_packages
4+
from setuptools import find_packages, setup
55

66
# Get the long description from the README file
77
with open("README.md", encoding="utf-8") as f:

‎tests/test_combitabconvert.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import pandas as pd
2-
3-
from modelitool.combitabconvert import df_to_combitimetable
4-
from modelitool.combitabconvert import seconds_to_datetime
5-
from modelitool.combitabconvert import datetime_to_seconds
6-
71
from datetime import timedelta
82

93
import pytest
104

5+
import pandas as pd
6+
7+
from modelitool.combitabconvert import (
8+
datetime_to_seconds,
9+
df_to_combitimetable,
10+
seconds_to_datetime,
11+
)
12+
1113

1214
class TestCombitabconvert:
1315
def test_get_dymo_time_index(self):

‎tests/test_corrai_connector.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import numpy as np
2-
import pandas as pd
31
from pathlib import Path
42

53
import pytest
64

7-
from sklearn.metrics import mean_squared_error, mean_absolute_error
8-
from modelitool.simulate import OMModel
5+
import numpy as np
6+
import pandas as pd
7+
98
from corrai.base.parameter import Parameter
109

11-
from modelitool.corrai_connector import ModelicaFunction
10+
from sklearn.metrics import mean_absolute_error, mean_squared_error
1211

12+
from modelitool.corrai_connector import ModelicaFunction
13+
from modelitool.simulate import OMModel
1314

1415
PACKAGE_DIR = Path(__file__).parent / "TestLib"
1516

‎tests/test_simulate.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from pathlib import Path
2-
import numpy as np
3-
import pytest
4-
5-
from modelitool.simulate import OMModel
6-
from modelitool.simulate import load_library, library_contents
72

3+
import pytest
84

5+
import numpy as np
96
import pandas as pd
107

8+
from modelitool.simulate import OMModel, library_contents, load_library
9+
1110
PACKAGE_DIR = Path(__file__).parent / "TestLib"
1211

1312

@@ -72,8 +71,8 @@ def test_load_and_print_library(self, simul, capfd):
7271
try:
7372
load_library(libpath)
7473
assert True
75-
except ValueError:
76-
raise AssertionError("library not loaded, failed test")
74+
except ValueError as exc:
75+
raise AssertionError("library not loaded, failed test") from exc
7776

7877
library_contents(libpath)
7978
out, err = capfd.readouterr()

‎tox.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ deps =
2222
pre-commit
2323
skip_install = true
2424
commands =
25-
pre-commit run pyupgrade --all-files --show-diff-on-failure
26-
pre-commit run black --all-files --show-diff-on-failure
27-
pre-commit run flake8 --all-files --show-diff-on-failure
25+
pre-commit run ruff --all-files --show-diff-on-failure
26+
pre-commit run ruff-format --all-files --show-diff-on-failure
27+
pre-commit run check-github-workflows --all-files --show-diff-on-failure

0 commit comments

Comments
 (0)