From e5a278c84cf05d9d5124bbea38bb5f50ed7a28f4 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Fri, 28 May 2021 22:30:48 +0200 Subject: [PATCH] [release] 0.5.0 --- halfapi/__init__.py | 2 +- halfapi/lib/domain.py | 23 ++--------------------- halfapi/lib/routes.py | 6 +++--- tests/conftest.py | 2 +- tests/test_lib_domain.py | 10 +--------- tests/test_lib_routes.py | 4 ++-- tests/test_lib_schemas.py | 4 ++-- 7 files changed, 12 insertions(+), 39 deletions(-) diff --git a/halfapi/__init__.py b/halfapi/__init__.py index 6ae62e1..7b49754 100644 --- a/halfapi/__init__.py +++ b/halfapi/__init__.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -__version__ = '0.4.1' +__version__ = '0.5.0' def version(): return f'HalfAPI version:{__version__}' diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index 610b3c3..34845d2 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -153,25 +153,6 @@ def gen_router_routes(m_router: ModuleType, path: List[str]) -> Generator: path.pop() - -def gen_domain_routes(domain: str, m_dom: ModuleType) -> Generator: - """ - Generator that calls gen_router_routes for a domain - - The domain must have a routers module in it's root-level. - If not, it is considered as empty - """ - m_router = None - try: - m_router = importlib.import_module('.routers', domain) - except ImportError: - logger.warning('Domain **%s** has no **routers** module', domain) - m_router = importlib.import_module('.routers', f'.{domain}') - - if m_router: - yield from gen_router_routes(m_router, [domain]) - - def d_domains(config) -> Dict[str, ModuleType]: """ Parameters: @@ -188,8 +169,8 @@ def d_domains(config) -> Dict[str, ModuleType]: try: sys.path.append('.') return { - domain: importlib.import_module(domain) - for domain, _ in config.items('domains') + domain: importlib.import_module(''.join((domain, module))) + for domain, module in config.items('domains') } except ImportError as exc: logger.error('Could not load a domain : %s', exc) diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index f77919b..cdc8cf6 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -24,7 +24,7 @@ from starlette.routing import Route from starlette.requests import Request from starlette.responses import Response, PlainTextResponse -from halfapi.lib.domain import gen_domain_routes, VERBS +from halfapi.lib.domain import gen_router_routes, VERBS logger = logging.getLogger('uvicorn.asgi') @@ -104,7 +104,7 @@ def gen_starlette_routes(d_domains: Dict[str, ModuleType]) -> Generator: """ for domain_name, m_domain in d_domains.items(): - for path, d_route in gen_domain_routes(domain_name, m_domain): + for path, d_route in gen_router_routes(m_domain, [domain_name]): for verb in VERBS: if verb not in d_route.keys(): continue @@ -148,7 +148,7 @@ def api_routes(m_dom: ModuleType) -> Generator: return l_params d_res = {} - for path, d_route in gen_domain_routes(m_dom.__name__, m_dom): + for path, d_route in gen_router_routes(m_dom, [m_dom.__name__]): d_res[path] = {'fqtn': d_route['fqtn'] } for verb in VERBS: diff --git a/tests/conftest.py b/tests/conftest.py index 4b8b8d2..0429703 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -197,7 +197,7 @@ def project_runner(runner, halfapicli, halfapi_conf_dir): ### # add dummy domain ### - create_domain('dummy_domain', '.dummy_domain') + create_domain('tests', '.dummy_domain.routers') ### yield halfapicli diff --git a/tests/test_lib_domain.py b/tests/test_lib_domain.py index 045b2f6..2327deb 100644 --- a/tests/test_lib_domain.py +++ b/tests/test_lib_domain.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 import importlib -from halfapi.lib.domain import VERBS, gen_domain_routes, gen_router_routes +from halfapi.lib.domain import VERBS, gen_router_routes def test_gen_router_routes(): @@ -16,11 +16,3 @@ def test_gen_router_routes(): assert hasattr(route['fct'], '__call__') if 'fqtn' in route: assert isinstance(route['fqtn'], str) - - -def test_gen_domain_routes(): - from . import dummy_domain - for path, route in gen_domain_routes( - 'dummy_domain', dummy_domain): - assert isinstance(path, str) - assert isinstance(route, dict) diff --git a/tests/test_lib_routes.py b/tests/test_lib_routes.py index 0b4f373..9c1b1ff 100644 --- a/tests/test_lib_routes.py +++ b/tests/test_lib_routes.py @@ -2,8 +2,8 @@ from starlette.routing import Route from halfapi.lib.routes import gen_starlette_routes def test_gen_starlette_routes(): - from . import dummy_domain + from .dummy_domain import routers for route in gen_starlette_routes({ - 'dummy_domain': dummy_domain }): + 'dummy_domain': routers }): assert isinstance(route, Route) diff --git a/tests/test_lib_schemas.py b/tests/test_lib_schemas.py index 638fb7c..b3f9d8a 100644 --- a/tests/test_lib_schemas.py +++ b/tests/test_lib_schemas.py @@ -9,9 +9,9 @@ from halfapi.app import application from halfapi.lib.schemas import schema_dict_dom def test_schemas_dict_dom(): - from . import dummy_domain + from .dummy_domain import routers schema = schema_dict_dom({ - 'dummy_domain':dummy_domain}) + 'dummy_domain':routers}) assert isinstance(schema, dict)