Skip to content

Commit

Permalink
Merge pull request #69 from geoadmin/feature_BGDIINF_SB-2944_update_p…
Browse files Browse the repository at this point in the history
…ython_to_3.11

BGDIINF_SB-2944: Update to python3.11
  • Loading branch information
IsabelleBzr authored Jun 30, 2023
2 parents 273733b + 90499c9 commit 52b8922
Show file tree
Hide file tree
Showing 8 changed files with 612 additions and 445 deletions.
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,6 @@ min-public-methods=2

# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception,
StandardError
overgeneral-exceptions=builtins.BaseException,
builtins.Exception,
builtins.StandardError
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-slim-buster
FROM python:3.11-slim-buster
RUN groupadd -r geoadmin && useradd -u 1000 -r -s /bin/false -g geoadmin geoadmin


Expand Down
16 changes: 8 additions & 8 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ name = "pypi"

[packages]
PyYAML = ">=5.4"
gevent = "~=20.9.0"
gunicorn = "~=19.9.0"
Flask = "~=2.1.1"
logging-utilities = "~=3.0"
gevent = "~=22.10.2"
gunicorn = "~=20.1.0"
Flask = "~=2.3.2"
logging-utilities = "~=4.0.0"
defusedxml = "~=0.7.1"
boto3 = "~=1.17.60"
botocore = "~=1.20.98"
boto3 = "~=1.26.158"
botocore = "~=1.29.158"
moto = {extras = [ "s3",], version = "*"}
python-dotenv = "~=0.17.0"
python-dotenv = "~=1.0.0"

[dev-packages]
yapf = "*"
Expand All @@ -23,4 +23,4 @@ pylint = "*"
pylint-flask = "*"

[requires]
python_version = "3.9"
python_version = "3.11"
980 changes: 556 additions & 424 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ See also [Git Flow - Versioning](https://github.com/geoadmin/doc-guidelines/blob

### Make Dependencies

The **Make** targets assume you have **python3.7**, **pipenv**, **bash**, **curl**, **tar**, **docker** and **docker-compose** installed.
The **Make** targets assume you have **python3.11**, **pipenv**, **bash**, **curl**, **tar**, **docker** and **docker-compose** installed.

### Setting up to work

Expand Down Expand Up @@ -131,7 +131,7 @@ Here some curl examples

```bash
# post a kml
curl -X POST http://localhost:5000/api/kml/admin -F kml="@./tests/samples/valid-kml.xml; type=application/vnd.google-earth.kml+xml" -H "Origin: map.geo.admin.ch"
curl -X POST http://localhost:5000/api/kml/admin -F kml="@./tests/samples/valid-kml.xml; type=application/vnd.google-earth.kml+xml" -F author="test" -H "Origin: map.geo.admin.ch"

# get the kml metadata
curl http://localhost:5000/api/kml/admin/${KML_ID} -H "Origin: map.geo.admin.ch"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def prepare_kml_payload(
with open(f'./tests/samples/{kml_file}', 'rb') as file:
kml_data = file.read()
if admin_id and kml_data:
data = dict(admin_id=admin_id, kml=(io.BytesIO(kml_data), 'kml.xml', content_type))
data = {'admin_id': admin_id, 'kml': (io.BytesIO(kml_data), 'kml.xml', content_type)}
elif kml_data:
data = dict(kml=(io.BytesIO(kml_data), 'kml.xml', content_type))
data = {'kml': (io.BytesIO(kml_data), 'kml.xml', content_type)}
elif admin_id:
data = dict(admin_id=admin_id)
data = {'admin_id': admin_id}
else:
raise ValueError('No admin_id and no kml_string given')

Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def test_kml_delete(self):
response = self.app.delete(
url_for('delete_kml', kml_id=id_to_delete),
content_type='multipart/form-data',
data=dict(admin_id=self.sample_kml['admin_id']),
data={'admin_id': self.sample_kml['admin_id']},
headers=self.origin_headers["allowed"]
)
self.assertEqual(response.status_code, 200)
Expand Down Expand Up @@ -562,7 +562,7 @@ def test_kml_delete_non_allowed_origin(self):

response = self.app.delete(
url_for('delete_kml', kml_id=id_to_delete),
data=dict(admin_id=self.sample_kml['admin_id']),
data={'admin_id': self.sample_kml['admin_id']},
content_type='multipart/form-data',
headers=self.origin_headers["bad"]
)
Expand All @@ -577,7 +577,7 @@ def test_kml_delete_non_allowed_admin_id(self):
response = self.app.delete(
url_for('delete_kml', kml_id=id_to_delete),
content_type='multipart/form-data',
data=dict(admin_id='invalid-id'),
data={'admin_id': 'invalid-id'},
headers=self.origin_headers["allowed"]
)
self.assertEqual(response.status_code, 403)
Expand All @@ -604,7 +604,7 @@ def test_kml_delete_wrong_content_type(self):
response = self.app.delete(
url_for('delete_kml', kml_id=id_to_delete),
content_type='application/json',
data=dict(admin_id=self.sample_kml['admin_id']),
data={'admin_id': self.sample_kml['admin_id']},
headers=self.origin_headers["allowed"]
)
self.assertEqual(response.status_code, 415)
Expand Down
35 changes: 35 additions & 0 deletions update_to_latest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# This script updates the Pipfile automatically. It will update all version strings of type
# "~=x.x.x" to their respective latest version. Version strings of dependencies that use other
# version specifiers (like "*") will be left untouched. All dependencies will be updated
# (with "pipenv update") in the process.
# A regex can be optionally specified as first argument. In this case, only the version strings
# of packages matching the regex will be updated. (e.g. update_to_latest.sh 'django.*')
# This script is meant as a helper only. Use git to revert unwanted changes made by this script.

cd "$(dirname "$0")" || exit
#If an argument was passed to the script, it will be used as a regular expression
#Else we will simply match any package name
regexp=${1:-'\S+'}
line_regexp="^($regexp) = \"~=[0-9\\.]+\"(.*)$"

#Generate an array of all packages that need to be updated and switch their version to "*"
packages_to_modify=( $(cat Pipfile | sed -En "s/$line_regexp/\1/ip") )
echo "The script will try to update the following packages: ${packages_to_modify[*]}"
read -p "Do you want to contnue? [Y|N] " -n 1 -r
echo
[[ ! $REPLY =~ ^[Yy]$ ]] && exit
sed -Ei "s/$line_regexp/\1 = \"*\"\2/i" Pipfile

# Update the packages to the latest version
pipenv update --dev

# Set the current version in the Pipfile (only for the packages that were updated)
updateVersions=""
while read -r name version ; do
if [[ " ${packages_to_modify[*]} " == *" $name "* ]] ; then
updateVersions+="/^$name =/s/\"\\*\"/$version/"
updateVersions+=$'\n'
fi
done < <(pipenv run pip freeze | sed -E 's/==([0-9\.]+\w*)/ "~=\1"/')
sed -Ei -f <(echo "$updateVersions") Pipfile

0 comments on commit 52b8922

Please sign in to comment.