Skip to content

Commit

Permalink
2nd attempt at ruff (#428)
Browse files Browse the repository at this point in the history
* starting

* ruff config

* fix notebook

* more rules

* F rules

* sort rules

* Q rules

* remove F401

* sort

* don't ignore F841

* being ridiculous

* some todo rules

* try gh action

* a few more ideas to try

* gitignore

* clean up toml
  • Loading branch information
ajfriend authored Oct 28, 2024
1 parent d061d81 commit e9506ff
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 51 deletions.
20 changes: 0 additions & 20 deletions .flake8

This file was deleted.

9 changes: 2 additions & 7 deletions .github/workflows/coverage-lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ jobs:
pip install --upgrade pip setuptools wheel
pip install .[test]
- name: Lint
run: flake8 src/h3 tests

- name: Pylint
# As a test for visibility of API bindings, we want to ensure that pylint has no
# `import-error` warnings for h3 imports.
run: pylint --disable=all --enable=import-error tests/
- name: Run Linting
uses: astral-sh/[email protected]

- name: Coverage
run: |
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/coverage-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ jobs:
pip install --upgrade pip setuptools wheel
pip install .[test]
- name: Lint
run: flake8 src/h3 tests

- name: Pylint
# As a test for visibility of API bindings, we want to ensure that pylint has no
# `import-error` warnings for h3 imports.
run: pylint --disable=all --enable=import-error tests/
- name: Run Linting
uses: astral-sh/[email protected]

- name: Coverage
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ h3c/
*.py[cod]
.cache/
h3/out/
.ruff_cache/

# Generated C code from Cython test
tests/**/*.c
Expand Down
25 changes: 11 additions & 14 deletions docs/polygon_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,36 @@
"import contextily as cx\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"def plot_df(df, column=None, ax=None):\n",
" 'Plot based on the `geometry` column of a GeoPandas dataframe'\n",
" \"Plot based on the `geometry` column of a GeoPandas dataframe\"\n",
" df = df.copy()\n",
" df = df.to_crs(epsg=3857) # web mercator\n",
" df = df.to_crs(epsg=3857) # web mercator\n",
"\n",
" if ax is None:\n",
" fig, ax = plt.subplots(figsize=(8,8))\n",
" _, ax = plt.subplots(figsize=(8,8))\n",
" ax.get_xaxis().set_visible(False)\n",
" ax.get_yaxis().set_visible(False)\n",
" \n",
"\n",
" df.plot(\n",
" ax=ax,\n",
" alpha=0.5, edgecolor='k',\n",
" column=column, categorical=True,\n",
" legend=True, legend_kwds={'loc': 'upper left'}, \n",
" legend=True, legend_kwds={'loc': 'upper left'},\n",
" )\n",
" cx.add_basemap(ax, crs=df.crs, source=cx.providers.CartoDB.Positron)\n",
"\n",
"\n",
"def plot_shape(shape, ax=None):\n",
" df = geopandas.GeoDataFrame({'geometry': [shape]}, crs='EPSG:4326')\n",
" plot_df(df, ax=ax)\n",
"\n",
"\n",
"def plot_cells(cells, ax=None):\n",
" shape = h3.cells_to_h3shape(cells)\n",
" plot_shape(shape, ax=ax)\n",
"\n",
"\n",
"def plot_shape_and_cells(shape, res=9):\n",
" fig, axs = plt.subplots(1,2, figsize=(10,5), sharex=True, sharey=True)\n",
" plot_shape(shape, ax=axs[0])\n",
Expand Down Expand Up @@ -263,6 +267,7 @@
" def __geo_interface__(self):\n",
" return self.d\n",
"\n",
"\n",
"geo = MockGeo(d)\n",
"h3.geo_to_h3shape(geo)"
]
Expand Down Expand Up @@ -902,14 +907,6 @@
"source": [
"plot_df(df, column='BoroName')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd012d79-a653-4d5d-bb30-408031301015",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -928,7 +925,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ test:
./env/bin/pytest

lint:
./env/bin/flake8 src/h3 tests
./env/bin/pylint --disable=all --enable=import-error tests/
./env/bin/ruff check

fix:
./env/bin/ruff check --fix

lab:
./env/bin/pip install .[all]
Expand Down
45 changes: 44 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Changelog = 'https://package.readthedocs.io/en/latest/changelog.html'

[project.optional-dependencies]
numpy = ['numpy']
test = ['pytest', 'pytest-cov', 'flake8', 'pylint', 'numpy']
test = ['pytest', 'pytest-cov', 'ruff', 'numpy']
all = [
'h3[test]',
'jupyter-book',
Expand Down Expand Up @@ -88,3 +88,46 @@ sdist.include = [
'src/h3lib/cmake/*',
'src/h3lib/src/h3lib/*'
]


[tool.ruff]
src = [
'src',
'tests',
]
line-length = 88

[tool.ruff.lint]
flake8-quotes.inline-quotes = 'single'

# https://docs.astral.sh/ruff/rules/
preview = true # https://docs.astral.sh/ruff/preview/#selecting-single-preview-rules
select = [
'A',
# 'B', # todo
# 'COM', # todo
'E',
'F',
'Q',
'W',
# 'D', # todo. this is nice!
# 'PL', # todo. some interesting ideas
# 'DOC', # todo: interesting
]
ignore = [
'E221', # Multiple spaces before operator
'E231', # Missing whitespace after ','
'E241', # Multiple spaces after ','
'E251', # Unexpected spaces around keyword / parameter equals
'E272', # Multiple spaces before keyword
'E731', # Do not assign a `lambda` expression, use a `def`
# 'PLR2004',
]

[tool.ruff.lint.per-file-ignores]
'*.ipynb' = [
'E501', # Line too long (104 > 88)
]
'test*.py' = [
# 'D', # maybe just the need for docstring
]

0 comments on commit e9506ff

Please sign in to comment.