Skip to content

Commit

Permalink
MNT: Use ruff for formatting checks
Browse files Browse the repository at this point in the history
Moves from flake8 and isort to ruff for the formatting checks.
Also updates some of the sorted and formatted imports that
were flagged by ruff.
  • Loading branch information
greglucas committed Oct 15, 2023
1 parent 53260b6 commit aa7cd73
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 44 deletions.
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ repos:
- id: no-commit-to-branch
# Trims trailing whitespace
- id: trailing-whitespace
- repo: https://github.com/pycqa/flake8
rev: "6.1.0"
hooks:
- id: flake8
- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
Expand All @@ -40,9 +36,8 @@ repos:
hooks:
- id: sort-all
types: [file, python]
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.292'
hooks:
- id: isort
types: [file, python]
args: [--filter-files]
- id: ruff
args: [--fix]
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies:
- sphinx
- sphinx-gallery
# Extras
- flake8
- pre-commit
- pykdtree
- ruff
- setuptools_scm
2 changes: 1 addition & 1 deletion examples/miscellanea/eccentric_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from io import BytesIO
from urllib.request import urlopen

from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

import cartopy.crs as ccrs

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/feature/nightshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import numpy as np
import shapely.geometry as sgeom

from . import ShapelyFeature
from .. import crs as ccrs
from . import ShapelyFeature


class Nightshade(ShapelyFeature):
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/io/img_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import collections
from pathlib import Path

from PIL import Image
import numpy as np
from PIL import Image
import shapely.geometry as sgeom


Expand Down
6 changes: 3 additions & 3 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from pathlib import Path
import warnings

from PIL import Image
import numpy as np
from PIL import Image
import shapely.geometry as sgeom

import cartopy
Expand Down Expand Up @@ -688,12 +688,12 @@ def __init__(self, subscription_key, tileset_id="microsoft.imagery",
A valid Azure Maps subscription key.
tileset_id
A tileset ID for a map. See
https://docs.microsoft.com/en-us/rest/api/maps/renderv2/getmaptilepreview#tilesetid # noqa: E501
https://docs.microsoft.com/en-us/rest/api/maps/renderv2/getmaptilepreview#tilesetid
for details.
api_version
API version to use. Defaults to 2.0 as recommended by Microsoft.
"""
""" # noqa: E501
super().__init__(desired_tile_form=desired_tile_form, cache=cache)
self.subscription_key = subscription_key
self.tileset_id = tileset_id
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/io/ogc_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import weakref
from xml.etree import ElementTree

from PIL import Image
import numpy as np
from PIL import Image
import shapely.geometry as sgeom


Expand Down
8 changes: 6 additions & 2 deletions lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

import cartopy
from cartopy.crs import PlateCarree, Projection, _RectangularProjection
from cartopy.mpl.ticker import (LatitudeFormatter, LatitudeLocator, LongitudeFormatter,
LongitudeLocator)
from cartopy.mpl.ticker import (
LatitudeFormatter,
LatitudeLocator,
LongitudeFormatter,
LongitudeLocator,
)


degree_locator = mticker.MaxNLocator(nbins=9, steps=[1, 1.5, 1.8, 2, 3, 6, 10])
Expand Down
8 changes: 6 additions & 2 deletions lib/cartopy/tests/io/test_srtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def srtm_login_or_skip(monkeypatch):
pytest.skip('SRTM_PASSWORD environment variable is unset.')

from http.cookiejar import CookieJar
from urllib.request import (HTTPBasicAuthHandler, HTTPCookieProcessor,
HTTPPasswordMgrWithDefaultRealm, build_opener)
from urllib.request import (
HTTPBasicAuthHandler,
HTTPCookieProcessor,
HTTPPasswordMgrWithDefaultRealm,
build_opener,
)

password_manager = HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(
Expand Down
9 changes: 7 additions & 2 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
import cartopy.crs as ccrs
from cartopy.mpl import _MPL_36
from cartopy.mpl.geoaxes import GeoAxes
from cartopy.mpl.gridliner import (LATITUDE_FORMATTER, LONGITUDE_FORMATTER, Gridliner,
classic_formatter, classic_locator)
from cartopy.mpl.gridliner import (
LATITUDE_FORMATTER,
LONGITUDE_FORMATTER,
Gridliner,
classic_formatter,
classic_locator,
)
from cartopy.mpl.ticker import LongitudeFormatter, LongitudeLocator


Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/mpl/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import types

from PIL import Image
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
import pytest
import shapely.geometry as sgeom

Expand Down
8 changes: 6 additions & 2 deletions lib/cartopy/tests/mpl/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

import cartopy.crs as ccrs
from cartopy.mpl.geoaxes import GeoAxes
from cartopy.mpl.ticker import (LatitudeFormatter, LatitudeLocator, LongitudeFormatter,
LongitudeLocator)
from cartopy.mpl.ticker import (
LatitudeFormatter,
LatitudeLocator,
LongitudeFormatter,
LongitudeLocator,
)


ONE_MIN = 1 / 60.
Expand Down
3 changes: 1 addition & 2 deletions lib/cartopy/tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import warnings

import numpy as np
from numpy.testing import assert_almost_equal
from numpy.testing import assert_almost_equal, assert_array_equal
from numpy.testing import assert_array_almost_equal as assert_arr_almost_eq
from numpy.testing import assert_array_equal
import pyproj
import pytest
import shapely.geometry as sgeom
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/tests/test_img_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import sys
import warnings

from PIL import Image
import numpy as np
from numpy.testing import assert_array_almost_equal, assert_array_equal
from PIL import Image
import pytest
import shapely.geometry as sgeom

Expand Down
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,17 @@ ignore = [
"lib/cartopy/trace.cpp",
]

[tool.isort]
force_sort_within_sections = true
known_first_party = "cartopy"
lines_after_imports = 2
line_length = 88
no_lines_before = "LOCALFOLDER"
skip_gitignore = true
verbose = false

[tool.pytest.ini_options]
addopts = "--mpl"
testpaths = ["lib"]
python_files = ["test_*.py"]

[tool.ruff]
target-version = "py39"
select = ["E", "F", "I", "W"]

[tool.ruff.isort]
force-sort-within-sections = true
known-first-party = ["cartopy"]
lines-after-imports = 2
no-lines-before = ["local-folder"]
6 changes: 0 additions & 6 deletions setup.cfg

This file was deleted.

0 comments on commit aa7cd73

Please sign in to comment.