[breaking] domain description is defined in a dict, not in "__name__", "__id__", "__routers__" ...

This commit is contained in:
Maxime Alves LIRMM 2022-10-13 12:13:37 +02:00
parent fd682ba0e0
commit 7723acb812
4 changed files with 19 additions and 17 deletions

View File

@ -3,6 +3,7 @@
## 0.6.22 ## 0.6.22
- IMPORTANT : Fix bug introduced with 0.6.20 (fix arguments handling) - 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 *html* return type as default argument ret_type
- Add *txt* return type - Add *txt* return type
- Log unhandled exceptions - Log unhandled exceptions

View File

@ -38,16 +38,15 @@ class HalfDomain(Starlette):
self.app = app self.app = app
self.m_domain = importlib.import_module(domain) if module is None else module self.m_domain = importlib.import_module(domain) if module is None else module
self.name = getattr(self.m_domain, '__name__', domain) d_domain = getattr(self.m_domain, 'domain', domain)
self.id = getattr(self.m_domain, '__id__') self.name = d_domain['name']
self.version = getattr(self.m_domain, '__version__', '0.0.0') self.id = d_domain['id']
# TODO: Check if given domain halfapi_version matches with __version__ self.version = d_domain['version']
self.halfapi_version = getattr(self.m_domain, '__halfapi_version__', __version__) self.halfapi_version = d_domain.get('halfapi_version', __version__)
self.deps = d_domain.get('deps', tuple())
self.deps = getattr(self.m_domain, '__deps__', tuple())
if not router: if not router:
self.router = getattr(domain, '__router__', '.routers') self.router = d_domain.get('routers', '.routers')
else: else:
self.router = router self.router = router

View File

@ -1,12 +1,12 @@
from halfapi import __version__ as halfapi_version from halfapi import __version__ as halfapi_version
__name__ = 'dummy_domain' domain = {
__version__ = '0.0.0' 'name': 'dummy_domain',
__patch_release__ = '0.0.0' 'version': '0.0.0',
__routers__ = '.routers' 'id': '8b88e60a625369235b36c2d6d70756a0c02c1c7fb169fcee6dc820bcf9723f5a',
__id__ = '8b88e60a625369235b36c2d6d70756a0c02c1c7fb169fcee6dc820bcf9723f5a' 'deps': (
__deps__ = (
('halfapi', '=={}'.format(halfapi_version)), ('halfapi', '=={}'.format(halfapi_version)),
) )
}

View File

@ -3,7 +3,9 @@ from halfapi.testing.test_domain import TestDomain
from pprint import pprint from pprint import pprint
class TestDummyDomain(TestDomain): class TestDummyDomain(TestDomain):
from .dummy_domain import __name__, __routers__ from .dummy_domain import domain
__name__ = domain.get('name')
__routers__ = domain.get('routers')
DOMAIN = __name__ DOMAIN = __name__
CONFIG = {'test': True} CONFIG = {'test': True}