Skip to content

Commit

Permalink
Merge pull request #78 from geoadmin/feat-BGDIINF_SB-2908-update-python
Browse files Browse the repository at this point in the history
…_3_9

BGDIINF_SB-2908: update python 3.7 towards python 3.9
  • Loading branch information
rebert authored May 30, 2023
2 parents e874641 + 70ab113 commit b54ce55
Show file tree
Hide file tree
Showing 7 changed files with 1,023 additions and 899 deletions.
11 changes: 6 additions & 5 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ limit-inference-results=100

# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=pylint_flask_sqlalchemy,pylint_sqlalchemy,pylint_flask
load-plugins=pylint_sqlalchemy,pylint_flask

# Pickle collected data for later comparisons.
persistent=yes
Expand Down Expand Up @@ -68,6 +68,7 @@ disable=missing-docstring,
too-many-arguments,
too-few-public-methods,
useless-object-inheritance,
superfluous-parens, # flask
fixme # remove this when done


Expand Down Expand Up @@ -163,7 +164,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis). It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
ignored-modules=flask_sqlalchemy

# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
Expand Down Expand Up @@ -522,6 +523,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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Buster slim python 3.7 base image.
FROM python:3.7-slim-buster as base
# Buster slim python 3.9 base image.
FROM python:3.9.16-slim-bullseye as base

RUN groupadd -r geoadmin && useradd -r -s /bin/false -g geoadmin geoadmin

Expand Down Expand Up @@ -68,4 +68,4 @@ USER geoadmin
EXPOSE $WMTS_PORT

# Use a real WSGI server
ENTRYPOINT ["python3", "wsgi.py"]
ENTRYPOINT ["python3", "wsgi.py"]
33 changes: 16 additions & 17 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,29 @@ verify_ssl = true
name = "pypi"

[packages]
PyYAML = "~=5.4.1"
gevent = "~=21.1.2"
PyYAML = "~=6.0"
gevent = "~=22.10.2"
gunicorn = "~=20.1.0"
Flask = "~=2.0.0"
logging-utilities = "~=3.0"
boto3 = "~=1.17.60"
pyproj = "~=3.0.1"
requests = "~=2.25.1"
Flask = "~=2.3.2"
logging-utilities = "~=4.0.0"
boto3 = "~=1.26.140"
pyproj = "~=3.5.0"
requests = "~=2.31.0"
gatilegrid = "~=0.2.0"
Pillow = "~=8.2.0"
python-dotenv = "~=0.17.0"
psycopg2 = "~=2.8.6"
SQLAlchemy = "~=1.4.15"
Flask-SQLAlchemy = "~=2.5.1"
Pillow = "~=9.5.0"
python-dotenv = "~=1.0.0"
psycopg2-binary = "~=2.9.6"
SQLAlchemy = "~=2.0.15"
Flask-SQLAlchemy = "~=3.0.3"

[dev-packages]
yapf = "*"
pylint = "*"
pylint-flask = "*"
nose2 = "*"
pylint = "*"
pylint_sqlalchemy = "~=0.2.0"
pylint_flask = "~=0.6"
requests-mock = "*"
pylint-sqlalchemy = "~=0.2.0"
pylint-flask-sqlalchemy = "~=0.2.0"
lxml = "*"

[requires]
python_version = "3.7"
python_version = "3.9"
1,803 changes: 946 additions & 857 deletions Pipfile.lock

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TileSetConcatenated(db.Model):
__tablename__ = 'view_tileset_concatenated'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})

id = db.Column('fk_dataset_id', db.Unicode, primary_key=True)
timestamps = db.Column('timestamps', db.ARRAY(db.Unicode))
Expand Down Expand Up @@ -65,31 +65,31 @@ class GetCap(object):

class GetCapFr(db.Model, GetCap):
__tablename__ = 'view_wmts_getcapabilities_fr'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})
query_class = QueryGetCap


class GetCapDe(db.Model, GetCap):
__tablename__ = 'view_wmts_getcapabilities_de'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})
query_class = QueryGetCap


class GetCapEn(db.Model, GetCap):
__tablename__ = 'view_wmts_getcapabilities_en'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})
query_class = QueryGetCap


class GetCapIt(db.Model, GetCap):
__tablename__ = 'view_wmts_getcapabilities_it'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})
query_class = QueryGetCap


class GetCapRm(db.Model, GetCap):
__tablename__ = 'view_wmts_getcapabilities_rm'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})
query_class = QueryGetCap


Expand All @@ -107,27 +107,27 @@ class GetCapThemes(object):

class GetCapThemesFr(db.Model, GetCapThemes):
__tablename__ = 'view_wmts_getcapabilities_themes_fr'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class GetCapThemesDe(db.Model, GetCapThemes):
__tablename__ = 'view_wmts_getcapabilities_themes_de'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class GetCapThemesIt(db.Model, GetCapThemes):
__tablename__ = 'view_wmts_getcapabilities_themes_it'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class GetCapThemesRm(db.Model, GetCapThemes):
__tablename__ = 'view_wmts_getcapabilities_themes_rm'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class GetCapThemesEn(db.Model, GetCapThemes):
__tablename__ = 'view_wmts_getcapabilities_themes_en'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class ServiceMetadata(object):
Expand All @@ -143,27 +143,27 @@ class ServiceMetadata(object):

class ServiceMetadataDe(db.Model, ServiceMetadata):
__tablename__ = 'view_wmts_service_metadata_de'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class ServiceMetadataFr(db.Model, ServiceMetadata):
__tablename__ = 'view_wmts_service_metadata_fr'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class ServiceMetadataIt(db.Model, ServiceMetadata):
__tablename__ = 'view_wmts_service_metadata_it'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class ServiceMetadataRm(db.Model, ServiceMetadata):
__tablename__ = 'view_wmts_service_metadata_rm'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


class ServiceMetadataEn(db.Model, ServiceMetadata):
__tablename__ = 'view_wmts_service_metadata_en'
__table_args__ = ({'schema': 'service-wmts', 'autoload': False})
__table_args__ = ({'schema': 'service-wmts'})


localized_models = {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_get_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_get_capabilities_invalid_param(self):
}
)

@patch('flask_sqlalchemy._QueryProperty.__get__')
@patch('flask_sqlalchemy.model._QueryProperty.__get__')
def test_get_capabilities_no_data_all_routes(self, query_mock):
query_mock.return_value.all.return_value = []
for url, url_args, url_params in [(
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 b54ce55

Please sign in to comment.