Skip to content

Commit

Permalink
Merge pull request #174 from cleder/170-modernize-packaging
Browse files Browse the repository at this point in the history
170 modernize packaging
  • Loading branch information
cleder authored Oct 25, 2023
2 parents 806c46e + c8420ff commit 930f6bf
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run-all-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
fail_ci_if_error: true
verbose: true
token: ${{ env.CODECOV_TOKEN }}

static-tests:
runs-on: ubuntu-latest
Expand Down
22 changes: 12 additions & 10 deletions pygeoif/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
from pygeoif.types import PolygonType

wkt_regex: Pattern[str] = re.compile(
r"^(SRID=(?P<srid>\d+);)?"
r"(?P<wkt>"
r"(?P<type>POINT|LINESTRING|LINEARRING|POLYGON|"
r"MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|"
r"GEOMETRYCOLLECTION)"
r"[ACEGIMLONPSRUTYZ\d,\.\-\(\) ]+)$",
re.I,
pattern=(
r"^(SRID=(?P<srid>\d+);)?"
"(?P<wkt>"
"(?P<type>POINT|LINESTRING|LINEARRING|POLYGON|"
"MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|"
"GEOMETRYCOLLECTION)"
r"[ACEGIMLONPSRUTYZ\d,\.\-\(\) ]+)$"
),
flags=re.I,
)
gcre: Pattern[str] = re.compile(r"POINT|LINESTRING|LINEARRING|POLYGON")
outer: Pattern[str] = re.compile(r"\((.+)\)")
Expand Down Expand Up @@ -78,7 +80,7 @@ def orient(polygon: Polygon, ccw: bool = True) -> Polygon: # noqa: FBT001, FBT0
rings.append(ring.coords)
else:
rings.append(list(ring.coords)[::-1])
return Polygon(rings[0], rings[1:])
return Polygon(shell=rings[0], holes=rings[1:])


def box(
Expand Down Expand Up @@ -228,8 +230,8 @@ def _polygon_from_wkt_coordinates(coordinates: str) -> Polygon:
]
interior, exteriors = _shell_holes_from_wkt_coords(coords)
return Polygon(
interior,
exteriors,
shell=interior,
holes=exteriors,
)


Expand Down
12 changes: 7 additions & 5 deletions pygeoif/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ def feature_geo_interface_equals(
my_interface["properties"] == other_interface.get("properties"),
my_interface["geometry"]["type"] == other_interface["geometry"].get("type"),
compare_coordinates(
my_interface["geometry"]["coordinates"],
other_interface["geometry"].get("coordinates"), # type: ignore[arg-type]
coords=my_interface["geometry"]["coordinates"],
other=other_interface["geometry"].get(
"coordinates",
), # type: ignore[arg-type]
),
],
)
Expand Down Expand Up @@ -96,8 +98,8 @@ def __eq__(self, other: object) -> bool:
except AttributeError:
return False
return feature_geo_interface_equals(
self.__geo_interface__,
other.__geo_interface__, # type: ignore [attr-defined]
my_interface=self.__geo_interface__,
other_interface=other.__geo_interface__, # type: ignore [attr-defined]
)

def __repr__(self) -> str:
Expand Down Expand Up @@ -176,7 +178,7 @@ def __eq__(self, other: object) -> bool:
"""Check if the geointerfaces are equal."""
return self._check_interface(other) and all(
(
feature_geo_interface_equals(mine, other)
feature_geo_interface_equals(my_interface=mine, other_interface=other)
for mine, other in zip(
self.__geo_interface__["features"],
other.__geo_interface__["features"], # type: ignore [attr-defined]
Expand Down
14 changes: 8 additions & 6 deletions pygeoif/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def _cross(o: Point2D, a: Point2D, b: Point2D) -> float:
def _build_hull(points: Iterable[Point2D]) -> List[Point2D]:
hull: List[Point2D] = []
for p in points:
while len(hull) >= 2 and _cross(hull[-2], hull[-1], p) <= 0: # noqa: PLR2004
while (
len(hull) >= 2 and _cross(o=hull[-2], a=hull[-1], b=p) <= 0 # noqa: PLR2004
):
hull.pop()
hull.append(p)
return hull
Expand Down Expand Up @@ -147,7 +149,7 @@ def compare_coordinates(
"""Compare two coordinate sequences."""
try:
return all(
compare_coordinates(c, o)
compare_coordinates(coords=c, other=o)
for c, o in zip_longest(
coords, # type: ignore [arg-type]
other, # type: ignore [arg-type]
Expand All @@ -156,7 +158,7 @@ def compare_coordinates(
)
except TypeError:
try:
return math.isclose(cast(float, coords), cast(float, other))
return math.isclose(a=cast(float, coords), b=cast(float, other))
except TypeError:
return False

Expand All @@ -171,16 +173,16 @@ def compare_geo_interface(
return False
if first["type"] == "GeometryCollection":
return all(
compare_geo_interface(g1, g2) # type: ignore [arg-type]
compare_geo_interface(first=g1, second=g2) # type: ignore [arg-type]
for g1, g2 in zip_longest(
first["geometries"], # type: ignore [typeddict-item]
second["geometries"], # type: ignore [typeddict-item]
fillvalue={"type": None, "coordinates": ()},
)
)
return compare_coordinates(
first["coordinates"], # type: ignore [typeddict-item]
second["coordinates"], # type: ignore [typeddict-item]
coords=first["coordinates"], # type: ignore [typeddict-item]
other=second["coordinates"], # type: ignore [typeddict-item]
)
except KeyError:
return False
Expand Down
27 changes: 15 additions & 12 deletions pygeoif/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def __eq__(self, other: object) -> bool:
"type",
),
compare_coordinates(
self.__geo_interface__["coordinates"],
other.__geo_interface__.get( # type: ignore [attr-defined]
coords=self.__geo_interface__["coordinates"],
other=other.__geo_interface__.get( # type: ignore [attr-defined]
"coordinates",
),
),
Expand Down Expand Up @@ -474,8 +474,8 @@ def centroid(self) -> Optional[Point]:
except ZeroDivisionError:
return None
return (
Point(cent[0], cent[1])
if math.isclose(area, signed_area(self.coords))
Point(x=cent[0], y=cent[1])
if math.isclose(a=area, b=signed_area(self.coords))
else None
)

Expand All @@ -502,7 +502,7 @@ def maybe_valid(self) -> bool:
_, area = centroid(self.coords)
except ZeroDivisionError:
return False
return math.isclose(area, signed_area(self.coords))
return math.isclose(a=area, b=signed_area(self.coords))


class Polygon(_Geometry):
Expand Down Expand Up @@ -634,14 +634,17 @@ def from_coordinates(cls, coordinates: PolygonType) -> "Polygon":
@classmethod
def from_linear_rings(cls, shell: LinearRing, *args: LinearRing) -> "Polygon":
"""Construct a Polygon from linear rings."""
return cls(shell.coords, tuple(lr.coords for lr in args))
return cls(
shell=shell.coords,
holes=tuple(lr.coords for lr in args),
)

@classmethod
def _from_dict(cls, geo_interface: GeoInterface) -> "Polygon":
cls._check_dict(geo_interface)
return cls(
cast(LineType, geo_interface["coordinates"][0]),
cast(Tuple[LineType], geo_interface["coordinates"][1:]),
shell=cast(LineType, geo_interface["coordinates"][0]),
holes=cast(Tuple[LineType], geo_interface["coordinates"][1:]),
)

def _check_interior_bounds(self) -> bool:
Expand Down Expand Up @@ -925,8 +928,8 @@ def __init__(self, polygons: Sequence[PolygonType], unique: bool = False) -> Non

self._geoms = tuple(
Polygon(
polygon[0],
polygon[1] # type: ignore [misc]
shell=polygon[0],
holes=polygon[1] # type: ignore [misc]
if len(polygon) == 2 # noqa: PLR2004
else None,
)
Expand Down Expand Up @@ -1061,8 +1064,8 @@ def __eq__(self, other: object) -> bool:
except AttributeError:
return False
return compare_geo_interface(
self.__geo_interface__,
other.__geo_interface__, # type: ignore [attr-defined]
first=self.__geo_interface__,
second=other.__geo_interface__, # type: ignore [attr-defined]
)

def __len__(self) -> int:
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ per-file-ignores =
tests/test_geometrycollection.py: ECE001,S101,D103,S307,DALL000
tests/test_factories.py: ECE001,S10,D10,S307,DALL000,PT009,T003
tests/test_feature.py: ECE001,S10,D10,S307,DALL000,PT009,T003,P103
feature.py: A003
types.py: A003
pygeoif/*: S604
pygeoif/types.py: A003
mutmut_config.py: TYP001
kwargs_ignore_function_pattern_extend = '^cast$'
literal_inline_quotes = double
literal_multiline_quotes = double
noqa_require_code = true
[mutmut]
paths_to_mutate=pygeoif/
test_dir=pygeoif/tests,
test_dir=tests/

0 comments on commit 930f6bf

Please sign in to comment.