Skip to content

Commit b3a4798

Browse files
jeremyhomad
authored andcommitted
Replace shed with ruff
Based on issues in #581
1 parent 5de3182 commit b3a4798

23 files changed

+134
-97
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
---
22
repos:
3-
# Normalise all Python code. (Black + isort + pyupgrade + autoflake)
4-
- repo: https://github.com/Zac-HD/shed
5-
rev: 2024.3.1
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.3.5
65
hooks:
7-
- id: shed
8-
# Python Linting
9-
- repo: https://github.com/pycqa/flake8
10-
rev: 7.0.0
11-
hooks:
12-
- id: flake8
13-
exclude: ^docs/
14-
additional_dependencies:
15-
- flake8-bugbear # Lint-checks too opinionated for flake8 proper
16-
- flake8-builtins # Don't allow built-in names like list
17-
- flake8-coding # Only UTF-8
18-
- flake8-debugger # Don't commit debugger calls
19-
- flake8-executable # Check shebangs and executable permissions
20-
- flake8-logging-format # Use log arguments, not string format
21-
- flake8-pep3101 # Don't use old string % formatting
22-
- flake8-pytest-style # Avoid common pytest mistakes
23-
- flake8-pytest # Use plain assert, not unittest assertions
24-
- flake8-rst-docstrings # docstring should be valid ReST
25-
- pep8-naming # Follow pep8 naming rules (eg. function names lowercase)
6+
- id: ruff
7+
args: [--fix, --show-fixes, --output-format, grouped]
8+
- id: ruff-format
269
# Lint Python snippets embedded in Markdown (using flake8)
2710
- repo: https://github.com/johnfraney/flake8-markdown
2811
rev: v0.5.0
@@ -41,7 +24,7 @@ repos:
4124
args: ['-c', '.yamllint']
4225
# Common pre-commit checks
4326
- repo: https://github.com/pre-commit/pre-commit-hooks
44-
rev: v4.5.0
27+
rev: v4.6.0
4528
hooks:
4629
- id: check-added-large-files # We don't want huge files. (Cut down test data!)
4730
args: ['--maxkb=2000']

cubedash/_audit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from datacube.model import Range
99
from flask import Blueprint, Response, redirect, url_for
1010

11-
from . import _model, _utils as utils
11+
from . import _model
12+
from . import _utils as utils
1213

1314
_LOG = logging.getLogger(__name__)
1415
bp = Blueprint(

cubedash/_dataset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import flask
55
from flask import Blueprint, abort, url_for
66

7-
from . import _model, _utils as utils
7+
from . import _model
8+
from . import _utils as utils
89

910
_LOG = logging.getLogger(__name__)
1011
bp = Blueprint(

cubedash/_filters.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
from orjson import orjson
1919
from shapely.geometry import MultiPolygon
2020

21-
from . import _model, _utils, _utils as utils
21+
from . import _model, _utils
22+
from . import _utils as utils
2223

2324
# How far to step the number when the user hits up/down.
2425
NUMERIC_STEP_SIZE = {
@@ -173,9 +174,7 @@ def _format_albers_area(shape: MultiPolygon):
173174
@bp.app_template_filter("query_value")
174175
def _format_query_value(val):
175176
if isinstance(val, Range):
176-
return "{} to {}".format(
177-
_format_query_value(val.begin), _format_query_value(val.end)
178-
)
177+
return f"{_format_query_value(val.begin)} to {_format_query_value(val.end)}"
179178
if isinstance(val, datetime):
180179
return _format_datetime(val)
181180
if val is None:

cubedash/_pages.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
_product,
2929
_stac,
3030
_stac_legacy,
31+
)
32+
from . import (
3133
_utils as utils,
3234
)
3335
from ._utils import as_rich_json, get_sorted_product_summaries
@@ -160,7 +162,7 @@ def legacy_search_page(
160162
@app.route("/products/<product_name>/datasets/<int:year>")
161163
@app.route("/products/<product_name>/datasets/<int:year>/<int:month>")
162164
@app.route("/products/<product_name>/datasets/<int:year>/<int:month>/<int:day>")
163-
def search_page( # noqa: C901
165+
def search_page(
164166
product_name: str = None, year: int = None, month: int = None, day: int = None
165167
):
166168
(
@@ -427,7 +429,9 @@ def timeline_page(product_name: str):
427429
return redirect(url_for("product_page", product_name=product_name))
428430

429431

430-
def _load_product(product_name, year, month, day) -> Tuple[
432+
def _load_product(
433+
product_name, year, month, day
434+
) -> Tuple[
431435
DatasetType,
432436
ProductSummary,
433437
TimePeriodOverview,

cubedash/_product.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
from flask import Blueprint, Response, abort, redirect, url_for
55

6-
from cubedash import _model, _utils, _utils as utils
6+
from cubedash import _model, _utils
7+
from cubedash import _utils as utils
78

89
_LOG = logging.getLogger(__name__)
910
bp = Blueprint("product", __name__)

cubedash/_stac.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import json
22
import logging
33
import uuid
4-
from datetime import datetime, time as dt_time, timedelta
4+
from datetime import datetime, timedelta
5+
from datetime import time as dt_time
56
from functools import partial
67
from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
78

@@ -10,7 +11,8 @@
1011
from datacube.model import Dataset, Range
1112
from datacube.utils import DocReader, parse_time
1213
from dateutil.tz import tz
13-
from eodatasets3 import serialise, stac as eo3stac
14+
from eodatasets3 import serialise
15+
from eodatasets3 import stac as eo3stac
1416
from eodatasets3.model import AccessoryDoc, DatasetDoc, MeasurementDoc, ProductDoc
1517
from eodatasets3.properties import Eo3Dict
1618
from eodatasets3.utils import is_doc_eo3
@@ -288,7 +290,7 @@ def field_path_row(key, value):
288290
elif key == "sat_row":
289291
kind = "landsat:wrs_row"
290292
else:
291-
raise ValueError(f"Path/row kind {repr(key)}")
293+
raise ValueError(f"Path/row kind {key!r}")
292294

293295
# If there's only one value in the range, return it.
294296
if isinstance(value, Range):
@@ -623,7 +625,7 @@ def _handle_fields_extension(
623625
keys=inc.split("."),
624626
# get corresponding field from item
625627
# disallow default to avoid None values being inserted
626-
func=lambda _: _get_property(inc, item, no_default=True), # noqa: B023
628+
func=lambda _: _get_property(inc, item, no_default=True),
627629
)
628630

629631
for exc in fields.get("exclude") or []:

cubedash/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import datacube.drivers.postgres._schema
1919
import eodatasets3.serialise
2020
import flask
21-
import numpy
21+
import numpy as np
2222
import shapely.geometry
2323
import shapely.validation
2424
import structlog
@@ -578,7 +578,7 @@ def as_yaml(*o, content_type="text/yaml", downloadable_filename_prefix: str = No
578578

579579
# TODO: remove the two functions once eo-datasets fix is released
580580
def _represent_float(self, value):
581-
text = numpy.format_float_scientific(value)
581+
text = np.format_float_scientific(value)
582582
return self.represent_scalar("tag:yaml.org,2002:float", text)
583583

584584
def dumps_yaml(yml, stream, *docs) -> None:

cubedash/generate.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
5353
5454
"""
55+
5556
import collections
5657
import multiprocessing
5758
import re
@@ -64,7 +65,8 @@
6465

6566
import click
6667
import structlog
67-
from click import secho as click_secho, style
68+
from click import secho as click_secho
69+
from click import style
6870
from datacube.config import LocalConfig
6971
from datacube.index import Index, index_connect
7072
from datacube.model import DatasetType
@@ -75,7 +77,7 @@
7577
GenerateResult,
7678
SummaryStore,
7779
TimePeriodOverview,
78-
UnsupportedWKTProductCRS,
80+
UnsupportedWKTProductCRSError,
7981
)
8082
from cubedash.summary._stores import DEFAULT_EPSG
8183
from cubedash.summary._summarise import DEFAULT_TIMEZONE
@@ -132,7 +134,7 @@ def print_status(product_name=None, year=None, month=None, day=None, summary=Non
132134
minimum_change_scan_window=settings.minimum_change_scan_window,
133135
)
134136
return product_name, result, updated_summary
135-
except UnsupportedWKTProductCRS as e:
137+
except UnsupportedWKTProductCRSError as e:
136138
log.warning("product.unsupported", reason=e.reason)
137139
return product_name, GenerateResult.UNSUPPORTED, None
138140
except Exception:
@@ -230,7 +232,7 @@ def _load_products(index: Index, product_names) -> List[DatasetType]:
230232
p.name for p in index.products.get_all()
231233
)
232234
raise click.BadParameter(
233-
f"Unknown product {repr(product_name)}.\n\n"
235+
f"Unknown product {product_name!r}.\n\n"
234236
f"Possibilities:\n\t{possible_product_names}",
235237
param_hint="product_names",
236238
)

cubedash/gunicorn_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Gunicorn config for Prometheus internal metrics
2-
"""
1+
"""Gunicorn config for Prometheus internal metrics"""
32

43
import os
54

0 commit comments

Comments
 (0)