Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typing support #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python-lib/tc_etl_lib/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
12 changes: 6 additions & 6 deletions python-lib/tc_etl_lib/tc_etl_lib/cb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions python-lib/tc_etl_lib/tc_etl_lib/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file to support type hints in exported package
# See https://peps.python.org/pep-0561/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¿Para que sirve este fichero? Ahora mismo por lo que veo estaría vacio (ya que entiendo que las líneas que empiezan por # se interpretan como comentarios)

Copy link
Collaborator Author

@rg2011 rg2011 May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Es un requisito de la PEP para exportar la información de tipado de la biblioteca: https://peps.python.org/pep-0561/#packaging-type-information . Por lo que entiendo de la PEP, el fichero es solo un marcador pero debe existir y distribuirse junto con la librería, incluyéndolo en el setup.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, aclarado. NTC.

6 changes: 3 additions & 3 deletions python-lib/tc_etl_lib/tc_etl_lib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down