Skip to content

Commit 71b199f

Browse files
committed
use ruff for linting
1 parent 40d06fa commit 71b199f

12 files changed

Lines changed: 89 additions & 112 deletions

‎.flake8‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎.pre-commit-config.yaml‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
repos:
2+
- repo: https://github.com/abravalheri/validate-pyproject
3+
rev: v0.12.1
4+
hooks:
5+
- id: validate-pyproject
6+
27
- repo: https://github.com/psf/black
3-
rev: 22.3.0
8+
rev: 22.12.0
49
hooks:
510
- id: black
611
language_version: python
@@ -11,19 +16,11 @@ repos:
1116
- id: isort
1217
language_version: python
1318

14-
- repo: https://github.com/PyCQA/flake8
15-
rev: 3.8.3
16-
hooks:
17-
- id: flake8
18-
language_version: python
19-
20-
- repo: https://github.com/PyCQA/pydocstyle
21-
rev: 6.1.1
19+
- repo: https://github.com/charliermarsh/ruff-pre-commit
20+
rev: v0.0.238
2221
hooks:
23-
- id: pydocstyle
24-
language_version: python
25-
additional_dependencies:
26-
- toml
22+
- id: ruff
23+
args: ["--fix"]
2724

2825
- repo: https://github.com/pre-commit/mirrors-mypy
2926
rev: v0.991

‎pyproject.toml‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ exclude = [
9292
requires = ["hatchling"]
9393
build-backend = "hatchling.build"
9494

95+
[tool.coverage.run]
96+
branch = true
97+
parallel = true
98+
99+
[tool.coverage.report]
100+
exclude_lines = [
101+
"no cov",
102+
"if __name__ == .__main__.:",
103+
"if TYPE_CHECKING:",
104+
]
95105

96106
[tool.isort]
97107
profile = "black"
@@ -106,6 +116,16 @@ default_section = "THIRDPARTY"
106116
[tool.mypy]
107117
no_strict_optional = "True"
108118

109-
[tool.pydocstyle]
110-
select = "D1"
111-
match = "(?!test).*.py"
119+
[tool.ruff]
120+
select = [
121+
"D1", # pydocstyle errors
122+
"E", # pycodestyle errors
123+
"W", # pycodestyle warnings
124+
"C", # flake8-comprehensions
125+
"B", # flake8-bugbear
126+
]
127+
ignore = [
128+
"E501", # line too long, handled by black
129+
"B008", # do not perform function calls in argument defaults
130+
"B905", # ignore zip() without an explicit strict= parameter, only support with python >3.10
131+
]

‎setup.py‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎tests/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""TiPG tests."""

‎tests/routes/test_geography.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
def test_geography_column(app):
8+
"""Test endpoints with table having geography column."""
89
response = app.get("/collections/public.my_data_geo")
910
assert response.status_code == 200
1011
assert response.headers["content-type"] == "application/json"

‎tests/routes/test_item.py‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ def test_item(app):
2121
assert response.status_code == 200
2222
assert response.headers["content-type"] == "application/json"
2323
feat = response.json()
24-
assert set(
25-
[
26-
"collectionId",
27-
"itemId",
28-
"id",
29-
"pr",
30-
"row",
31-
"path",
32-
"ogc_fid",
33-
"geometry",
34-
]
35-
) == set(feat.keys())
24+
assert {
25+
"collectionId",
26+
"itemId",
27+
"id",
28+
"pr",
29+
"row",
30+
"path",
31+
"ogc_fid",
32+
"geometry",
33+
} == set(feat.keys())
3634

3735
# not found
3836
response = app.get("/collections/public.landsat_wrs/items/50000")

‎tests/routes/test_items.py‎

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_items_properties(app):
141141
assert response.status_code == 200
142142
assert response.headers["content-type"] == "application/geo+json"
143143
body = response.json()
144-
assert sorted(["path", "row"]) == sorted(list(body["features"][0]["properties"]))
144+
assert sorted(["path", "row"]) == sorted(body["features"][0]["properties"])
145145

146146
# no properties
147147
response = app.get("/collections/public.landsat_wrs/items?properties=")
@@ -301,6 +301,7 @@ def test_items_properties_filter_cql2(app):
301301

302302

303303
def test_items_geo_filter_cql2(app):
304+
"""Test CQL2 geo filter."""
304305
response = app.get(
305306
"/collections/public.landsat_wrs/items?filter-lang=cql2-text&filter=S_INTERSECTS(geom, POLYGON((-22.2153 79.6888,-22.2153 81.8555,-8.97407 81.8555,-8.97407 79.6888,-22.2153 79.6888)))"
306307
)
@@ -311,6 +312,7 @@ def test_items_geo_filter_cql2(app):
311312

312313

313314
def test_items_geo_filter_cql2_non_4326_crs(app):
315+
"""Test CQL2 non 4326 geo filter."""
314316
response = app.get(
315317
"/collections/public.minnesota/items?filter-lang=cql2-text&filter=S_INTERSECTS(geom, POLYGON((-95.5389899 47.5578719,-95.5018943 46.4902864,-94.1637708 46.4891952,-94.1277889 47.5804373,-95.5389899 47.5578719)))"
316318
)
@@ -322,6 +324,7 @@ def test_items_geo_filter_cql2_non_4326_crs(app):
322324

323325

324326
def test_items_function_filter_cql2(app):
327+
"""Test CQL2 filter with function."""
325328
response = app.get(
326329
"/collections/public.landsat_wrs/items?filter-lang=cql2-text&filter=left(pr,2)='13'"
327330
)
@@ -654,18 +657,16 @@ def test_output_response_type(app):
654657
body = response.json()
655658
assert len(body) == 10
656659
feat = body[0]
657-
assert set(
658-
[
659-
"collectionId",
660-
"itemId",
661-
"id",
662-
"pr",
663-
"row",
664-
"path",
665-
"ogc_fid",
666-
"geometry",
667-
]
668-
) == set(feat.keys())
660+
assert {
661+
"collectionId",
662+
"itemId",
663+
"id",
664+
"pr",
665+
"row",
666+
"path",
667+
"ogc_fid",
668+
"geometry",
669+
} == set(feat.keys())
669670

670671
# json output no geometry
671672
response = app.get("/collections/public.landsat_wrs/items?f=json&geom-column=none")
@@ -692,18 +693,16 @@ def test_output_response_type(app):
692693
body = response.text.splitlines()
693694
assert len(body) == 10
694695
feat = json.loads(body[0])
695-
assert set(
696-
[
697-
"collectionId",
698-
"itemId",
699-
"id",
700-
"pr",
701-
"row",
702-
"path",
703-
"ogc_fid",
704-
"geometry",
705-
]
706-
) == set(feat.keys())
696+
assert {
697+
"collectionId",
698+
"itemId",
699+
"id",
700+
"pr",
701+
"row",
702+
"path",
703+
"ogc_fid",
704+
"geometry",
705+
} == set(feat.keys())
707706

708707
response = app.get(
709708
"/collections/public.landsat_wrs/items",

‎tests/routes/test_tiles.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_tile(app):
5959
decoded = mapbox_vector_tile.decode(response.content)
6060
assert len(decoded["default"]["features"]) == 1000
6161
assert sorted(["id", "pr", "row", "path", "ogc_fid"]) == sorted(
62-
list(decoded["default"]["features"][0]["properties"])
62+
decoded["default"]["features"][0]["properties"]
6363
)
6464

6565
response = app.get(
@@ -68,7 +68,7 @@ def test_tile(app):
6868
assert response.status_code == 200
6969
decoded = mapbox_vector_tile.decode(response.content)
7070
assert sorted(["pr", "row", "path"]) == sorted(
71-
list(decoded["default"]["features"][0]["properties"])
71+
decoded["default"]["features"][0]["properties"]
7272
)
7373

7474
response = app.get(f"/collections/public.{name}/tiles/0/0/0?geom-column=geom")
@@ -84,6 +84,7 @@ def test_tile(app):
8484

8585

8686
def test_tile_custom_name(app):
87+
"""Test custom layer name."""
8788
init_value = mvt_settings.set_mvt_layername
8889
mvt_settings.set_mvt_layername = True
8990

@@ -116,7 +117,7 @@ def test_tile_tms(app):
116117
decoded = mapbox_vector_tile.decode(response.content)
117118
assert len(decoded["default"]["features"]) <= 1000
118119
assert sorted(["id", "pr", "row", "path", "ogc_fid"]) == sorted(
119-
list(decoded["default"]["features"][0]["properties"])
120+
decoded["default"]["features"][0]["properties"]
120121
)
121122

122123
response = app.get(
@@ -125,13 +126,14 @@ def test_tile_tms(app):
125126
assert response.status_code == 200
126127
decoded = mapbox_vector_tile.decode(response.content)
127128
assert sorted(["pr", "row", "path"]) == sorted(
128-
list(decoded["default"]["features"][0]["properties"])
129+
decoded["default"]["features"][0]["properties"]
129130
)
130131

131132
mvt_settings.set_mvt_layername = init_value
132133

133134

134135
def test_tile_tms_custom_name(app):
136+
"""test layername with tms."""
135137
init_value = mvt_settings.set_mvt_layername
136138
mvt_settings.set_mvt_layername = True
137139

‎tipg/dbmodel.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ def _geom(
456456

457457
return g
458458

459-
def _where(
459+
def _where( # noqa: C901
460460
self,
461461
ids: Optional[List[str]] = None,
462462
datetime: Optional[List[str]] = None,
@@ -577,9 +577,9 @@ def _datetime_filter_to_sql(self, interval: List[str], dt_name: str):
577577

578578
else:
579579
start = (
580-
parse_rfc3339(interval[0]) if not interval[0] in ["..", ""] else None
580+
parse_rfc3339(interval[0]) if interval[0] not in ["..", ""] else None
581581
)
582-
end = parse_rfc3339(interval[1]) if not interval[1] in ["..", ""] else None
582+
end = parse_rfc3339(interval[1]) if interval[1] not in ["..", ""] else None
583583

584584
if start is None and end is None:
585585
raise InvalidDatetime(
@@ -731,9 +731,11 @@ async def features(
731731
bbox_only: Optional[bool] = None,
732732
simplify: Optional[float] = None,
733733
geom_as_wkt: bool = False,
734-
function_parameters: Dict[str, str] = {},
734+
function_parameters: Optional[Dict[str, str]] = None,
735735
) -> Tuple[FeatureCollection, int]:
736736
"""Build and run Pg query."""
737+
function_parameters = function_parameters or {}
738+
737739
if geom and geom.lower() != "none" and not self.get_geometry_column(geom):
738740
raise InvalidGeometryColumnName(f"Invalid Geometry Column: {geom}.")
739741

@@ -872,7 +874,7 @@ def queryables(self) -> Dict:
872874

873875
async def get_collection_index( # noqa: C901
874876
db_pool: asyncpg.BuildPgPool,
875-
schemas: Optional[List[str]] = ["public"],
877+
schemas: Optional[List[str]] = None,
876878
tables: Optional[List[str]] = None,
877879
exclude_tables: Optional[List[str]] = None,
878880
exclude_table_schemas: Optional[List[str]] = None,
@@ -882,6 +884,7 @@ async def get_collection_index( # noqa: C901
882884
spatial: bool = True,
883885
) -> Database:
884886
"""Fetch Table and Functions index."""
887+
schemas = schemas or ["public"]
885888

886889
query = """
887890
SELECT pg_temp.tipg_catalog(

0 commit comments

Comments
 (0)