Skip to content

Commit

Permalink
Add more ruff checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alihamdan committed Feb 21, 2023
1 parent e4716a9 commit f1cd89f
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
.vscode/*.json linguist-language=jsonc
44 changes: 44 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {"cwd": "${workspaceFolder}"},
"presentation": {
"showReuseMessage": true,
"clear": true
},
"tasks": [
{
"label": "Build docs",
"detail": "Build the docs using Sphinx.",
"type": "shell",
"command": "make -C doc html",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"presentation": {
"reveal": "silent",
"focus": true,
}
},
{
"label": "Open docs",
"detail": "Open the docs in the browser.",
"type": "shell",
"command": "open build/html/index.html",
"presentation": {
"reveal": "never",
"close": true,
"focus": false,
"panel": "dedicated",
},
"group": {
"kind": "build",
"isDefault": true
},
"isBackground": true,
},
],
}
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ target-version = ["py39", "py310", "py311"]
[tool.ruff]
line-length = 120
target-version = "py39"
show-fixes = true
select = ["E", "F", "C90", "W", "B", "UP", "I", "RUF100"]
unfixable = ["B"]
extend-ignore = ["E501", "B024"]


[tool.ruff.mccabe]
max-complexity = 15
Expand Down
2 changes: 1 addition & 1 deletion roseau/load_flow/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This module contains the exceptions used by Roseau Load Flow.
"""
import unicodedata
from enum import auto, Enum
from enum import Enum, auto
from typing import Union

from roseau.load_flow.typing import Self
Expand Down
2 changes: 1 addition & 1 deletion roseau/load_flow/models/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import warnings
from abc import ABC
from typing import Any, ClassVar, NoReturn, Optional, TYPE_CHECKING, TypeVar, Union
from typing import TYPE_CHECKING, Any, ClassVar, NoReturn, Optional, TypeVar, Union

import shapely
from shapely.geometry import shape
Expand Down
12 changes: 6 additions & 6 deletions roseau/load_flow/models/lines/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
from roseau.load_flow.typing import Id, JsonDict, Self
from roseau.load_flow.units import Q_, ureg
from roseau.load_flow.utils import (
ConductorType,
CX,
EPSILON_0,
EPSILON_R,
Identifiable,
IsolationType,
JsonMixin,
LineModel,
LineType,
MU_0,
OMEGA,
PI,
RHO,
TAN_D,
ConductorType,
Identifiable,
IsolationType,
JsonMixin,
LineModel,
LineType,
)

logger = logging.getLogger(__name__)
Expand Down
22 changes: 11 additions & 11 deletions roseau/load_flow/models/loads/flexible_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from roseau.load_flow.exceptions import RoseauLoadFlowException, RoseauLoadFlowExceptionCode
from roseau.load_flow.typing import JsonDict, Self, ControlType, ProjectionType
from roseau.load_flow.typing import ControlType, JsonDict, ProjectionType, Self
from roseau.load_flow.units import Q_, ureg
from roseau.load_flow.utils import JsonMixin

Expand Down Expand Up @@ -34,9 +34,9 @@ def __init__(
The type of the control:
* ``"constant"``: no control is applied;
* ``"p_max_u_production"``: control the maximum production active power of the
load (inverter) based on the voltage :math:`P^{\max}_{\mathrm{prod}}(U)`;
load (inverter) based on the voltage :math:`P^{\\max}_{\\mathrm{prod}}(U)`;
* ``"p_max_u_consumption"``: control the maximum consumption active power of the
load based on the voltage :math:`P^{\max}_{\mathrm{cons}}(U)`;
load based on the voltage :math:`P^{\\max}_{\\mathrm{cons}}(U)`;
* ``"q_u"``: control the reactive power based on the voltage :math:`Q(U)`.
u_min:
Expand Down Expand Up @@ -172,12 +172,12 @@ def p_max_u_production(cls, u_up: float, u_max: float, alpha: float = DEFAULT_AL
u_up:
The voltage norm that triggers the control. A voltage higher than this value signals to
the controller to start to reduce the production active power. On the figure, a normalised version
:math:`U^{\mathrm{up}\,\mathrm{norm.}}` is used.
:math:`U^{\\mathrm{up}\\,\\mathrm{norm.}}` is used.
u_max:
The maximum norm voltage i.e. the one the control reached its maximum action. A voltage
higher than this value signals to the controller to set the production active power
to its minimal value. On the figure, a normalised version :math:`U^{\max\,\mathrm{norm.}}` is used.
to its minimal value. On the figure, a normalised version :math:`U^{\\max\\,\\mathrm{norm.}}` is used.
alpha:
A factor used to soften the control function (soft clip) to make it more
Expand All @@ -202,12 +202,12 @@ def p_max_u_consumption(cls, u_min: float, u_down: float, alpha: float = DEFAULT
u_min:
The minimum voltage norm i.e. the one the control reached its maximum action. A voltage
lower than this value signals to the controller to set the consumption active power
to its minimal value. On the figure, a normalised version :math:`U^{\min\,\mathrm{norm.}}` is used.
to its minimal value. On the figure, a normalised version :math:`U^{\\min\\,\\mathrm{norm.}}` is used.
u_down:
The voltage norm that triggers the control. A voltage lower than this value signals to
the controller to start to reduce the consumption active power. On the figure, a normalised version
:math:`U^{\mathrm{down}\,\mathrm{norm.}}` is used.
:math:`U^{\\mathrm{down}\\,\\mathrm{norm.}}` is used.
alpha:
A factor used to soften the control function (soft clip) to make it more
Expand All @@ -232,22 +232,22 @@ def q_u(cls, u_min: float, u_down: float, u_up: float, u_max: float, alpha: floa
u_min:
The minimum voltage norm i.e. the one the control reached its maximum action. A voltage
lower than this value signals to the controller to set the reactive power to its
maximal capacitive value. On the figure, a normalised version :math:`U^{\min\,\mathrm{norm.}}` is used.
maximal capacitive value. On the figure, a normalised version :math:`U^{\\min\\,\\mathrm{norm.}}` is used.
u_down:
The voltage that triggers the capacitive reactive power control. A voltage lower
than this value signals to the controller to start to increase the capacitive
reactive power. On the figure, a normalised version :math:`U^{\mathrm{down}\,\mathrm{norm.}}` is used.
reactive power. On the figure, a normalised version :math:`U^{\\mathrm{down}\\,\\mathrm{norm.}}` is used.
u_up:
The voltage that triggers the inductive reactive power control. A voltage higher
than this value signals to the controller to start to increase the inductive
reactive power. On the figure, a normalised version :math:`U^{\mathrm{up}\,\mathrm{norm.}}` is used.
reactive power. On the figure, a normalised version :math:`U^{\\mathrm{up}\\,\\mathrm{norm.}}` is used.
u_max:
The minimum voltage i.e. the one the control reached its maximum action. A voltage
lower than this value signals to the controller to set the reactive power to its
maximal inductive value. On the figure, a normalised version :math:`U^{\max\,\mathrm{norm.}}` is used.
maximal inductive value. On the figure, a normalised version :math:`U^{\\max\\,\\mathrm{norm.}}` is used.
alpha:
A factor used to soften the control function (soft clip) to make it more
Expand Down
2 changes: 1 addition & 1 deletion roseau/load_flow/models/potential_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def to_dict(self) -> JsonDict:
elif isinstance(e, Ground):
res["ground"] = e.id
else:
assert False, f"Unexpected element type {type(e).__name__}"
raise AssertionError(f"Unexpected element type {type(e).__name__}")
return res

def results_from_dict(self, data: JsonDict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion roseau/load_flow/models/tests/test_flexible_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import pytest

from roseau.load_flow import (
Q_,
Control,
FlexibleParameter,
Projection,
Q_,
RoseauLoadFlowException,
RoseauLoadFlowExceptionCode,
)
Expand Down
2 changes: 1 addition & 1 deletion roseau/load_flow/models/transformers/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def from_name(cls, name: str, windings: str) -> Self:
except ValueError:
msg = f"The transformer type name does not follow the syntax rule. {name!r} was provided."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_TYPE_NAME_SYNTAX)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_TYPE_NAME_SYNTAX) from None
else:
return cls(name, windings, 20000, 400, sn * 1e3, 460, 2.3 / 100, 2350, 4 / 100)
else:
Expand Down
2 changes: 1 addition & 1 deletion roseau/load_flow/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
This module contains utility classes and functions for Roseau Load Flow.
"""
from roseau.load_flow.utils.constants import CX, DELTA_P, EPSILON_0, EPSILON_R, F, MU_0, MU_R, OMEGA, PI, RHO, TAN_D
from roseau.load_flow.utils.constants import CX, DELTA_P, EPSILON_0, EPSILON_R, MU_0, MU_R, OMEGA, PI, RHO, TAN_D, F
from roseau.load_flow.utils.mixins import Identifiable, JsonMixin
from roseau.load_flow.utils.types import BranchType, ConductorType, IsolationType, LineModel, LineType, TransformerType

Expand Down
4 changes: 2 additions & 2 deletions roseau/load_flow/utils/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from enum import auto, Enum, unique
from enum import Enum, auto, unique
from typing import Optional

import regex
Expand Down Expand Up @@ -421,7 +421,7 @@ def from_string(cls, string: str) -> Self:
except AttributeError:
msg = f"The string {string!r} cannot be converted into a TransformerType."
logger.error(msg)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_TRANSFORMER_TYPE)
raise RoseauLoadFlowException(msg=msg, code=RoseauLoadFlowExceptionCode.BAD_TRANSFORMER_TYPE) from None

@property
def windings(self) -> tuple[str, str]:
Expand Down

0 comments on commit f1cd89f

Please sign in to comment.