Skip to content

Commit 2d0e673

Browse files
committed
linted
1 parent 8c5fb05 commit 2d0e673

3 files changed

Lines changed: 78 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,77 @@ license = {text = "GPL-3.0-or-later"}
3131
dynamic = ["version"]
3232

3333
[project.optional-dependencies]
34-
docs = ["folium", "GitPython", "jupyterlab_myst", "mapclassify", "matplotlib",
35-
"myst-nb", "nbsphinx", "pybtex-apa7-style", "sphinx",
36-
"sphinx-book-theme", "sphinx-design", "sphinxcontrib-bibtex",
37-
"sphinxcontrib-images", "xyzservices"]
38-
tests = ["pytest", "pytest-cov", "pytest-lazy-fixtures"]
34+
dev = [
35+
"black",
36+
"flake8",
37+
"flake8-bugbear",
38+
"flake8-pyproject",
39+
"isort",
40+
"pydocstyle",
41+
"pylint",
42+
]
43+
docs = [
44+
"folium",
45+
"GitPython",
46+
"jupyterlab_myst",
47+
"mapclassify",
48+
"matplotlib",
49+
"myst-nb",
50+
"nbsphinx",
51+
"pybtex-apa7-style",
52+
"sphinx",
53+
"sphinx-book-theme",
54+
"sphinx-design",
55+
"sphinxcontrib-bibtex",
56+
"sphinxcontrib-images",
57+
"xyzservices",
58+
]
59+
tests = [
60+
"pytest",
61+
"pytest-cov",
62+
"pytest-lazy-fixtures",
63+
]
3964

4065
[project.urls]
4166
Documentation = "https://python-cartogram.readthedocs.org/"
4267
Repository = "https://github.com/austromorph/python-cartogram"
4368
"Change log" = "https://github.com/austromorph/python-cartogram/blob/main/CHANGELOG.md"
4469
"Bug tracker" = "https://github.com/austromorph/python-cartogram/issues"
4570

71+
[tool.coverage.paths]
72+
equivalent_sources = [
73+
"src/cartogram/",
74+
".virtualenv/lib/python*/site-packages/cartogram/",
75+
"/opt/hostedtoolcache/Python/*/x64/lib/python*/site-packages/cartogram/",
76+
"/Library/Frameworks/Python.framework/Versions/*/lib/python*/site-packages/cartogram/",
77+
"C:/hostedtoolcache/windows/Python/*/x64/Lib/site-packages/cartogram/"
78+
]
79+
80+
[tool.coverage.report]
81+
exclude_also = [
82+
'if __name__ == .__main__.:',
83+
]
84+
4685
[tool.coverage.run]
4786
omit = ["tests/*", ".virtualenv/**/*"]
4887

88+
[tool.flake8]
89+
exclude = ["build", "dist", "docs/conf.py", ".virtualenv"]
90+
extent-ignore = ["E203", "E501", "E701"]
91+
extent-select = ["B950"]
92+
max-line-length = 88
93+
94+
[tool.isort]
95+
profile = "black"
96+
skip = ["build", "dist", "docs/conf.py", ".virtualenv"]
97+
98+
[tool.pydocstyle]
99+
#match-dir = "^(src|tests|build_backend).*"
100+
101+
[tool.pylintrc]
102+
good-names = ["i", "j", "k", "e", "ex", "id", "Run", "_"]
103+
max-line-length = 88
104+
49105
[tool.pytest.ini_options]
50106
addopts = "--cov=cartogram --cov-report term-missing --cov-report xml"
51107
pythonpath = ["src"]

src/cartogram/cartogram.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import pandas
1414
import shapely
1515

16-
1716
__all__ = ["Cartogram"]
1817

1918

@@ -39,15 +38,13 @@ class Cartogram(geopandas.GeoDataFrame):
3938
_constructor_sliced = pandas.Series
4039

4140
@classmethod
42-
def _geodataframe_constructor_with_fallback(
43-
cls, *args, **kwargs
44-
):
41+
def _geodataframe_constructor_with_fallback(cls, *args, **kwargs):
4542
"""
46-
A flexible constructor for Cartogram.
43+
Provide a flexible constructor for Cartogram.
4744
4845
Checks whether or not arguments of the child class are used.
4946
"""
50-
if "cartogram_attribute" in kwargs.keys():
47+
if "cartogram_attribute" in kwargs:
5148
df = cls(*args, **kwargs)
5249
else:
5350
df = geopandas.GeoDataFrame(*args, **kwargs)
@@ -131,7 +128,8 @@ def _check_geodata(self):
131128
for geometry_type in geometry_types:
132129
if geometry_type not in ["MultiPolygon", "Polygon"]:
133130
raise ValueError(
134-
f"Only POLYGON or MULTIPOLYGON geometries supported, found {geometry_type}."
131+
"Only POLYGON or MULTIPOLYGON geometries supported, "
132+
f"found {geometry_type}."
135133
)
136134
self._input_is_multipolygon = "MultiPolygon" in geometry_types
137135

@@ -179,15 +177,17 @@ def _feature_error(self, feature):
179177

180178
return error
181179

182-
def _invalidate_cached_properties(self, properties=[]):
180+
def _invalidate_cached_properties(self, properties=None):
183181
"""Invalidate properties that were cached as `functools.cached_property`."""
184182
# https://stackoverflow.com/a/68316608
185183
if not properties:
186184
# # clear all as default
187185
# properties = [
188186
# attribute
189187
# for attribute in self.__dict__.keys()
190-
# if isinstance(getattr(self, attribute, None), functools.cached_property)
188+
# if isinstance(
189+
# getattr(self, attribute, None),
190+
# functools.cached_property)
191191
# ]
192192
properties = [
193193
attr
@@ -215,7 +215,12 @@ def _transform(self):
215215
self.iteration < self.max_iterations
216216
and self.average_error > self.max_average_error
217217
):
218-
# self.geometry = self.geometry.apply(functools.partial(self._transform_geometry, features=self._cartogram_features))
218+
# self.geometry = self.geometry.apply(
219+
# functools.partial(
220+
# self._transform_geometry,
221+
# features=self._cartogram_features
222+
# )
223+
# )
219224
with joblib.Parallel(
220225
verbose=(self.verbose * 10),
221226
n_jobs=NUM_THREADS,
@@ -234,7 +239,8 @@ def _transform(self):
234239
self.iteration += 1
235240
if self.verbose:
236241
print(
237-
f"{self.average_error:0.5f} error left after {self.iteration:d} iteration(s)"
242+
f"{self.average_error:0.5f} error left "
243+
f"after {self.iteration:d} iteration(s)"
238244
)
239245

240246
self.geometry = self.geometry.buffer(0.0)

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import geopandas
1515
import pytest
1616

17-
1817
DATA_DIRECTORY = pathlib.Path(__file__).resolve().parent / "data"
1918
AUSTRIA_NUTS2_POPULATION = DATA_DIRECTORY / "Austria_PopulationByNUTS2.geojson"
2019
AUSTRIA_NUTS2_POPULATION_CARTOGRAM = (

0 commit comments

Comments
 (0)