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

MNT: Use ruff for formatting checks #2273

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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.1.5'
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 @@ -31,7 +31,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 @@ -751,12 +751,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
2 changes: 1 addition & 1 deletion lib/cartopy/tests/io/test_ogc_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import pytest

import cartopy.crs as ccrs
import cartopy.io.ogc_clients as ogc
from cartopy.io.ogc_clients import _OWSLIB_AVAILABLE
import cartopy.io.ogc_clients as ogc


RESOLUTION = (30, 30)
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,
)
Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer the old style here, as I like the horizontal separation between modules and their objects. I can't see a setting for that though, and it isn't a deal-breaker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a strong preference either way, so I was fine applying this. I think that ruff likely takes the black formatting approach and applies it liberally here even if we aren't using black. I also haven't found a setting to override this so I think we are stuck with it if we want to replace isort with ruff.

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 @@ -87,16 +87,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"]