Skip to content

Commit eb3ccbc

Browse files
ci: use Ruff as new formatter and linter (#233)
* wip * pycodestyle * update dependencies * skl2onnx * use ruff * apply formatter * apply lint auto fixes * manually apply lints * change check * ruff ci from branch
1 parent a0e325e commit eb3ccbc

File tree

79 files changed

+9087
-9334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+9087
-9334
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
check:
15-
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@main
15+
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@ruff
1616

1717
strategy:
1818
fail-fast: false
@@ -28,7 +28,7 @@ jobs:
2828
# Checks the library using minimum version resolution
2929
# `uv` has this feature built-in, c.f. https://github.com/astral-sh/uv
3030
check-min-version:
31-
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@main
31+
uses: geo-engine/geoengine-python/.github/workflows/test-python.yml@ruff
3232

3333
with:
3434
python-version: "3.10"

.github/workflows/test-python.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ on:
1010
use-uv:
1111
type: boolean
1212
default: false
13-
description: 'Use `uv` for minimum version resolution'
13+
description: "Use `uv` for minimum version resolution"
1414
coverage:
1515
type: boolean
1616
default: false
17-
description: 'Generate coverage report'
17+
description: "Generate coverage report"
1818

1919
jobs:
2020
check:
@@ -70,11 +70,11 @@ jobs:
7070
- name: Check Formatting
7171
run: |
7272
${{ steps.vars.outputs.VENV_CALL }}
73-
python -m pycodestyle
73+
python -m ruff format --check
7474
- name: Lint code
7575
run: |
7676
${{ steps.vars.outputs.VENV_CALL }}
77-
python -m pylint geoengine
77+
python3 -m ruff check
7878
- name: Type-check code
7979
# mypy seems buggy with uv
8080
if: ${{ !inputs.use-uv }}
@@ -89,10 +89,6 @@ jobs:
8989
run: |
9090
${{ steps.vars.outputs.VENV_CALL }}
9191
${{ steps.vars.outputs.PIP_INSTALL }} -e .[test]
92-
- name: Lint tests
93-
run: |
94-
${{ steps.vars.outputs.VENV_CALL }}
95-
python -m pylint tests
9692
- name: Type-check tests
9793
# mypy seems buggy with uv
9894
if: ${{ !inputs.use-uv }}

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,30 @@ python3 -m build
101101

102102
## Formatting
103103

104-
This package is formatted according to `pycodestyle`.
104+
This package is formatted according to `ruff`.
105105
You can check it by calling:
106106

107107
```bash
108-
python3 -m pycodestyle
108+
python3 -m ruff format --check
109109
```
110110

111-
Our tip is to install `autopep8` and use it to format the code.
111+
Our tip is to install `ruff` and use it to format the code.
112+
113+
### VSCode
114+
115+
If you use VSCode, you can install the [ruff extension](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) and set it as the default formatter.
112116

113117
## Lints
114118

115119
Our CI automatically checks for lint errors.
116-
We use `pylint` to check the code.
120+
We use `ruff` to check the code.
117121
You can check it by calling:
118122

119123
```bash
120-
python3 -m pylint geoengine
121-
python3 -m pylint tests
124+
python3 -m ruff check
122125
```
123126

124-
Our tip is to activate linting with `pylint` in your IDE.
127+
Our tip is to activate linting with `ruff` in your IDE.
125128

126129
## Type Checking
127130

check.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ function echoerr() {
1313

1414
echoerr "Check code style"
1515

16-
python3 -m pycodestyle
16+
python3 -m ruff format --check
1717

1818
echoerr "Check code with linter"
1919

20-
python3 -m pylint geoengine
21-
python3 -m pylint tests
20+
python3 -m ruff check
2221

2322
echoerr "Check code with type checker"
2423

examples/add_public_raster_dataset.ipynb

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
"metadata": {},
1515
"outputs": [],
1616
"source": [
17-
"import geoengine as ge\n",
18-
"import geoengine_openapi_client\n",
1917
"from datetime import datetime\n",
18+
"\n",
19+
"import geoengine_openapi_client\n",
20+
"\n",
21+
"import geoengine as ge\n",
2022
"from geoengine.types import RasterBandDescriptor"
2123
]
2224
},
@@ -110,19 +112,21 @@
110112
"\n",
111113
"file_not_found_handling = geoengine_openapi_client.FileNotFoundHandling.NODATA\n",
112114
"\n",
113-
"gdal_params = geoengine_openapi_client.GdalDatasetParameters.from_dict({\n",
114-
" \"filePath\": file_path,\n",
115-
" \"rasterbandChannel\": rasterband_channel,\n",
116-
" \"geoTransform\": geo_transform.to_api_dict(),\n",
117-
" \"width\": width,\n",
118-
" \"height\": height,\n",
119-
" \"fileNotFoundHandling\": file_not_found_handling,\n",
120-
" \"noDataValue\": None,\n",
121-
" \"propertiesMapping\": None,\n",
122-
" \"gdalOpenOptions\": None,\n",
123-
" \"gdalConfigOptions\": None,\n",
124-
" \"allowAlphabandAsMask\": True\n",
125-
"})\n",
115+
"gdal_params = geoengine_openapi_client.GdalDatasetParameters.from_dict(\n",
116+
" {\n",
117+
" \"filePath\": file_path,\n",
118+
" \"rasterbandChannel\": rasterband_channel,\n",
119+
" \"geoTransform\": geo_transform.to_api_dict(),\n",
120+
" \"width\": width,\n",
121+
" \"height\": height,\n",
122+
" \"fileNotFoundHandling\": file_not_found_handling,\n",
123+
" \"noDataValue\": None,\n",
124+
" \"propertiesMapping\": None,\n",
125+
" \"gdalOpenOptions\": None,\n",
126+
" \"gdalConfigOptions\": None,\n",
127+
" \"allowAlphabandAsMask\": True,\n",
128+
" }\n",
129+
")\n",
126130
"\n",
127131
"result_descriptor_measurement = ge.ClassificationMeasurement(\n",
128132
" measurement=\"Land Cover\",\n",
@@ -143,9 +147,8 @@
143147
" \"13\": \"Urban and Built-Up\",\n",
144148
" \"14\": \"Cropland-Natural Vegetation Mosaics\",\n",
145149
" \"15\": \"Snow and Ice\",\n",
146-
" \"16\": \"Barren or Sparsely Vegetated\"\n",
147-
" }\n",
148-
"\n",
150+
" \"16\": \"Barren or Sparsely Vegetated\",\n",
151+
" },\n",
149152
")\n",
150153
"\n",
151154
"\n",
@@ -154,22 +157,24 @@
154157
" [RasterBandDescriptor(\"band\", result_descriptor_measurement)],\n",
155158
" \"EPSG:4326\",\n",
156159
" spatial_bounds=ge.SpatialPartition2D(-180.0, -90.0, 180.0, 90.0),\n",
157-
" spatial_resolution=ge.SpatialResolution(0.1, 0.1)\n",
160+
" spatial_resolution=ge.SpatialResolution(0.1, 0.1),\n",
158161
")\n",
159162
"\n",
160-
"meta_data = geoengine_openapi_client.GdalMetaDataStatic.from_dict({\n",
161-
" \"type\": \"GdalStatic\",\n",
162-
" \"time\": None,\n",
163-
" \"params\": gdal_params,\n",
164-
" \"resultDescriptor\": result_descriptor.to_api_dict().to_dict(),\n",
165-
"})\n",
163+
"meta_data = geoengine_openapi_client.GdalMetaDataStatic.from_dict(\n",
164+
" {\n",
165+
" \"type\": \"GdalStatic\",\n",
166+
" \"time\": None,\n",
167+
" \"params\": gdal_params,\n",
168+
" \"resultDescriptor\": result_descriptor.to_api_dict().to_dict(),\n",
169+
" }\n",
170+
")\n",
166171
"\n",
167172
"meta_data"
168173
]
169174
},
170175
{
171176
"cell_type": "code",
172-
"execution_count": 5,
177+
"execution_count": null,
173178
"metadata": {},
174179
"outputs": [
175180
{
@@ -197,21 +202,21 @@
197202
" breakpoints=[\n",
198203
" ge.ColorBreakpoint(value=0, color=(0, 0, 255, 255)),\n",
199204
" ge.ColorBreakpoint(value=8, color=(0, 255, 0, 255)),\n",
200-
" ge.ColorBreakpoint(value=16, color=(255, 0, 0, 255))\n",
205+
" ge.ColorBreakpoint(value=16, color=(255, 0, 0, 255)),\n",
201206
" ],\n",
202207
" no_data_color=(0, 0, 0, 0),\n",
203208
" over_color=(0, 0, 0, 0),\n",
204-
" under_color=(0, 0, 0, 0)\n",
205-
" )\n",
206-
" )\n",
209+
" under_color=(0, 0, 0, 0),\n",
210+
" ),\n",
211+
" ),\n",
207212
" ),\n",
208-
" provenance=[ge.Provenance(\n",
209-
" citation=\"The data was obtained from <https://lpdaac.usgs.gov/products/mcd12c1v006>. The layer Majority_Land_Cover_Type_1 was extracted, downscaled and saved as landcover.tif.\",\n",
210-
" uri=\"https://lpdaac.usgs.gov/products/mcd12c1v006/\",\n",
211-
" license=\"All data distributed by the LP DAAC contain no restrictions on the data reuse. (https://lpdaac.usgs.gov/resources/faqs/#am-i-allowed-to-reuse-lp-daac-data).\"\n",
212-
" )],\n",
213-
"\n",
214-
"\n",
213+
" provenance=[\n",
214+
" ge.Provenance(\n",
215+
" citation=\"The data was obtained from <https://lpdaac.usgs.gov/products/mcd12c1v006>. The layer Majority_Land_Cover_Type_1 was extracted, downscaled and saved as landcover.tif.\", # noqa: E501\n",
216+
" uri=\"https://lpdaac.usgs.gov/products/mcd12c1v006/\",\n",
217+
" license=\"All data distributed by the LP DAAC contain no restrictions on the data reuse. (https://lpdaac.usgs.gov/resources/faqs/#am-i-allowed-to-reuse-lp-daac-data).\",\n",
218+
" )\n",
219+
" ],\n",
215220
")\n",
216221
"\n",
217222
"add_dataset_properties.to_api_dict()"
@@ -280,7 +285,7 @@
280285
}
281286
],
282287
"source": [
283-
"ge.datasets.list_datasets(name_filter='MCD12C1')"
288+
"ge.datasets.list_datasets(name_filter=\"MCD12C1\")"
284289
]
285290
},
286291
{
@@ -314,15 +319,17 @@
314319
"ge.reset()\n",
315320
"ge.initialize(\"http://localhost:3030/api\")\n",
316321
"\n",
317-
"workflow = ge.register_workflow({\n",
318-
" \"type\": \"Raster\",\n",
319-
" \"operator\": {\n",
320-
" \"type\": \"GdalSource\",\n",
321-
" \"params\": {\n",
322-
" \"data\": \"MCD12C1\",\n",
323-
" }\n",
322+
"workflow = ge.register_workflow(\n",
323+
" {\n",
324+
" \"type\": \"Raster\",\n",
325+
" \"operator\": {\n",
326+
" \"type\": \"GdalSource\",\n",
327+
" \"params\": {\n",
328+
" \"data\": \"MCD12C1\",\n",
329+
" },\n",
330+
" },\n",
324331
" }\n",
325-
"})\n",
332+
")\n",
326333
"\n",
327334
"workflow.get_result_descriptor()"
328335
]
@@ -370,14 +377,13 @@
370377
}
371378
],
372379
"source": [
373-
"time = datetime.strptime(\n",
374-
" '2014-04-01T12:00:00.000Z', \"%Y-%m-%dT%H:%M:%S.%f%z\")\n",
380+
"time = datetime.strptime(\"2014-04-01T12:00:00.000Z\", \"%Y-%m-%dT%H:%M:%S.%f%z\")\n",
375381
"\n",
376382
"data = workflow.get_xarray(\n",
377383
" ge.QueryRectangle(\n",
378384
" ge.BoundingBox2D(-180.0, -90.0, 180.0, 90.0),\n",
379385
" ge.TimeInterval(time, time),\n",
380-
" resolution=ge.SpatialResolution(360. / 16, 180. / 16),\n",
386+
" resolution=ge.SpatialResolution(360.0 / 16, 180.0 / 16),\n",
381387
" )\n",
382388
")\n",
383389
"\n",
@@ -439,7 +445,7 @@
439445
" ge.QueryRectangle(\n",
440446
" ge.BoundingBox2D(-180.0, -90.0, 180.0, 90.0),\n",
441447
" ge.TimeInterval(time, time),\n",
442-
" resolution=ge.SpatialResolution(360. / 16, 180. / 16),\n",
448+
" resolution=ge.SpatialResolution(360.0 / 16, 180.0 / 16),\n",
443449
" )\n",
444450
" )\n",
445451
"except Exception as e:\n",

0 commit comments

Comments
 (0)