From 8f79e2a52cb640acf125141274a6d7b671125dea Mon Sep 17 00:00:00 2001 From: private Date: Mon, 22 May 2023 13:11:31 +0000 Subject: [PATCH] fix typing support --- python-lib/tc_etl_lib/setup.py | 4 ++++ python-lib/tc_etl_lib/tc_etl_lib/cb.py | 12 ++++++------ python-lib/tc_etl_lib/tc_etl_lib/py.typed | 2 ++ python-lib/tc_etl_lib/tc_etl_lib/store.py | 6 +++--- 4 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 python-lib/tc_etl_lib/tc_etl_lib/py.typed diff --git a/python-lib/tc_etl_lib/setup.py b/python-lib/tc_etl_lib/setup.py index 68d0202..8d518ad 100644 --- a/python-lib/tc_etl_lib/setup.py +++ b/python-lib/tc_etl_lib/setup.py @@ -53,5 +53,9 @@ install_requires=INSTALL_REQUIRES, license=LICENSE, packages=find_packages(), + # See https://peps.python.org/pep-0561/ + package_data={ + 'tc_etl_lib': ['py.typed'] + }, include_package_data=True ) diff --git a/python-lib/tc_etl_lib/tc_etl_lib/cb.py b/python-lib/tc_etl_lib/tc_etl_lib/cb.py index 39f9946..450165d 100644 --- a/python-lib/tc_etl_lib/tc_etl_lib/cb.py +++ b/python-lib/tc_etl_lib/tc_etl_lib/cb.py @@ -27,7 +27,7 @@ ''' import requests from requests.adapters import HTTPAdapter -from requests.packages.urllib3.util.retry import Retry +from urllib3.util.retry import Retry from typing import Iterable, List, Any, Optional import logging @@ -118,7 +118,7 @@ def __init__(self,*, endpoint: Optional[str] = None, timeout: int = 10, post_ret self.block_size = block_size - def delete_entities(self, *, service: str = None, subservice: str = None, auth: authManager = None, limit: int = 100, type: str = None, q: str = None, mq: str = None, georel: str = None, geometry: str = None, coords: str = None, id: str = None, options_get: list = [], options_send: list = []): + def delete_entities(self, *, service: Optional[str] = None, subservice: Optional[str] = None, auth: Optional[authManager] = None, limit: int = 100, type: Optional[str] = None, q: Optional[str] = None, mq: Optional[str] = None, georel: Optional[str] = None, geometry: Optional[str] = None, coords: Optional[str] = None, id: Optional[str] = None, options_get: list = [], options_send: list = []): """Delete data from context broker :param service: Define service from which entities are deleted, defaults to None @@ -149,7 +149,7 @@ def delete_entities(self, *, service: str = None, subservice: str = None, auth: self.send_batch(service=service, subservice=subservice, auth=auth, entities=entities, actionType='delete', options=options_send) - def get_entities(self, *, service: str = None, subservice: str = None, auth: authManager = None, limit: int = 100, type: str = None, orderBy: str = None, q: str = None, mq: str = None, georel: str = None, geometry: str = None, coords: str = None, id: str = None, options: list = []): + def get_entities(self, *, service: Optional[str] = None, subservice: Optional[str] = None, auth: Optional[authManager] = None, limit: int = 100, type: Optional[str] = None, orderBy: Optional[str] = None, q: Optional[str] = None, mq: Optional[str] = None, georel: Optional[str] = None, geometry: Optional[str] = None, coords: Optional[str] = None, id: Optional[str] = None, options: list = []): """Retrieve data from context broker :param service: Define service from which entities are retrieved, defaults to None @@ -265,7 +265,7 @@ def get_entities_page(self, *, service: Optional[str] = None, subservice: Option return resp.json() - def send_batch(self, *, service:str = None, subservice: str = None, auth: authManager = None, entities: Iterable[Any], actionType: str = 'append', options: list = []) -> bool: + def send_batch(self, *, service: Optional[str] = None, subservice: Optional[str] = None, auth: Optional[authManager] = None, entities: Iterable[Any], actionType: str = 'append', options: list = []) -> bool: """Send batch data to context broker with block control :param auth: Define authManager @@ -303,7 +303,7 @@ def send_batch(self, *, service:str = None, subservice: str = None, auth: authMa return True - def __send_batch(self, *, service:str = None, subservice: str = None, auth: authManager = None, entities: List[Any], actionType: str = 'append', options: list = []) -> bool: + def __send_batch(self, *, service: Optional[str] = None, subservice: Optional[str] = None, auth: Optional[authManager] = None, entities: List[Any], actionType: str = 'append', options: list = []) -> bool: """Send batch data to context broker :param auth: Define authManager @@ -348,7 +348,7 @@ def __send_batch(self, *, service:str = None, subservice: str = None, auth: auth return True - def __batch_creation(self, *, service: str = None, subservice: str = None, auth: authManager = None, entities: List[Any], actionType: str = 'append', options: list = []): + def __batch_creation(self, *, service: Optional[str] = None, subservice: Optional[str] = None, auth: Optional[authManager] = None, entities: List[Any], actionType: str = 'append', options: list = []): """Send batch data to Context Broker :param entities: Entities data diff --git a/python-lib/tc_etl_lib/tc_etl_lib/py.typed b/python-lib/tc_etl_lib/tc_etl_lib/py.typed new file mode 100644 index 0000000..085e896 --- /dev/null +++ b/python-lib/tc_etl_lib/tc_etl_lib/py.typed @@ -0,0 +1,2 @@ +# Marker file to support type hints in exported package +# See https://peps.python.org/pep-0561/ \ No newline at end of file diff --git a/python-lib/tc_etl_lib/tc_etl_lib/store.py b/python-lib/tc_etl_lib/tc_etl_lib/store.py index 7e2b825..c116b2e 100644 --- a/python-lib/tc_etl_lib/tc_etl_lib/store.py +++ b/python-lib/tc_etl_lib/tc_etl_lib/store.py @@ -38,7 +38,7 @@ Store = Callable[[Iterable[Any]], None] @contextmanager -def orionStore(cb: cbManager, auth: authManager, *, service:str=None, subservice:str=None, actionType:str='append', options:list=[]): +def orionStore(cb: cbManager, auth: authManager, *, service: Optional[str]=None, subservice: Optional[str]=None, actionType:str='append', options:list=[]): ''' Context manager that creates a store to save entities to the given cbManager All parameters are the same as for the cbManager.send_batch function @@ -70,12 +70,12 @@ def sqlFileStore(path: Path, *, subservice:str, schema:str=":target_schema", nam mode = "a+" if append else "w+" handler = path.open(mode=mode, encoding="utf-8") some_table_names = table_names or {} # make sure it is not None - replace_id = replace_id or {} # make sure it is not None + some_replace_id = replace_id or {} # make sure it is not None try: def send_batch(entities: Iterable[Any]): """Send a batch of entities to the database""" for chunk in iter_chunk(entities, chunk_size): - handler.write(sqlfile_batch(schema=schema, namespace=namespace, table_names=some_table_names, subservice=subservice, replace_id=replace_id, entities=chunk)) + handler.write(sqlfile_batch(schema=schema, namespace=namespace, table_names=some_table_names, subservice=subservice, replace_id=some_replace_id, entities=chunk)) handler.write("\n") yield send_batch finally: