Skip to content

Commit

Permalink
A few project configuration changes
Browse files Browse the repository at this point in the history
* Add ruff as a dev dependency
* Fix ruff warning about deprecated `extend-ignore` setting
* Activate ruff pre-commit hook for notebooks as well
* Sync versions between .pre-commit-config.yaml and pyproject.toml
  • Loading branch information
alihamdan committed Jul 26, 2023
1 parent 4de7a62 commit 3dde16b
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 32 deletions.
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ repos:
hooks:
- id: poetry-check
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.7.0 # keep in sync with pyproject.toml
hooks:
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.280
rev: v0.0.280 # keep in sync with pyproject.toml
hooks:
- id: ruff
types_or: [ python, pyi, jupyter ]
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.15.0
hooks:
- id: blacken-docs
entry: bash -c "blacken-docs -l 90 $(find doc/ -name '*.md')"
args: [ -l 90 ]
additional_dependencies: [ black==23.7.0 ]
additional_dependencies: [ black==23.7.0 ] # keep in sync with black above
101 changes: 75 additions & 26 deletions doc/notebooks/Advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@
"outputs": [
{
"data": {
"text/plain": "array([243.66463933, 232.20612714, 233.55093129]) <Unit('volt')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[243.66463933130166 232.2061271436693 233.5509312888294]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[243.66463933130166 232.2061271436693 233.5509312888294]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt}$"
],
"text/plain": [
"array([243.66463933, 232.20612714, 233.55093129]) <Unit('volt')>"
]
},
"execution_count": 4,
"metadata": {},
Expand Down Expand Up @@ -221,9 +227,15 @@
"outputs": [
{
"data": {
"text/plain": "array([243.08225748, 232.46046866, 233.62854073]) <Unit('volt')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[243.08225748385007 232.46046865587596 233.62854072949668]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[243.08225748385007 232.46046865587596 233.62854072949668]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt}$"
],
"text/plain": [
"array([243.08225748, 232.46046866, 233.62854073]) <Unit('volt')>"
]
},
"execution_count": 6,
"metadata": {},
Expand Down Expand Up @@ -260,9 +272,15 @@
"outputs": [
{
"data": {
"text/plain": "array([-2757.8035271+0.j, 0. +0.j, 0. +0.j]) <Unit('volt_ampere')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[-2757.8035271+0.j 0. +0.j 0. +0.j]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt_ampere</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt\\_ampere}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[-2757.8035271+0.j 0. +0.j 0. +0.j]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt_ampere</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt\\_ampere}$"
],
"text/plain": [
"array([-2757.8035271+0.j, 0. +0.j, 0. +0.j]) <Unit('volt_ampere')>"
]
},
"execution_count": 7,
"metadata": {},
Expand Down Expand Up @@ -343,9 +361,15 @@
"outputs": [
{
"data": {
"text/plain": "array([239.5133208 , 230.2108052 , 237.59184615]) <Unit('volt')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[239.51332079629023 230.21080520340482 237.59184615484196]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[239.51332079629023 230.21080520340482 237.59184615484196]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt}$"
],
"text/plain": [
"array([239.5133208 , 230.2108052 , 237.59184615]) <Unit('volt')>"
]
},
"execution_count": 9,
"metadata": {},
Expand Down Expand Up @@ -381,9 +405,16 @@
"outputs": [
{
"data": {
"text/plain": "array([-2566.23768012+3068.29336425j, 0. +0.j ,\n 0. +0.j ]) <Unit('volt_ampere')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[-2566.23768012+3068.29336425j 0. +0.j<br> 0. +0.j ]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt_ampere</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt\\_ampere}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[-2566.23768012+3068.29336425j 0. +0.j<br> 0. +0.j ]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt_ampere</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt\\_ampere}$"
],
"text/plain": [
"array([-2566.23768012+3068.29336425j, 0. +0.j ,\n",
" 0. +0.j ]) <Unit('volt_ampere')>"
]
},
"execution_count": 10,
"metadata": {},
Expand All @@ -406,9 +437,15 @@
"outputs": [
{
"data": {
"text/plain": "array([4000., 0., 0.]) <Unit('volt_ampere')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[4000.0 0.0 0.0]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt_ampere</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt\\_ampere}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[4000.0 0.0 0.0]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt_ampere</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix} & & \\end{pmatrix}\\ \\mathrm{volt\\_ampere}$"
],
"text/plain": [
"array([4000., 0., 0.]) <Unit('volt_ampere')>"
]
},
"execution_count": 11,
"metadata": {},
Expand Down Expand Up @@ -448,14 +485,14 @@
"# Connect a new bus to the network\n",
"new_bus = Bus(id=\"new_bus\", phases=\"abcn\")\n",
"new_load = PowerLoad(id=\"new_load\", bus=new_bus, phases=\"an\", powers=[6e3])\n",
"lp_S_AL_240 = LineParameters.from_name_lv(\"S_AL_240\")\n",
"lp_s_al_240 = LineParameters.from_name_lv(\"S_AL_240\")\n",
"new_line = Line(\n",
" id=\"new_line\",\n",
" bus1=bus2,\n",
" bus2=new_bus,\n",
" phases=\"abcn\",\n",
" ground=ground,\n",
" parameters=lp_S_AL_240,\n",
" parameters=lp_s_al_240,\n",
" length=0.5,\n",
")"
]
Expand All @@ -479,7 +516,9 @@
"outputs": [
{
"data": {
"text/plain": "Bus(id='new_bus', phases='abcn')"
"text/plain": [
"Bus(id='new_bus', phases='abcn')"
]
},
"execution_count": 13,
"metadata": {},
Expand All @@ -502,7 +541,9 @@
"outputs": [
{
"data": {
"text/plain": "PowerLoad(id='new_load', phases='an', bus='new_bus')"
"text/plain": [
"PowerLoad(id='new_load', phases='an', bus='new_bus')"
]
},
"execution_count": 14,
"metadata": {},
Expand All @@ -525,7 +566,9 @@
"outputs": [
{
"data": {
"text/plain": "Line(id='new_line', phases1='abcn', phases2='abcn', bus1='bus2', bus2='new_bus')"
"text/plain": [
"Line(id='new_line', phases1='abcn', phases2='abcn', bus1='bus2', bus2='new_bus')"
]
},
"execution_count": 15,
"metadata": {},
Expand Down Expand Up @@ -555,9 +598,15 @@
"outputs": [
{
"data": {
"text/plain": "array([227.43645429]) <Unit('volt')>",
"text/html": "<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[227.43645429483067]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>",
"text/latex": "$\\begin{pmatrix}\\end{pmatrix}\\ \\mathrm{volt}$"
"text/html": [
"<table><tbody><tr><th>Magnitude</th><td style='text-align:left;'><pre>[227.43645429483067]</pre></td></tr><tr><th>Units</th><td style='text-align:left;'>volt</td></tr></tbody></table>"
],
"text/latex": [
"$\\begin{pmatrix}\\end{pmatrix}\\ \\mathrm{volt}$"
],
"text/plain": [
"array([227.43645429]) <Unit('volt')>"
]
},
"execution_count": 16,
"metadata": {},
Expand Down
28 changes: 27 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ coverage = { version = "^7.0.5", extras = ["toml"] }

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.0.0"
black = { version = "^23.1.0", extras = ["jupyter"] }
black = { version = "==23.7.0", extras = ["jupyter"] } # keep in sync with .pre-commit-config.yaml
ruff = "==0.0.280" # keep in sync with .pre-commit-config.yaml

[tool.poetry.group.doc.dependencies]
sphinx = "^7.0.1"
Expand Down Expand Up @@ -84,7 +85,7 @@ show-fixes = true
namespace-packages = ["roseau"]
select = ["E", "F", "C90", "W", "B", "UP", "I", "RUF100", "TID", "SIM", "PT", "PIE", "N", "C4", "NPY"]
unfixable = ["B"]
extend-ignore = ["E501", "B024", "N818"]
ignore = ["E501", "B024", "N818"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
Expand All @@ -95,6 +96,9 @@ parametrize-values-type = "tuple"
[tool.ruff.mccabe]
max-complexity = 15

[tool.ruff.per-file-ignores]
"*.ipynb" = ["E402", "F403", "F405", "B018"]

[tool.coverage.run]
branch = true
omit = ["roseau/load_flow/__about__.py"]
Expand Down

0 comments on commit 3dde16b

Please sign in to comment.