Skip to content

Commit 9bbd877

Browse files
authored
maintenance & updates 2022 (#3)
* replace yapf with black & flake8 * fix tests with newer valhalla:latest image * update dependencies * jeez.. weird bug in flask-restx, needed to install stuff from git * edit the action workflow
1 parent b61774a commit 9bbd877

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1548
-1485
lines changed

.github/workflows/test-ubuntu.yml

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ on:
1010

1111
jobs:
1212
build:
13-
runs-on: ${{ matrix.os }}
14-
strategy:
15-
matrix:
16-
os: [ubuntu-20.04, ubuntu-18.04]
17-
python_version: [3.7, 3.8, 3.9]
13+
runs-on: ubuntu-20.04
1814
services:
1915
postgres:
2016
image: kartoza/postgis:12.1
@@ -43,16 +39,10 @@ jobs:
4339
steps:
4440
- uses: actions/checkout@v2
4541

46-
- name: Set up Python ${{ matrix.python_version }}
42+
- name: Set up Python 3.10
4743
uses: actions/setup-python@v2
4844
with:
49-
python-version: ${{ matrix.python_version }}
50-
51-
# From https://github.com/python-poetry/poetry/actions
52-
- name: Get full python version
53-
id: full-python-version
54-
run: |
55-
echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info[:3]))")
45+
python-version: '3.10'
5646

5747
- name: Install and set up Poetry
5848
run: |
@@ -64,7 +54,7 @@ jobs:
6454
uses: actions/cache@v2
6555
with:
6656
path: .venv
67-
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
57+
key: venv-3.10-${{ hashFiles('**/poetry.lock') }}
6858

6959
- name: Install dependencies
7060
run: |
@@ -77,29 +67,25 @@ jobs:
7767
7868
- name: Install osmium
7969
run: |
80-
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
81-
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC
82-
sudo add-apt-repository 'deb http://ftp.debian.org/debian sid main'
8370
sudo apt-get update
8471
sudo apt-get install -y -qq osmium-tool osmctools
8572
echo $(osmium --version)
8673
87-
- name: yapf linting
74+
- name: linting
8875
run: |
8976
source .venv/bin/activate
90-
yapf -r -vv --diff -p tests routing_packager_app config.py http_app.py gunicorn.py
77+
pre-commit run --all-files
9178
92-
- name: pytest
79+
- name: pytest and coverage
9380
run: |
9481
source .venv/bin/activate
9582
sudo python -m smtpd -n -c DebuggingServer localhost:1025 &
9683
sudo docker volume create routing-packager_packages --driver local --opt type=none --opt device=$PWD --opt o=bind
9784
pytest --cov=routing_packager_app --ignore=tests/test_tasks.py
85+
coverage lcov --include "routing_packager_app/*"
9886
9987
- name: coveralls
100-
run: |
101-
source .venv/bin/activate
102-
coveralls
103-
104-
env:
105-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
uses: coverallsapp/github-action@master
89+
with:
90+
github-token: ${{ secrets.GITHUB_TOKEN }}
91+
path-to-lcov: ./coverage.lcov

.pre-commit-config.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
repos:
2-
- repo: https://github.com/pre-commit/mirrors-yapf
3-
rev: v0.30.0 # Use the sha / tag you want to point at
2+
- repo: https://github.com/psf/black
3+
rev: 22.3.0
44
hooks:
5-
- id: yapf
5+
- id: black
6+
language_version: python3
7+
args: [routing_packager_app, tests]
8+
- repo: https://github.com/pycqa/flake8
9+
rev: 4.0.1 # pick a git hash / tag to point to
10+
hooks:
11+
- id: flake8

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#--- BEGIN Usual Python stuff ---
2-
FROM python:3.9-slim-buster
2+
FROM python:3.10-slim-bullseye
33
44

55
# Install poetry
@@ -21,14 +21,17 @@ RUN apt-get update -y > /dev/null && \
2121
RUN apt-get update -y > /dev/null && \
2222
apt-get install -y --fix-missing \
2323
software-properties-common \
24-
gnupg-agent \
24+
apt-transport-https \
25+
ca-certificates \
26+
curl \
27+
gnupg \
28+
lsb-release \
2529
nano \
2630
jq \
2731
cron -o APT::Immediate-Configure=0 > /dev/null && \
2832
# install docker & osmium
2933
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
3034
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
31-
add-apt-repository 'deb http://ftp.debian.org/debian sid main' && \
3235
apt-get update -y > /dev/null && \
3336
apt-get install -y docker-ce docker-ce-cli containerd.io osmium-tool osmctools > /dev/null && \
3437
systemctl enable docker

config.py

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,62 @@
33
from distutils.util import strtobool
44

55
basedir = os.path.abspath(os.path.dirname(__file__))
6-
load_dotenv(os.path.join(basedir, '.env'))
6+
load_dotenv(os.path.join(basedir, ".env"))
77

88

99
def _get_list_var(var):
1010
out = []
1111
if var:
12-
out.extend(var.split(','))
12+
out.extend(var.split(","))
1313

1414
return out
1515

1616

1717
class BaseConfig(object):
1818
### FLASK ###
19-
SECRET_KEY = os.getenv(
20-
'SECRET_KEY'
21-
) or '<MMs8?u_;rTt>;LarIGI&FjWhKNSe=%3|W;=DFDqOdx+~-rBS+K=p8#t#9E+;{e$'
19+
SECRET_KEY = (
20+
os.getenv("SECRET_KEY") or "<MMs8?u_;rTt>;LarIGI&FjWhKNSe=%3|W;=DFDqOdx+~-rBS+K=p8#t#9E+;{e$"
21+
)
2222
ERROR_INCLUDE_MESSAGE = False # No default "message" field in error responses
2323
RESTX_MASK_SWAGGER = False # No default MASK header in Swagger
2424
SQLALCHEMY_TRACK_MODIFICATIONS = False
2525

2626
### APP ###
27-
ADMIN_EMAIL = os.getenv('ADMIN_EMAIL') or '[email protected]'
28-
ADMIN_PASS = os.getenv('ADMIN_PASSWORD') or 'admin'
27+
ADMIN_EMAIL = os.getenv("ADMIN_EMAIL") or "[email protected]"
28+
ADMIN_PASS = os.getenv("ADMIN_PASSWORD") or "admin"
2929

30-
DATA_DIR = os.getenv('DATA_DIR') or os.path.join(basedir, 'data')
30+
DATA_DIR = os.getenv("DATA_DIR") or os.path.join(basedir, "data")
3131
# if we're inside a docker container, we need to reference the fixed directory instead
3232
# Watch out for CI, also runs within docker
33-
if os.path.isdir('/app/data') and not os.getenv('CI', None):
34-
DATA_DIR = '/app/data'
33+
if os.path.isdir("/app/data") and not os.getenv("CI", None):
34+
DATA_DIR = "/app/data"
3535

36-
ENABLED_PROVIDERS = _get_list_var(os.getenv('ENABLED_PROVIDERS')) or ['osm']
37-
ENABLED_ROUTERS = _get_list_var(os.getenv('ENABLED_ROUTERS')) or ['valhalla']
38-
VALHALLA_IMAGE = os.getenv('VALHALLA_IMAGE') or 'gisops/valhalla:latest'
39-
OSRM_IMAGE = os.getenv('OSRM_IMAGE') or 'osrm/osrm-backend:latest'
40-
ORS_IMAGE = os.getenv('ORS_IMAGE') or 'openrouteservice/openrouteservice:latest'
41-
GRAPHHOPPER_IMAGE = os.getenv('GRAPHHOPPER_IMAGE') or 'graphhopper/graphhopper:latest'
36+
ENABLED_PROVIDERS = _get_list_var(os.getenv("ENABLED_PROVIDERS")) or ["osm"]
37+
ENABLED_ROUTERS = _get_list_var(os.getenv("ENABLED_ROUTERS")) or ["valhalla"]
38+
VALHALLA_IMAGE = os.getenv("VALHALLA_IMAGE") or "gisops/valhalla:latest"
39+
OSRM_IMAGE = os.getenv("OSRM_IMAGE") or "osrm/osrm-backend:latest"
40+
ORS_IMAGE = os.getenv("ORS_IMAGE") or "openrouteservice/openrouteservice:latest"
41+
GRAPHHOPPER_IMAGE = os.getenv("GRAPHHOPPER_IMAGE") or "graphhopper/graphhopper:latest"
4242

4343
### DATABASES ###
44-
POSTGRES_HOST = os.getenv('POSTGRES_HOST') or 'localhost'
45-
POSTGRES_PORT = int(os.getenv('POSTGRES_PORT', int())) or 5432
46-
POSTGRES_DB = os.getenv('POSTGRES_DB') or 'gis'
47-
POSTGRES_USER = os.getenv('POSTGRES_USER') or 'docker'
48-
POSTGRES_PASS = os.getenv('POSTGRES_PASS') or 'docker'
49-
SQLALCHEMY_DATABASE_URI = os.getenv('POSTGRES_URL') or \
50-
f'postgresql://{POSTGRES_USER}:{POSTGRES_PASS}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}'
51-
REDIS_URL = os.getenv('REDIS_URL') or f'redis://localhost:6379/0'
44+
POSTGRES_HOST = os.getenv("POSTGRES_HOST") or "localhost"
45+
POSTGRES_PORT = int(os.getenv("POSTGRES_PORT", int())) or 5432
46+
POSTGRES_DB = os.getenv("POSTGRES_DB") or "gis"
47+
POSTGRES_USER = os.getenv("POSTGRES_USER") or "docker"
48+
POSTGRES_PASS = os.getenv("POSTGRES_PASS") or "docker"
49+
SQLALCHEMY_DATABASE_URI = (
50+
os.getenv("POSTGRES_URL")
51+
or f"postgresql://{POSTGRES_USER}:{POSTGRES_PASS}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB}"
52+
)
53+
REDIS_URL = os.getenv("REDIS_URL") or "redis://localhost:6379/0"
5254

5355
### SMTP ###
54-
SMTP_HOST = os.getenv('SMTP_HOST') or 'localhost'
55-
SMTP_PORT = int(os.getenv('SMTP_PORT', int())) or 1025
56-
SMTP_FROM = os.getenv('SMTP_FROM') or '[email protected]'
57-
SMTP_USER = os.getenv('SMTP_USER')
58-
SMTP_PASS = os.getenv('SMTP_PASS')
59-
SMTP_SECURE = bool(strtobool(os.getenv('SMTP_SECURE', 'False'))) or False
56+
SMTP_HOST = os.getenv("SMTP_HOST") or "localhost"
57+
SMTP_PORT = int(os.getenv("SMTP_PORT", int())) or 1025
58+
SMTP_FROM = os.getenv("SMTP_FROM") or "[email protected]"
59+
SMTP_USER = os.getenv("SMTP_USER")
60+
SMTP_PASS = os.getenv("SMTP_PASS")
61+
SMTP_SECURE = bool(strtobool(os.getenv("SMTP_SECURE", "False"))) or False
6062

6163

6264
class DevConfig(BaseConfig):
@@ -71,22 +73,24 @@ class TestingConfig(BaseConfig):
7173
TESTING = True
7274
FLASK_DEBUG = 0
7375

74-
POSTGRES_HOST = os.getenv('POSTGRES_HOST') or 'localhost'
75-
POSTGRES_PORT = os.getenv('POSTGRES_PORT') or '5432'
76-
POSTGRES_DB_TEST = os.getenv('POSTGRES_DB_TEST') or 'gis_test'
77-
POSTGRES_USER = os.getenv('POSTGRES_USER') or 'admin'
78-
POSTGRES_PASS = os.getenv('POSTGRES_PASS') or 'admin'
76+
POSTGRES_HOST = os.getenv("POSTGRES_HOST") or "localhost"
77+
POSTGRES_PORT = os.getenv("POSTGRES_PORT") or "5432"
78+
POSTGRES_DB_TEST = os.getenv("POSTGRES_DB_TEST") or "gis_test"
79+
POSTGRES_USER = os.getenv("POSTGRES_USER") or "admin"
80+
POSTGRES_PASS = os.getenv("POSTGRES_PASS") or "admin"
7981

80-
SQLALCHEMY_DATABASE_URI = os.getenv('POSTGRES_TEST_URL') or \
81-
f'postgresql://{POSTGRES_USER}:{POSTGRES_PASS}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB_TEST}'
82+
SQLALCHEMY_DATABASE_URI = (
83+
os.getenv("POSTGRES_TEST_URL")
84+
or f"postgresql://{POSTGRES_USER}:{POSTGRES_PASS}@{POSTGRES_HOST}:{POSTGRES_PORT}/{POSTGRES_DB_TEST}"
85+
)
8286

83-
DATA_DIR = os.path.join(basedir, 'tests', 'data')
84-
OSM_PBF_PATH = os.path.join(basedir, 'tests', 'data', 'andorra-200827.osm.pbf')
85-
TOMTOM_PBF_PATH = os.path.join(basedir, 'tests', 'data', 'liechtenstein-201109.tomtom.pbf')
86-
HERE_PBF_PATH = os.path.join(basedir, 'tests', 'data', 'liechtenstein-201109.here.pbf')
87+
DATA_DIR = os.path.join(basedir, "tests", "data")
88+
OSM_PBF_PATH = os.path.join(basedir, "tests", "data", "andorra-200827.osm.pbf")
89+
TOMTOM_PBF_PATH = os.path.join(basedir, "tests", "data", "liechtenstein-201109.tomtom.pbf")
90+
HERE_PBF_PATH = os.path.join(basedir, "tests", "data", "liechtenstein-201109.here.pbf")
8791

88-
ENABLED_ROUTERS = _get_list_var('valhalla')
89-
ENABLED_PROVIDERS = _get_list_var('osm,tomtom,here')
92+
ENABLED_ROUTERS = _get_list_var("valhalla")
93+
ENABLED_PROVIDERS = _get_list_var("osm,tomtom,here")
9094

91-
ADMIN_EMAIL = '[email protected]'
92-
ADMIN_PASS = 'admin'
95+
ADMIN_EMAIL = "[email protected]"
96+
ADMIN_PASS = "admin"

gunicorn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
bind = "0.0.0.0:5000"
22
# Generally we recommend (2 x $num_cores) + 1 as the number of workers to start off with
33
workers = 5
4-
worker_class = 'gevent'
4+
worker_class = "gevent"
55
worker_connections = 10
66
timeout = 30
77
keepalive = 2

http_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
@app.shell_context_processor
99
def make_shell_context():
10-
return {'db': db, 'User': User, 'Job': Job}
10+
return {"db": db, "User": User, "Job": Job}

0 commit comments

Comments
 (0)