From 900b5efff55e3e51f168415372dcb4f2a55fecfd Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 18 Mar 2021 12:20:17 +0100 Subject: [PATCH] [chore] Minor cleanup --- flaschengeist/models/__init__.py | 7 +++++-- flaschengeist/plugins/__init__.py | 16 ++++++++++------ flaschengeist/plugins/auth_plain/__init__.py | 10 ++++++---- flaschengeist/utils/datetime.py | 7 +++++-- setup.py | 4 +--- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/flaschengeist/models/__init__.py b/flaschengeist/models/__init__.py index 59bb5b5..5f9484a 100644 --- a/flaschengeist/models/__init__.py +++ b/flaschengeist/models/__init__.py @@ -14,8 +14,11 @@ class ModelSerializeMixin: return False import typing - if typing.get_origin(self.__class__.__annotations__[param]) is typing.Union and \ - typing.get_args(self.__class__.__annotations__[param])[1] is None: + + if ( + typing.get_origin(self.__class__.__annotations__[param]) is typing.Union + and isinstance(typing.get_args(self.__class__.__annotations__[param])[1], type(None)) + ): return getattr(self, param) is None def serialize(self): diff --git a/flaschengeist/plugins/__init__.py b/flaschengeist/plugins/__init__.py index d4249a9..6665830 100644 --- a/flaschengeist/plugins/__init__.py +++ b/flaschengeist/plugins/__init__.py @@ -62,9 +62,11 @@ class Plugin: Value stored in database (native python) """ try: - setting = _PluginSetting.query\ - .filter(_PluginSetting.plugin == self._plugin_name)\ - .filter(_PluginSetting.name == name).one() + setting = ( + _PluginSetting.query.filter(_PluginSetting.plugin == self._plugin_name) + .filter(_PluginSetting.name == name) + .one() + ) return setting.value except sqlalchemy.orm.exc.NoResultFound: if "default" in kwargs: @@ -78,9 +80,11 @@ class Plugin: name: String identifying the setting value: Value to be stored """ - setting = _PluginSetting.query \ - .filter(_PluginSetting.plugin == self._plugin_name) \ - .filter(_PluginSetting.name == name).one_or_none() + setting = ( + _PluginSetting.query.filter(_PluginSetting.plugin == self._plugin_name) + .filter(_PluginSetting.name == name) + .one_or_none() + ) if setting is not None: setting.value = value else: diff --git a/flaschengeist/plugins/auth_plain/__init__.py b/flaschengeist/plugins/auth_plain/__init__.py index 21f5254..c8de367 100644 --- a/flaschengeist/plugins/auth_plain/__init__.py +++ b/flaschengeist/plugins/auth_plain/__init__.py @@ -23,10 +23,12 @@ class AuthPlain(AuthPlugin): self.modify_user(admin, None, "admin") db.session.add(admin) db.session.commit() - logger.warning("New administrator user was added, please change the password or remove it before going into" - "production mode. Initial credentials:\n" - "name: admin\n" - "password: admin") + logger.warning( + "New administrator user was added, please change the password or remove it before going into" + "production mode. Initial credentials:\n" + "name: admin\n" + "password: admin" + ) def login(self, user: User, password: str): if user.has_attribute("password"): diff --git a/flaschengeist/utils/datetime.py b/flaschengeist/utils/datetime.py index cf97a00..9de34ad 100644 --- a/flaschengeist/utils/datetime.py +++ b/flaschengeist/utils/datetime.py @@ -1,7 +1,10 @@ import datetime -from backports.datetime_fromisoformat import MonkeyPatch +import sys -MonkeyPatch.patch_fromisoformat() +if sys.version_info < (3, 7): + from backports.datetime_fromisoformat import MonkeyPatch + + MonkeyPatch.patch_fromisoformat() def from_iso_format(date_str): diff --git a/setup.py b/setup.py index 34c4e84..2986a6e 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( packages=find_packages(), package_data={"": ["*.toml"]}, scripts=["run_flaschengeist"], - python_requires=">=3.6", + python_requires=">=3.7", install_requires=[ "Flask >= 1.1", "toml", @@ -19,8 +19,6 @@ setup( "flask_sqlalchemy", "flask_cors", "werkzeug", - # Needed for python < 3.7 - "backports-datetime-fromisoformat", ], extras_require={"ldap": ["flask_ldapconn", "ldap3"], "test": ["pytest", "coverage"]}, entry_points={