Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace flake8 and pylint with ruff #416

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .flake8

This file was deleted.

27 changes: 21 additions & 6 deletions .github/workflows/coverage-lint-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,28 @@ jobs:
pip install --upgrade pip setuptools wheel
pip install .[test]

- name: Lint
run: flake8 src/h3 tests
- name: Install CLI Reviewdog
uses: reviewdog/action-setup@v1

# Order is important for these commands
# Run the actual fixes first so that they are picked up by next GH step but
# removed from the final run of the linter.
# Second run of the linter will report unfixable issues via reviewdog
- name: Run Linting
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ruff format .
ruff check . --fix-only
ruff check . | reviewdog -efm="%f:%l:%c: %m" -reporter=github-pr-review -level=warning

- 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/
# Picks up file changes from the previous action
- name: Suggest Fixes
uses: reviewdog/action-suggester@v1
with:
tool_name: ruff
github_token: ${{ secrets.GITHUB_TOKEN }}
level: warning

- name: Coverage
run: |
Expand Down
27 changes: 21 additions & 6 deletions .github/workflows/coverage-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,28 @@ jobs:
pip install --upgrade pip setuptools wheel
pip install .[test]

- name: Lint
run: flake8 src/h3 tests
- name: Install CLI Reviewdog
uses: reviewdog/action-setup@v1

# Order is important for these commands
# Run the actual fixes first so that they are picked up by next GH step but
# removed from the final run of the linter.
# Second run of the linter will report unfixable issues via reviewdog
- name: Run Linting
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ruff format .
ruff check . --fix-only
ruff check . | reviewdog -efm="%f:%l:%c: %m" -reporter=github-pr-review -level=warning

- 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/
# Picks up file changes from the previous action
- name: Suggest Fixes
uses: reviewdog/action-suggester@v1
with:
tool_name: ruff
github_token: ${{ secrets.GITHUB_TOKEN }}
level: warning

- name: Coverage
run: |
Expand Down
46 changes: 28 additions & 18 deletions docs/polygon_tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,48 @@
"metadata": {},
"outputs": [],
"source": [
"import h3\n",
"\n",
"import geopandas\n",
"import geodatasets\n",
"import contextily as cx\n",
"import geodatasets\n",
"import geopandas\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import h3\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",
" fig, 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",
" alpha=0.5,\n",
" edgecolor='k',\n",
" column=column,\n",
" categorical=True,\n",
" legend=True,\n",
" 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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙄

" fig, axs = plt.subplots(1, 2, figsize=(10, 5), sharex=True, sharey=True)\n",
" plot_shape(shape, ax=axs[0])\n",
" plot_cells(h3.h3shape_to_cells(shape, res), ax=axs[1])\n",
" fig.tight_layout()"
Expand All @@ -92,11 +99,7 @@
"metadata": {},
"outputs": [],
"source": [
"outer = [\n",
" (37.804, -122.412),\n",
" (37.778, -122.507),\n",
" (37.733, -122.501)\n",
"]\n",
"outer = [(37.804, -122.412), (37.778, -122.507), (37.733, -122.501)]\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way a lot of these auto formatters work is that you can add a trailing comma to the last element to force it to have one element per line.

"\n",
"poly = h3.LatLngPoly(outer)\n",
"print(poly)\n",
Expand Down Expand Up @@ -263,6 +266,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 @@ -429,7 +433,13 @@
"poly1 = h3.LatLngPoly([(37.804, -122.412), (37.778, -122.507), (37.733, -122.501)])\n",
"poly2 = h3.LatLngPoly(\n",
" [(37.803, -122.408), (37.736, -122.491), (37.738, -122.380), (37.787, -122.39)],\n",
" [(37.760, -122.441), (37.772, -122.427), (37.773, -122.404), (37.758, -122.401), (37.745, -122.428)]\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to complain about this, but its inconsistent with what I just said above. 😬

" [\n",
" (37.760, -122.441),\n",
" (37.772, -122.427),\n",
" (37.773, -122.404),\n",
" (37.758, -122.401),\n",
" (37.745, -122.428),\n",
" ],\n",
")\n",
"mpoly = h3.LatLngMultiPoly(poly1, poly2)\n",
"\n",
Expand Down
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ 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 format

lab:
./env/bin/pip install .[all]
Expand Down
48 changes: 42 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ 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]',
ajfriend marked this conversation as resolved.
Show resolved Hide resolved
'jupyter-book',
'flake8',
'sphinx>=7.3.3', # https://github.com/sphinx-doc/sphinx/issues/12290
'jupyterlab',
'jupyterlab-geojson',
Expand All @@ -59,15 +59,51 @@ all = [
'contextily',
'cartopy',
'geoviews',
'numpy',
'pytest',
'pytest-cov',
'pylint',
]

[tool.pytest.ini_options]
addopts = "--cov=h3 --cov=tests --cov-report=term-missing --durations=10"

[tool.ruff]
src = [
"src",
"tests",
]

lint.select = [
"E",
"F",
"W",
]

lint.extend-select = [
"I",
]

lint.ignore = [
"E251", # unexpected spaces around keyword / parameter equals
"E272", # multiple spaces before keyword
# sometimes I just want to line up decimal points...
"E201", # whitespace after '['
"E241", # multiple spaces after ','
"E731", # do not assign a lambda expression, use a def
# Ignore when using formatter (https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules)
"E501", # Line-too-long;
]

respect-gitignore = true

[tool.ruff.format]
indent-style = "space"
quote-style = "single"

[tool.ruff.lint.per-file-ignores]
# Do not enforce usage in init files
"__init__.py" = [
"E402",
"F401",
]

[tool.coverage.run]
omit = [
'*/h3/api/basic_int/__init__.py',
Expand Down
35 changes: 15 additions & 20 deletions src/h3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# flake8: noqa

from .api.basic_str import *
from ._version import __version__

from ._cy import (
UnknownH3ErrorCode,
H3BaseException,

H3GridNavigationError,
H3MemoryError,
H3ValueError,

H3FailedError,
H3DomainError,
H3LatLngDomainError,
H3ResDomainError,
H3CellInvalidError,
H3DirEdgeInvalidError,
H3UndirEdgeInvalidError,
H3VertexInvalidError,
H3PentagonError,
H3DomainError,
H3DuplicateInputError,
H3NotNeighborsError,
H3ResMismatchError,
H3FailedError,
H3GridNavigationError,
H3LatLngDomainError,
H3MemoryAllocError,
H3MemoryBoundsError,
H3MemoryError,
H3NotNeighborsError,
H3OptionInvalidError,
H3PentagonError,
H3ResDomainError,
H3ResMismatchError,
H3UndirEdgeInvalidError,
H3ValueError,
H3VertexInvalidError,
UnknownH3ErrorCode,
)
from ._version import __version__
from .api.basic_str import * # noqa
Loading
Loading