Skip to content

Commit

Permalink
Merge pull request #95 from geoadmin/bug-log-query-string
Browse files Browse the repository at this point in the history
BGDIINF_SB-2197: Updated python packages and clean up unused packages
  • Loading branch information
ltshb authored Mar 28, 2022
2 parents 22ebd07 + 4ac36e4 commit 18e4974
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 447 deletions.
15 changes: 6 additions & 9 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ verify_ssl = true
name = "pypi"

[packages]
Flask = "~=1.1.2"
geojson = "~=2.5.0"
gevent = "~=21.1.2"
geojson = "~=2.5"
gevent = "~=21.12.0"
gunicorn = "~=20.1.0"
regex = "~=2020.7.14"
scipy = "~=1.5.2"
Shapely = "~=1.7.0"
Werkzeug = "~=1.0.1"
PyYAML = "~=5.3.1"
logging-utilities = "~=1.2.0"
Shapely = "~=1.8"
logging-utilities = "~=1.2"
Flask = "~=2.0"
PyYAML = "~=6.0"

[dev-packages]
mock = "~=4.0.2"
Expand Down
856 changes: 451 additions & 405 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def log_route():
def wrap_in_callback_if_present(response):
if "callback" in request.args:
response.headers['Content-Type'] = 'application/javascript'
response.data = '%s(%s)' % (request.args.get('callback'), response.get_data(as_text=True))
response.data = f'{request.args.get("callback")}({response.get_data(as_text=True)})'
return response


Expand Down
2 changes: 1 addition & 1 deletion app/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def get_logging_cfg():
print(f"LOGGING_CFG is {LOGGING_CFG}")

config = {}
with open(LOGGING_CFG, 'rt') as fd:
with open(LOGGING_CFG, 'rt', encoding='utf-8') as fd:
config = yaml.safe_load(path.expandvars(fd.read()))

logger.debug('Load logging configuration from file %s', LOGGING_CFG)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/raster/dbfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def dbfreader(f):
raise ValueError(f'Invalid DBF terminator {terminator}')

fields.insert(0, (b'DeletionFlag', b'C', 1, 0))
fmt = ''.join(['%ds' % fieldinfo[2] for fieldinfo in fields])
fmt = ''.join([f'{fieldinfo[2]}s' for fieldinfo in fields])
fmtsiz = struct.calcsize(fmt)
for i in range(numrec):
record = struct.unpack(fmt, f.read(fmtsiz))
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/raster/georaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ def __init__(self, min_x, min_y, max_x, max_y, filename):
self.resolution_y = None

def __str__(self):
return "%f, %f, %f, %f: %s" % (
self.min_x, self.min_y, self.max_x, self.max_y, self.filename
)
return f"{self.min_x}, {self.min_y}, {self.max_x}, {self.max_y}: {self.filename}"

def contains(self, x, y):
return self.min_x <= x < self.max_x and self.min_y <= y < self.max_y
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/raster/shputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def read_record_poly_line(fp):
curr_point = read_record_point(fp)
data['parts'][part_index]['points'].append(curr_point)
points_read += 1
if points_read == 0 or check_point == []:
if points_read == 0 or not check_point:
check_point = curr_point
elif curr_point == check_point:
break
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
r'.*\.swisstopo\.cloud',
]

ALLOWED_DOMAINS_PATTERN = '({})'.format('|'.join(ALLOWED_DOMAINS))
ALLOWED_DOMAINS_PATTERN = f"({'|'.join(ALLOWED_DOMAINS)})"
8 changes: 4 additions & 4 deletions app/helpers/validation/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def read_linestring():
if len(geom_to_shape.coords) > PROFILE_MAX_AMOUNT_POINTS:
abort(
413,
"Request Geometry contains too many points. Maximum number of points allowed: {}, "
"found {}".format(PROFILE_MAX_AMOUNT_POINTS, len(geom_to_shape.coords))
"Request Geometry contains too many points. Maximum number of points allowed: "
f"{PROFILE_MAX_AMOUNT_POINTS}, found {len(geom_to_shape.coords)}"
)
return geom_to_shape

Expand All @@ -76,8 +76,8 @@ def read_number_points():
else:
abort(
400,
"Please provide a numerical value for the parameter 'NbPoints'/'nb_points'" +
" smaller than {}".format(PROFILE_MAX_AMOUNT_POINTS)
"Please provide a numerical value for the parameter 'NbPoints'/'nb_points'"
f" smaller than {PROFILE_MAX_AMOUNT_POINTS}"
)
return nb_points

Expand Down
2 changes: 1 addition & 1 deletion app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def height_route():
abort(400, "Query is out of bounds")
alt = get_height(sr, lon, lat, georaster_utils)
if alt is None:
abort(400, 'Requested coordinate ({},{}) out of bounds in sr {}'.format(lon, lat, sr))
abort(400, f'Requested coordinate ({lon},{lat}) out of bounds in sr {sr}')
return {'height': str(alt)}


Expand Down
2 changes: 1 addition & 1 deletion app/statistics/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def load_json(filename):
with open(DATA_FOLDER + filename, "r") as json_file:
with open(DATA_FOLDER + filename, "r", encoding='utf-8') as json_file:
if json_file is None:
raise IOError("No metadata file found")
json_data = json.load(json_file)
Expand Down
8 changes: 3 additions & 5 deletions tests/unit_tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def setUp(self) -> None:

def __check_response(self, response, expected_status=200):
self.assertIsNotNone(response)
self.assertEqual(
response.status_code, expected_status, msg="%s" % response.get_data(as_text=True)
)
self.assertEqual(response.status_code, expected_status, msg=response.get_data(as_text=True))

def prepare_mock_and_test_post(self, mock_georaster_utils, body, expected_status):
prepare_mock(mock_georaster_utils)
Expand All @@ -65,7 +63,7 @@ def get_json_profile(self, params, expected_status=200):
return response
except Exception as e:
logger.exception(e)
self.fail('Call to test_instance failed: %s' % (e))
self.fail(f'Call to test_instance failed: {e}')

def get_csv_with_params(self, params):
return self.test_instance.get(
Expand Down Expand Up @@ -93,7 +91,7 @@ def verify_point_is_present(self, response, point, msg="point not present"):
def assert_response_contains(self, response, content):
self.assertTrue(
content in response.get_data(as_text=True),
msg="Response doesn't contain '%s' : '%s'" % (content, response.get_data(as_text=True))
msg=f"Response doesn't contain '{content}' : '{response.get_data(as_text=True)}'"
)

@patch('app.routes.georaster_utils')
Expand Down
21 changes: 8 additions & 13 deletions tests/unit_tests/test_profile_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ def test_no_smart_filling(self, mock_georaster_utils):
len(response),
PROFILE_DEFAULT_AMOUNT_POINTS,
msg="with 'dumb' filling, there should be no regard to resolution and default amount "
"of points has to be used (default: {}, actual: {})".format(
PROFILE_DEFAULT_AMOUNT_POINTS, len(response)
)
f"of points has to be used (default: {PROFILE_DEFAULT_AMOUNT_POINTS}, "
f"actual: {len(response)})"
)
# checking values, it should switch to the next value every 20 iteration (point in profile)
# i : 0 .... 19 20 .... 39 40 .... etc ... 198 199 (exception with the last point)
Expand All @@ -72,9 +71,8 @@ def test_no_smart_filling(self, mock_georaster_utils):
self.assertEqual(
value,
expected_value,
msg="Wrong value at index {} (tile index: {}, expected: {}, actual: {}".format(
i, value_index, expected_value, value
)
msg=f"Wrong value at index {i} (tile index: {value_index}, "
f"expected: {expected_value}, actual: {value}"
)

@patch('app.routes.georaster_utils')
Expand All @@ -85,7 +83,7 @@ def test_with_smart_filling(self, mock_georaster_utils):
11,
msg="with 'smart' filling, there should be no more points than the resolution permits,"
" in this case 20m of length with a resolution of 2m => 10points plus starting"
" points => 11 (was: {})".format(len(response))
f" points => 11 (was: {len(response)})"
)
# each values should be present only once, so we can test them in sequence (with the
# exception of rounding, the value at index 9 should be rounded to the first digit :
Expand All @@ -96,9 +94,7 @@ def test_with_smart_filling(self, mock_georaster_utils):
self.assertEqual(
value,
expected,
msg="Values don't match at index {} (expected: {}, actual: {})".format(
i, expected, value
)
msg=f"Values don't match at index {i} (expected: {expected}, actual: {value})"
)

@patch('app.routes.georaster_utils')
Expand Down Expand Up @@ -151,9 +147,8 @@ def test_keep_point_without_smart_fill(self, mock_georaster_utils):
self.assertEqual(
len(response),
PROFILE_DEFAULT_AMOUNT_POINTS,
msg="There should be an exactly {} points in the profile, found {}".format(
PROFILE_DEFAULT_AMOUNT_POINTS, len(response)
)
msg=f"There should be an exactly {PROFILE_DEFAULT_AMOUNT_POINTS} points in the profile,"
f" found {len(response)}"
)
# there should be our middle point somewhere in the profile
middle_point_found = False
Expand Down
2 changes: 1 addition & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def load(self):
ALTI_WORKERS = (multiprocessing.cpu_count() * 2) + 1
# Bind to 0.0.0.0 to let your app listen to all network interfaces.
options = {
'bind': '%s:%s' % ('0.0.0.0', HTTP_PORT),
'bind': f'0.0.0.0:{HTTP_PORT}',
'worker_class': 'gevent',
'workers': ALTI_WORKERS,
'access_log_format': '%(h)s %(l)s %(u)s "%(r)s" %(s)s %(B)s Bytes '
Expand Down

0 comments on commit 18e4974

Please sign in to comment.