Skip to content

Commit e235927

Browse files
authored
Merge pull request #285 from lonvia/add-flake-linting
Github actions: add tests for linting and type checking
2 parents f8d9d13 + 7b15fe5 commit e235927

24 files changed

+120
-90
lines changed

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 100
3+
max-doc-length = 100
4+
per-file-ignores =
5+
__init__.py: F401

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ jobs:
1212
- name: Install packages
1313
run: |
1414
sudo apt-get update -y -qq
15-
sudo apt-get install -y -qq libboost-dev libexpat1-dev zlib1g-dev libbz2-dev libproj-dev libgeos-dev liblz4-dev
15+
sudo apt-get install -y -qq libboost-dev libexpat1-dev zlib1g-dev libbz2-dev libproj-dev libgeos-dev liblz4-dev pipx
16+
pipx install mypy
17+
pipx inject mypy types-requests
18+
pipx install flake8
19+
20+
- name: Lint package
21+
run: flake8 src examples
22+
23+
- name: Typecheck package
24+
run: mypy src
1625

1726
- name: Set up Python 3.7
1827
uses: actions/setup-python@v5

examples/amenity_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
wkbfab = osmium.geom.WKBFactory()
1515

16+
1617
class AmenityListHandler(osmium.SimpleHandler):
1718

1819
def print_amenity(self, tags, lon, lat):
@@ -37,6 +38,7 @@ def main(osmfile):
3738

3839
return 0
3940

41+
4042
if __name__ == '__main__':
4143
if len(sys.argv) != 2:
4244
print("Usage: python %s <osmfile>" % sys.argv[0])

examples/convert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@
2424
writer.add_relation(obj)
2525

2626
writer.close()
27-

examples/convert_to_geojson.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
geojsonfab = osmium.geom.GeoJSONFactory()
1212

13+
1314
class GeoJsonWriter(osmium.SimpleHandler):
1415

1516
def __init__(self):
@@ -48,7 +49,8 @@ def print_object(self, geojson, tags):
4849
def main(osmfile):
4950
handler = GeoJsonWriter()
5051

51-
handler.apply_file(osmfile,filters=[osmium.filter.EmptyTagFilter().enable_for(osmium.osm.NODE)])
52+
handler.apply_file(osmfile,
53+
filters=[osmium.filter.EmptyTagFilter().enable_for(osmium.osm.NODE)])
5254
handler.finish()
5355

5456
return 0

examples/filter_coastlines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
way_filter = osmium.filter.KeyFilter('natural').enable_for(osmium.osm.WAY)
3333

3434
# We need nodes and ways in the second pass.
35-
for obj in osmium.FileProcessor(sys.argv[1], osmium.osm.WAY | osmium.osm.NODE).with_filter(way_filter):
35+
for obj in osmium.FileProcessor(sys.argv[1], osmium.osm.WAY | osmium.osm.NODE) \
36+
.with_filter(way_filter):
3637
if obj.is_node() and obj.id in nodes:
3738
# Strip the object of tags along the way
3839
writer.add_node(obj.replace(tags={}))

examples/normalize_boolean.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import osmium
77
import sys
88

9+
910
class BoolNormalizer(osmium.SimpleHandler):
1011

1112
def __init__(self, writer):

examples/osm_diff_stats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import osmium
88
import sys
99

10+
1011
class Stats:
1112

1213
def __init__(self):
@@ -40,6 +41,7 @@ def main(osmfile):
4041

4142
return 0
4243

44+
4345
if __name__ == '__main__':
4446
if len(sys.argv) != 2:
4547
print("Usage: python %s <osmfile>" % sys.argv[0])

examples/osm_file_stats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import osmium
77
import sys
88

9+
910
class FileStatsHandler(osmium.SimpleHandler):
1011

1112
def __init__(self):
@@ -35,6 +36,7 @@ def main(osmfile):
3536

3637
return 0
3738

39+
3840
if __name__ == '__main__':
3941
if len(sys.argv) != 2:
4042
print("Usage: python %s <osmfile>" % sys.argv[0])

examples/osm_replication_stats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import datetime as dt
1010
import osmium.replication.server as rserv
1111

12-
class Stats(object):
12+
13+
class Stats:
1314

1415
def __init__(self):
1516
self.added = 0
@@ -24,12 +25,12 @@ def add(self, o):
2425
else:
2526
self.modified += 1
2627

27-
2828
def outstats(self, prefix):
2929
print("%s added: %d" % (prefix, self.added))
3030
print("%s modified: %d" % (prefix, self.modified))
3131
print("%s deleted: %d" % (prefix, self.deleted))
3232

33+
3334
class FileStatsHandler(osmium.SimpleHandler):
3435
def __init__(self):
3536
super(FileStatsHandler, self).__init__()
@@ -54,8 +55,7 @@ def relation(self, r):
5455

5556
server_url = sys.argv[1]
5657
start = dt.datetime.strptime(sys.argv[2], "%Y-%m-%dT%H:%M:%SZ")
57-
if sys.version_info >= (3,0):
58-
start = start.replace(tzinfo=dt.timezone.utc)
58+
start = start.replace(tzinfo=dt.timezone.utc)
5959
maxkb = min(int(sys.argv[3]), 10 * 1024)
6060

6161
repserv = rserv.ReplicationServer(server_url)

0 commit comments

Comments
 (0)