[release] 0.5.0

This commit is contained in:
Maxime Alves LIRMM 2021-05-28 22:30:48 +02:00
parent 904783b134
commit e5a278c84c
7 changed files with 12 additions and 39 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
__version__ = '0.4.1'
__version__ = '0.5.0'
def version():
return f'HalfAPI version:{__version__}'

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)