Skip to content

Commit

Permalink
👷 Use ruff to lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Jun 25, 2024
1 parent a53cf09 commit 0c2df4c
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 46 deletions.
20 changes: 7 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
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]
- id: check-github-workflows
25 changes: 25 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions modelitool/combitabconvert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime as dt

import pandas as pd


Expand Down
4 changes: 3 additions & 1 deletion modelitool/corrai_connector.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
7 changes: 3 additions & 4 deletions modelitool/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion modelitool/weather.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import requests
import json

import pandas as pd

import requests

from .combitabconvert import get_dymo_time_index

# TODO
Expand Down
6 changes: 1 addition & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[flake8]
max-line-length = 88
extend-ignore = E203,B028

[bumpversion]
current_version = 0.1.0
commit = True
Expand All @@ -15,4 +11,4 @@ replace = version="{new_version}"

[bumpversion:file:corrai/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"
replace = __version__ = "{new_version}"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
14 changes: 8 additions & 6 deletions tests/test_combitabconvert.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
11 changes: 6 additions & 5 deletions tests/test_corrai_connector.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
13 changes: 6 additions & 7 deletions tests/test_simulate.py
Original file line number Diff line number Diff line change
@@ -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"


Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 0c2df4c

Please sign in to comment.