From 7723acb81229ed82741895ebfdba9f8b08f3b620 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Thu, 13 Oct 2022 12:13:37 +0200 Subject: [PATCH] [breaking] domain description is defined in a dict, not in "__name__", "__id__", "__routers__" ... --- CHANGELOG.md | 1 + halfapi/half_domain.py | 15 +++++++-------- tests/dummy_domain/__init__.py | 16 ++++++++-------- tests/test_domain.py | 4 +++- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d7eb41..69b6a5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.6.22 - IMPORTANT : Fix bug introduced with 0.6.20 (fix arguments handling) +- BREAKING : A domain should now include it's meta datas in a "domain" dictionary located in the __init__.py file of the domain's root. Consider looking in 'tests/dummy_domain/__init__.py' - Add *html* return type as default argument ret_type - Add *txt* return type - Log unhandled exceptions diff --git a/halfapi/half_domain.py b/halfapi/half_domain.py index 85309be..688470a 100644 --- a/halfapi/half_domain.py +++ b/halfapi/half_domain.py @@ -38,16 +38,15 @@ class HalfDomain(Starlette): self.app = app self.m_domain = importlib.import_module(domain) if module is None else module - self.name = getattr(self.m_domain, '__name__', domain) - self.id = getattr(self.m_domain, '__id__') - self.version = getattr(self.m_domain, '__version__', '0.0.0') - # TODO: Check if given domain halfapi_version matches with __version__ - self.halfapi_version = getattr(self.m_domain, '__halfapi_version__', __version__) - - self.deps = getattr(self.m_domain, '__deps__', tuple()) + d_domain = getattr(self.m_domain, 'domain', domain) + self.name = d_domain['name'] + self.id = d_domain['id'] + self.version = d_domain['version'] + self.halfapi_version = d_domain.get('halfapi_version', __version__) + self.deps = d_domain.get('deps', tuple()) if not router: - self.router = getattr(domain, '__router__', '.routers') + self.router = d_domain.get('routers', '.routers') else: self.router = router diff --git a/tests/dummy_domain/__init__.py b/tests/dummy_domain/__init__.py index cfb9459..1a60aa6 100644 --- a/tests/dummy_domain/__init__.py +++ b/tests/dummy_domain/__init__.py @@ -1,12 +1,12 @@ from halfapi import __version__ as halfapi_version -__name__ = 'dummy_domain' -__version__ = '0.0.0' -__patch_release__ = '0.0.0' -__routers__ = '.routers' -__id__ = '8b88e60a625369235b36c2d6d70756a0c02c1c7fb169fcee6dc820bcf9723f5a' +domain = { + 'name': 'dummy_domain', + 'version': '0.0.0', + 'id': '8b88e60a625369235b36c2d6d70756a0c02c1c7fb169fcee6dc820bcf9723f5a', + 'deps': ( + ('halfapi', '=={}'.format(halfapi_version)), + ) +} -__deps__ = ( - ('halfapi', '=={}'.format(halfapi_version)), -) diff --git a/tests/test_domain.py b/tests/test_domain.py index 68b627b..afd2baa 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -3,7 +3,9 @@ from halfapi.testing.test_domain import TestDomain from pprint import pprint class TestDummyDomain(TestDomain): - from .dummy_domain import __name__, __routers__ + from .dummy_domain import domain + __name__ = domain.get('name') + __routers__ = domain.get('routers') DOMAIN = __name__ CONFIG = {'test': True}