From d6265c479711e7fa76196324ea27a9f4c194f053 Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Wed, 26 Feb 2020 22:01:25 -0500 Subject: [PATCH] Revert "Refactor datatypes into submodules" This reverts commit 07828f006337c8b232ef4ecc5d02cd5a0afc5c01. --- keyosk/config/__init__.py | 1 - keyosk/config/storage.py | 14 +++----------- keyosk/database/__init__.py | 5 +++-- keyosk/datatypes.py | 18 ++++++++++++++++++ keyosk/datatypes/__init__.py | 8 -------- tests/test_config.py | 3 ++- tox.ini | 2 +- 7 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 keyosk/datatypes.py delete mode 100644 keyosk/datatypes/__init__.py diff --git a/keyosk/config/__init__.py b/keyosk/config/__init__.py index 03a3aa2..9b5f92f 100644 --- a/keyosk/config/__init__.py +++ b/keyosk/config/__init__.py @@ -13,7 +13,6 @@ import toml from keyosk import constants from keyosk.config.storage import KeyoskStorageConfig -from keyosk.config.storage import StorageBackend # pylint: disable=unused-import from keyosk.config.storage import StorageConfigSerializer diff --git a/keyosk/config/storage.py b/keyosk/config/storage.py index d26a7b9..8fdb118 100644 --- a/keyosk/config/storage.py +++ b/keyosk/config/storage.py @@ -1,5 +1,4 @@ """Data containers and utilities related to the storage configuration""" -import enum from dataclasses import asdict from dataclasses import dataclass from dataclasses import field @@ -12,17 +11,10 @@ from typing import Union import marshmallow as msh +from keyosk import datatypes from keyosk import fields as custom_fields -@enum.unique -class StorageBackend(enum.Enum): - """Supported storage backends""" - - SQLITE = "sqlite" - MARIA = "maria" - - def _default_sqlite_pragmas() -> Dict[str, Any]: """Generate the default pragmas for the sqlite connection @@ -139,7 +131,7 @@ class KeyoskStorageConfig: time, depending on the value of the ``backend`` setting. """ - backend: StorageBackend = StorageBackend.SQLITE + backend: datatypes.StorageBackend = datatypes.StorageBackend.SQLITE sqlite: KeyoskSQLiteStorageConfig = KeyoskSQLiteStorageConfig() maria: KeyoskMariaStorageConfig = KeyoskMariaStorageConfig() @@ -151,7 +143,7 @@ class StorageConfigSerializer(msh.Schema): :class:`KeyoskStorageConfig` class. """ - backend = custom_fields.EnumItem(StorageBackend, pretty_names=True) + backend = custom_fields.EnumItem(datatypes.StorageBackend, pretty_names=True) sqlite = msh.fields.Nested(SQLiteStorageConfigSerializer) maria = msh.fields.Nested(MariaStorageConfigSerializer) diff --git a/keyosk/database/__init__.py b/keyosk/database/__init__.py index fb75f82..c648750 100644 --- a/keyosk/database/__init__.py +++ b/keyosk/database/__init__.py @@ -24,6 +24,7 @@ from typing import Type import peewee from keyosk import config +from keyosk import datatypes from keyosk.database._shared import INTERFACE as interface from keyosk.database._shared import KeyoskBaseModel from keyosk.database.account import Account @@ -56,7 +57,7 @@ def initialize(conf: config.KeyoskConfig): logger = logging.getLogger(__name__) - if conf.storage.backend == config.StorageBackend.SQLITE: + if conf.storage.backend == datatypes.StorageBackend.SQLITE: logger.debug("Using SQLite database backend") logger.debug(f"Applying SQLite pragmas: {conf.storage.sqlite.pragmas}") # Explicit cast-to-string on the path is to support py3.6: sqlite driver @@ -65,7 +66,7 @@ def initialize(conf: config.KeyoskConfig): str(conf.storage.sqlite.path), pragmas=conf.storage.sqlite.pragmas ) - elif conf.storage.backend == config.StorageBackend.MARIA: + elif conf.storage.backend == datatypes.StorageBackend.MARIA: logger.debug("Using MariaDB database backend") logger.debug( f"Configuring MariaDB: {conf.storage.maria.username}@{conf.storage.maria.host}:{conf.storage.maria.port}, with database '{conf.storage.maria.schema}'" diff --git a/keyosk/datatypes.py b/keyosk/datatypes.py new file mode 100644 index 0000000..088b4e6 --- /dev/null +++ b/keyosk/datatypes.py @@ -0,0 +1,18 @@ +"""Shared types, enums, and data containers""" +import enum +from typing import Dict +from typing import Union + + +Extras = Dict[str, Union[int, float, bool, str, None]] + + +TokenClaims = Dict[str, Union[str, int, bool, Dict[str, int]]] + + +@enum.unique +class StorageBackend(enum.Enum): + """Supported storage backends""" + + SQLITE = "sqlite" + MARIA = "maria" diff --git a/keyosk/datatypes/__init__.py b/keyosk/datatypes/__init__.py deleted file mode 100644 index 86dcbe0..0000000 --- a/keyosk/datatypes/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -from typing import Dict -from typing import Union - - -Extras = Dict[str, Union[int, float, bool, str, None]] - - -TokenClaims = Dict[str, Union[str, int, bool, Dict[str, int]]] diff --git a/tests/test_config.py b/tests/test_config.py index 52ba773..c4fb69b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -5,6 +5,7 @@ import toml from keyosk import config from keyosk import constants +from keyosk import datatypes DEMO_CONFIG = { @@ -38,7 +39,7 @@ def test_roundtrip(): def test_settings(): loaded = config.ConfigSerializer().load(DEMO_CONFIG) - assert loaded.storage.backend == config.StorageBackend.MARIA + assert loaded.storage.backend == datatypes.StorageBackend.MARIA assert loaded.storage.sqlite.path == Path(DEMO_CONFIG["storage"]["sqlite"]["path"]) assert loaded.storage.sqlite.pragmas == DEMO_CONFIG["storage"]["sqlite"]["pragmas"] for key, value in DEMO_CONFIG["storage"]["maria"].items(): diff --git a/tox.ini b/tox.ini index 1070af0..53669fd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36, py37, py38, lint, typing, security, docs +envlist = py37, py36, lint, typing, security, docs isolated_build = true [testenv]