Skip to content

Commit

Permalink
Ruff formatting + checks (#116)
Browse files Browse the repository at this point in the history
* Ruff formatting + checks
- add ruff ruff settings to pyproject.toml
- use ruff gh actions
- add python 3.12, remove python 3.8
- fix most ruff issues in code base (see pyproject.toml for ignore list).

* Use ruff to format and lint (#114)

* Use ruff to format and lint, fix all issues that came up.

* Git blame: ignore ruff style changes

* Looks like ruff trivialized test_import

* Do not exclude examples from ruff

* Remove unused computation in StripAreaSink.changetrace

* Add ruff format --check in linting step

* Also format the examples

* Add examples ruff format to git-blame-ignore

* more ruff after merge

* this file shouldnt be in this PR.

* speed up building docs using autoapi

* formatting

* more formatting

---------

Co-authored-by: Huite <huitebootsma@gmail.com>
  • Loading branch information
dbrakenhoff and Huite authored Sep 26, 2024
1 parent fd0d1d3 commit 202b5b6
Show file tree
Hide file tree
Showing 59 changed files with 1,096 additions and 755 deletions.
6 changes: 5 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Migrate code style to black
998b86fc128e35f1506e3d4facb169c558679bde
998b86fc128e35f1506e3d4facb169c558679bde

# Migrate code style to ruff
a11f92ff2732d7fdc548559f15f009e4a3d5ea7a
571e4b5af45bd1ca6f025dd883b9ea800acb4aef
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -30,13 +30,14 @@ jobs:
python -m pip install --upgrade pip
pip install -e .[ci]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=80 --statistics
- name: ruff-lint
uses: chartboost/ruff-action@v1

- name: ruff-format
uses: chartboost/ruff-action@v1
with:
args: "format --check"

- name: Run tests
run: |
py.test ./tests
Expand Down
1 change: 1 addition & 0 deletions docs/00tutorials/tutorial0_well_single_layer_aquifer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"outputs": [],
"source": [
"import numpy as np # import numpy package\n",
"\n",
"import timml as tml # import timml package"
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/00tutorials/tutorial1_well_multi_layer_aquifer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import timml as tml"
]
},
Expand Down
73 changes: 37 additions & 36 deletions docs/03examples/BuildingPit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import timml as tml"
]
},
Expand Down Expand Up @@ -59,8 +60,8 @@
"metadata": {},
"outputs": [],
"source": [
"l = 40.0 # length building pit in m\n",
"b = 30.0 # width building pit in m\n",
"length = 40.0 # length building pit in m\n",
"width = 30.0 # width building pit in m\n",
"\n",
"h_bem = -6.21 # m\n",
"offset = 5.0 # distance groundwater extraction element from sheetpiles in m"
Expand All @@ -73,11 +74,11 @@
"outputs": [],
"source": [
"xy = [\n",
" (-l / 2, -b / 2),\n",
" (l / 2, -b / 2),\n",
" (l / 2, b / 2),\n",
" (-l / 2, b / 2),\n",
" (-l / 2, -b / 2),\n",
" (-length / 2, -width / 2),\n",
" (length / 2, -width / 2),\n",
" (length / 2, width / 2),\n",
" (-length / 2, width / 2),\n",
" (-length / 2, -width / 2),\n",
"]"
]
},
Expand Down Expand Up @@ -211,28 +212,28 @@
"\n",
"tml.HeadLineSink(\n",
" ml,\n",
" x1=-l / 2 + offset,\n",
" y1=b / 2 - offset,\n",
" x2=l / 2 - offset,\n",
" y2=b / 2 - offset,\n",
" x1=-length / 2 + offset,\n",
" y1=width / 2 - offset,\n",
" x2=length / 2 - offset,\n",
" y2=width / 2 - offset,\n",
" hls=h_bem,\n",
" layers=np.arange(last_lay_dw + 1),\n",
")\n",
"tml.HeadLineSink(\n",
" ml,\n",
" x1=-l / 2 + offset,\n",
" x1=-length / 2 + offset,\n",
" y1=0,\n",
" x2=l / 2 - offset,\n",
" x2=length / 2 - offset,\n",
" y2=0,\n",
" hls=h_bem,\n",
" layers=np.arange(last_lay_dw + 1),\n",
")\n",
"tml.HeadLineSink(\n",
" ml,\n",
" x1=-l / 2 + offset,\n",
" y1=-b / 2 + offset,\n",
" x2=l / 2 - offset,\n",
" y2=-b / 2 + offset,\n",
" x1=-length / 2 + offset,\n",
" y1=-width / 2 + offset,\n",
" x2=length / 2 - offset,\n",
" y2=-width / 2 + offset,\n",
" hls=h_bem,\n",
" layers=np.arange(last_lay_dw + 1),\n",
")\n",
Expand All @@ -248,7 +249,7 @@
"\n",
"print(\"\\nDischarge =\", np.round(Qtot.sum(), 2), \"m^3/dag\")\n",
"\n",
"y = np.linspace(-b / 2 - 25, b / 2 + 1100, 201)\n",
"y = np.linspace(-width / 2 - 25, width / 2 + 1100, 201)\n",
"hl = ml.headalongline(np.zeros(201), y, layers=[0])\n",
"y_5cm = np.interp(\n",
" -0.05, ml.headalongline(np.zeros(201), y, layers=0).squeeze(), y, right=np.nan\n",
Expand Down Expand Up @@ -298,7 +299,7 @@
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(0.0, l / 2 + 1100, 201)\n",
"x = np.linspace(0.0, length / 2 + 1100, 201)\n",
"hl = ml.headalongline(x, np.zeros(201), layers=[last_lay_dw, last_lay_dw + 1])"
]
},
Expand Down Expand Up @@ -337,7 +338,7 @@
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(-l / 2 - 25, 0.0, 201)\n",
"x = np.linspace(-length / 2 - 25, 0.0, 201)\n",
"hl = ml.headalongline(x, np.zeros(201), layers=[last_lay_dw, last_lay_dw + 1])"
]
},
Expand Down Expand Up @@ -378,7 +379,7 @@
"source": [
"xoffset = 50\n",
"zoffset = 15\n",
"x1, x2, y1, y2 = [-l / 2 - xoffset, 0.0, 0, 0]\n",
"x1, x2, y1, y2 = [-length / 2 - xoffset, 0.0, 0, 0]\n",
"nudge = 1e-6\n",
"n = 301"
]
Expand Down Expand Up @@ -581,29 +582,29 @@
"\n",
"tml.HeadLineSink(\n",
" ml,\n",
" x1=-l / 2 + offset,\n",
" y1=b / 2 - offset,\n",
" x2=l / 2 - offset,\n",
" y2=b / 2 - offset,\n",
" x1=-length / 2 + offset,\n",
" y1=width / 2 - offset,\n",
" x2=length / 2 - offset,\n",
" y2=width / 2 - offset,\n",
" hls=h_bem,\n",
" layers=wlayers,\n",
")\n",
"tml.HeadLineSink(\n",
" ml,\n",
" x1=-l / 2 + offset,\n",
" x1=-length / 2 + offset,\n",
" y1=0,\n",
" x2=l / 2 - offset,\n",
" x2=length / 2 - offset,\n",
" y2=0,\n",
" hls=h_bem,\n",
" layers=wlayers,\n",
" order=5,\n",
")\n",
"tml.HeadLineSink(\n",
" ml,\n",
" x1=-l / 2 + offset,\n",
" y1=-b / 2 + offset,\n",
" x2=l / 2 - offset,\n",
" y2=-b / 2 + offset,\n",
" x1=-length / 2 + offset,\n",
" y1=-width / 2 + offset,\n",
" x2=length / 2 - offset,\n",
" y2=-width / 2 + offset,\n",
" hls=h_bem,\n",
" layers=wlayers,\n",
")\n",
Expand All @@ -619,7 +620,7 @@
"\n",
"print(\"\\nDischarge =\", np.round(Qtot.sum(), 2), \"m^3/dag\")\n",
"\n",
"y = np.linspace(-b / 2 - 25, b / 2 + 1100, 201)\n",
"y = np.linspace(-width / 2 - 25, width / 2 + 1100, 201)\n",
"hl = ml.headalongline(np.zeros(201), y, layers=[0])\n",
"y_5cm = np.interp(\n",
" -0.05, ml.headalongline(np.zeros(201), y, layers=0).squeeze(), y, right=np.nan\n",
Expand All @@ -642,7 +643,7 @@
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(0.0, l / 2 + 1100, 201)\n",
"x = np.linspace(0.0, length / 2 + 1100, 201)\n",
"hl = ml.headalongline(x, np.zeros(201), layers=[0, last_lay_dw, last_lay_dw + 1])"
]
},
Expand Down Expand Up @@ -682,7 +683,7 @@
"metadata": {},
"outputs": [],
"source": [
"x = np.linspace(-l / 2 - 25, 0.0, 201)\n",
"x = np.linspace(-length / 2 - 25, 0.0, 201)\n",
"hl = ml.headalongline(x, np.zeros(201), layers=[0, last_lay_dw, last_lay_dw + 1])"
]
},
Expand Down Expand Up @@ -724,7 +725,7 @@
"source": [
"xoffset = 50\n",
"zoffset = 15\n",
"x1, x2, y1, y2 = [-l / 2 - xoffset, 0.0, 0, 0]\n",
"x1, x2, y1, y2 = [-length / 2 - xoffset, 0.0, 0, 0]\n",
"nudge = 1e-6\n",
"n = 301"
]
Expand Down
5 changes: 3 additions & 2 deletions docs/03examples/circareasink_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"\n",
"import timml as tml"
]
},
{
Expand Down
1 change: 1 addition & 0 deletions docs/03examples/circular_buildingpit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
" zip(\n",
" shapely.get_coordinates(circle)[:, 0],\n",
" shapely.get_coordinates(circle)[:, 1],\n",
" strict=False,\n",
" )\n",
")[::-1]"
]
Expand Down
4 changes: 1 addition & 3 deletions docs/03examples/lake_horizontal_well.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"import timml as tml"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions docs/03examples/normal_flux.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
"outputs": [],
"source": [
"# import packages\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import timml as tml\n",
"import matplotlib.pyplot as plt"
"\n",
"import timml as tml"
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions docs/03examples/test_linesink_discharge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"\n",
"import timml as tml"
]
},
{
Expand Down Expand Up @@ -969,7 +970,7 @@
" topthick=2,\n",
" hstar=7,\n",
")\n",
"xy = list(zip(np.linspace(-10, 10, 21), np.zeros(21)))\n",
"xy = list(zip(np.linspace(-10, 10, 21), np.zeros(21), strict=False))\n",
"ls = tml.LineSinkDitchString(\n",
" ml, xy=xy, Qls=100, wh=2, res=5, order=2, layers=np.arange(10, 30, 1)\n",
")\n",
Expand Down
5 changes: 3 additions & 2 deletions docs/03examples/test_polygon_areasink.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"\n",
"import timml as tml"
]
},
{
Expand Down
4 changes: 1 addition & 3 deletions docs/03examples/test_well_near_lake.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"import timml as tml"
]
},
{
Expand Down
14 changes: 6 additions & 8 deletions docs/03examples/timml_notebook0_sol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@
"metadata": {},
"outputs": [],
"source": [
"# install timml if it is not installed already\n",
"try:\n",
" import timml as tml\n",
"except:\n",
" !pip install timml\n",
" import timml as tml\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"\n",
"import timml as tml"
]
},
{
Expand Down Expand Up @@ -393,7 +389,9 @@
"w = tml.Well(ml, xw=-400, yw=0, Qw=200, rw=0.2)\n",
"xls = np.zeros(21)\n",
"yls = np.linspace(-800, 800, 21)\n",
"ls = tml.HeadLineSinkString(ml, xy=list(zip(xls, yls)), hls=40, layers=0, label=\"river\")\n",
"ls = tml.HeadLineSinkString(\n",
" ml, xy=list(zip(xls, yls, strict=False)), hls=40, layers=0, label=\"river\"\n",
")\n",
"ml.solve()\n",
"ml.contour(\n",
" win=[-1000, 100, -500, 500], ngr=50, levels=np.arange(39, 42, 0.1), figsize=(6, 6)\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/03examples/timml_notebook1_sol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import timml as tml\n",
"\n",
"figsize = (8, 8)"
]
Expand Down
4 changes: 2 additions & 2 deletions docs/03examples/timml_notebook2_sol.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"metadata": {},
"outputs": [],
"source": [
"import timml as tml\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import timml as tml\n",
"\n",
"figsize = (8, 8)"
]
Expand Down
Loading

0 comments on commit 202b5b6

Please sign in to comment.