Skip to content

Commit d2fb383

Browse files
authored
Add flake8 Github Action (#331)
* Add flake8 Github Action * fix PEP8 format
1 parent 131b636 commit d2fb383

27 files changed

+220
-194
lines changed

.github/workflows/flake8.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: flake8 Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
flake8-lint:
7+
runs-on: ubuntu-latest
8+
name: Lint with flake8
9+
steps:
10+
- uses: actions/checkout@v1
11+
- uses: ricardochaves/python-lint@v1.3.0
12+
with:
13+
use-pylint: false
14+
use-pycodestyle: false
15+
use-flake8: true
16+
use-black: false
17+
use-mypy: false
18+
use-isort: false

docs/source/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import os
1616
import json
1717
import sys
18+
19+
import xrspatial
20+
21+
1822
sys.path.insert(0, os.path.abspath('../..'))
1923

2024
# -- Project information -----------------------------------------------------
@@ -23,7 +27,6 @@
2327
copyright = u'2021, makepath'
2428
author = u'makepath'
2529

26-
import xrspatial
2730
version = release = xrspatial.__version__
2831

2932
# -- General configuration ---------------------------------------------------

setup.py

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import os, sys
1+
import os
2+
import sys
23
import shutil
34
from setuptools import setup
4-
import pkg_resources
55

66
# build dependencies
77
import pyct.build
88

99
# dependencies
1010

11-
# datashader first, then pyct unless pyct version compatible with ds is specified
11+
# datashader first, then pyct unless pyct version compatible with ds
12+
# is specified
1213
# spatialpandas may not be required in final pharmacy_desert version
1314
# pyct may not be required after pyctdev is released
1415
install_requires = [
@@ -22,18 +23,18 @@
2223
'scipy',
2324
'xarray',
2425
'pyct <=0.4.6',
25-
]
26+
]
2627

2728
examples = [
28-
'spatialpandas',
29+
'spatialpandas',
2930
]
3031

3132
# Additional tests dependencies and examples_extra may be needed in the future
3233
extras_require = {
33-
'tests': [
34-
'pytest',
35-
],
36-
'examples': examples,
34+
'tests': [
35+
'pytest',
36+
],
37+
'examples': examples,
3738
}
3839

3940
# additional doc dependencies may be needed
@@ -44,37 +45,37 @@
4445
# metadata for setuptools
4546

4647
setup_args = dict(
47-
name='xarray-spatial',
48-
use_scm_version={
49-
"write_to": "xrspatial/_version.py",
50-
"write_to_template": '__version__ = "{version}"',
51-
"tag_regex": r"^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$",
52-
},
53-
description='xarray-based spatial analysis tools',
54-
install_requires=install_requires,
55-
extras_require=extras_require,
56-
tests_require=extras_require['tests'],
57-
zip_safe=False,
58-
classifiers=["Programming Language :: Python :: 3",
59-
"License :: OSI Approved :: MIT License",
60-
"Operating System :: OS Independent"],
61-
packages=['xrspatial',
62-
'xrspatial.tests'
63-
],
64-
include_package_data=True,
65-
entry_points={
66-
'console_scripts': [
67-
'xrspatial = xrspatial.__main__:main'
68-
]
69-
},
48+
name='xarray-spatial',
49+
use_scm_version={
50+
'write_to': 'xrspatial/_version.py',
51+
'write_to_template': '__version__ = "{version}"',
52+
'tag_regex': r'^(?P<prefix>v)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
53+
},
54+
description='xarray-based spatial analysis tools',
55+
install_requires=install_requires,
56+
extras_require=extras_require,
57+
tests_require=extras_require['tests'],
58+
zip_safe=False,
59+
classifiers=['Programming Language :: Python :: 3',
60+
'License :: OSI Approved :: MIT License',
61+
'Operating System :: OS Independent'],
62+
packages=['xrspatial',
63+
'xrspatial.tests'
64+
],
65+
include_package_data=True,
66+
entry_points={
67+
'console_scripts': [
68+
'xrspatial = xrspatial.__main__:main'
69+
]
70+
},
7071
)
7172

7273
if __name__ == '__main__':
73-
example_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
74-
'xarray-spatial', 'examples')
75-
if 'develop' not in sys.argv:
76-
pyct.build.examples(example_path, __file__, force=True)
77-
setup(**setup_args)
78-
79-
if os.path.isdir(example_path):
80-
shutil.rmtree(example_path)
74+
example_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
75+
'xarray-spatial', 'examples')
76+
if 'develop' not in sys.argv:
77+
pyct.build.examples(example_path, __file__, force=True)
78+
setup(**setup_args)
79+
80+
if os.path.isdir(example_path):
81+
shutil.rmtree(example_path)

test_examples_cli.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55

66
# test_args include copy-examples, fetch-data, or examples (does both)
77
def run_examples_cmds(*cli_cmds):
8-
98
"""
9+
Run conda package cli commands to download examples and fetch data
10+
for notebooks.
1011
11-
Run conda package cli commands to download examples and fetch data for notebooks
1212
Parameters: 'copy-examples', 'fetch-data', 'examples'
13-
Output: downloads examples and data to new xrspatial-examples directory in xarray-spatial
14-
13+
Output: downloads examples and data to new xrspatial-examples
14+
directory in xarray-spatialx
1515
"""
1616

1717
for arg in cli_cmds:
1818
with patch.object(sys, 'argv', ['xrspatial', arg]):
1919
m.main()
2020

21+
2122
run_examples_cmds('examples')

xrspatial/__main__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import os
2-
31
def main(args=None):
42
try:
53
import pyct.cmd
@@ -8,7 +6,8 @@ def main(args=None):
86
from . import _missing_cmd
97
print(_missing_cmd())
108
sys.exit(1)
11-
return pyct.cmd.substitute_main('xrspatial',args=args)
9+
return pyct.cmd.substitute_main('xrspatial', args=args)
10+
1211

1312
if __name__ == "__main__":
14-
main()
13+
main()

xrspatial/aspect.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ def aspect(agg: xr.DataArray,
179179
Notes:
180180
----------
181181
Algorithm References:
182-
- http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-aspect-works.htm#ESRI_SECTION1_4198691F8852475A9F4BC71246579FAA
183-
- Burrough, P. A., and McDonell, R. A., 1998.
184-
Principles of Geographical Information Systems
185-
(Oxford University Press, New York), pp 406
182+
- http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-aspect-works.htm#ESRI_SECTION1_4198691F8852475A9F4BC71246579FAA # noqa
183+
- Burrough, P. A., and McDonell, R. A., 1998. Principles of Geographical
184+
Information Systems (Oxford University Press, New York), pp 406
186185
187186
Examples:
188187
----------
@@ -217,7 +216,8 @@ def aspect(agg: xr.DataArray,
217216
* lon (lon) float64 0.0 1.0 2.0 3.0
218217
* lat (lat) float64 0.0 1.0 2.0 3.0 4.0
219218
220-
Terrain Example: https://makepath.github.io/xarray-spatial/assets/examples/user-guide.html
219+
Terrain Example:
220+
- https://makepath.github.io/xarray-spatial/assets/examples/user-guide.html
221221
"""
222222

223223
# numpy case

xrspatial/bump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def bump(width: int, height: int, count: Optional[int] = None,
118118
res: 1
119119
120120
Terrrain Example:
121-
- https://makepath.github.io/xarray-spatial/assets/examples/user-guide.html
121+
- https://makepath.github.io/xarray-spatial/assets/examples/user-guide.html # noqa
122122
"""
123123

124124
linx = range(width)
@@ -128,7 +128,7 @@ def bump(width: int, height: int, count: Optional[int] = None,
128128
count = width * height // 10
129129

130130
if height_func is None:
131-
height_func = lambda bumps: np.ones(len(bumps))
131+
height_func = lambda bumps: np.ones(len(bumps)) # noqa
132132

133133
# create 2d array of random x, y for bump locations
134134
locs = np.empty((count, 2), dtype=np.uint16)

xrspatial/classify.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,23 +358,23 @@ def quantile(agg: xr.DataArray,
358358
Number of quantiles to be produced, default = 4.
359359
name: str, optional (default = "quantile")
360360
Name of the output aggregate array.
361-
361+
362362
Returns:
363363
----------
364364
xarray.DataArray, quantiled aggregate
365365
2D array, of the same type as the input, of quantile allocations.
366366
All other input attributes are preserved.
367-
367+
368368
Notes:
369369
----------
370370
Adapted from PySAL:
371-
- https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#Quantiles
371+
- https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#Quantiles # noqa
372372
373373
Note that dask's percentile algorithm is approximate,
374374
while numpy's is exact. This may cause some differences
375375
between results of vanilla numpy and dask version of the input agg.
376-
- https://github.com/dask/dask/issues/3099
377-
376+
- https://github.com/dask/dask/issues/3099
377+
378378
Examples:
379379
----------
380380
Imports
@@ -455,7 +455,7 @@ def _run_numpy_jenks_matrices(data, n_classes):
455455
nl = data.shape[0] + 1
456456
variance = 0.0
457457

458-
for l in range(2, nl):
458+
for l in range(2, nl): # noqa
459459
sum = 0.0
460460
sum_squares = 0.0
461461
w = 0.0
@@ -573,7 +573,7 @@ def _run_cupy_jenks_matrices(data, n_classes):
573573
nl = data.shape[0] + 1
574574
variance = 0.0
575575

576-
for l in range(2, nl):
576+
for l in range(2, nl): # noqa
577577
sum = 0.0
578578
sum_squares = 0.0
579579
w = 0.0
@@ -709,9 +709,9 @@ def natural_breaks(agg: xr.DataArray,
709709
710710
Algorithm References:
711711
----------
712-
Map Classify
713-
- https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#NaturalBreaks
714-
perrygeo
712+
Map Classify:
713+
- https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#NaturalBreaks # noqa
714+
perrygeo:
715715
- https://github.com/perrygeo/jenks/blob/master/jenks.pyx
716716
717717
Examples:
@@ -850,8 +850,10 @@ def equal_interval(agg: xr.DataArray,
850850
851851
Algorithm References:
852852
----------
853-
PySal: https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#EqualInterval
854-
SciKit: https://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html#sphx-glr-auto-examples-classification-plot-classifier-comparison-py
853+
PySal:
854+
- https://pysal.org/mapclassify/_modules/mapclassify/classifiers.html#EqualInterval # noqa
855+
SciKit:
856+
- https://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html#sphx-glr-auto-examples-classification-plot-classifier-comparison-py # noqa
855857
856858
Examples:
857859
----------

xrspatial/convolution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def convolve_2d(image: xr.DataArray,
3535
convolve_agg: xarray.DataArray
3636
2D array representation of the impulse function.
3737
All other input attributes are preserverd.
38-
38+
3939
Examples:
4040
----------
4141
Imports
@@ -163,7 +163,7 @@ def _convolve_2d_cuda(result, kernel, image):
163163
# with k and l going through the whole kernel array:
164164
s = 0
165165
for k in range(kernel.shape[0]):
166-
for l in range(kernel.shape[1]):
166+
for l in range(kernel.shape[1]): # noqa
167167
i_k = i - k + delta_rows
168168
j_l = j - l + delta_cols
169169
# (-4-) Check if (i_k, j_k)

xrspatial/curvature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def curvature(agg: xr.DataArray,
127127
Notes:
128128
----------
129129
Algorithm References:
130-
- https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/how-curvature-works.htm
130+
- https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/how-curvature-works.htm # noqa
131131
132132
Examples:
133133
----------

0 commit comments

Comments
 (0)