From cc0a603a662774da0b3b863179c5edfa7c11c8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Thu, 21 Aug 2025 19:49:57 +0200 Subject: [PATCH 1/3] refact: replace logger.warn -> logger.warning --- tagreader/clients.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tagreader/clients.py b/tagreader/clients.py index 8c6fceb..4825e43 100644 --- a/tagreader/clients.py +++ b/tagreader/clients.py @@ -412,7 +412,7 @@ def read_tags( ): start = start_time end = stop_time - logger.warn( + logger.warning( ( "This function has been renamed to read() and is deprecated. " "Please call 'read()' instead" From 59f50976902bcfcd8e3e5eb7364a30403e8aef9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Fri, 22 Aug 2025 09:42:54 +0200 Subject: [PATCH 2/3] refact: rename verifySSL -> verify_ssl, doc: fix type hinting test: fix tag --- tagreader/clients.py | 20 ++++++++++---------- tagreader/web_handlers.py | 12 ++++++------ tests/test_AspenHandlerREST_connect.py | 16 ++++++++-------- tests/test_PIHandlerREST_connect.py | 10 +++++----- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tagreader/clients.py b/tagreader/clients.py index 4825e43..0b16d81 100644 --- a/tagreader/clients.py +++ b/tagreader/clients.py @@ -32,7 +32,7 @@ def list_sources( imstype: Union[IMSType, str], url: Optional[str] = None, auth: Optional[Any] = None, - verifySSL: bool = True, + verify_ssl: Optional[Union[bool, str]] = True, ) -> List[str]: if isinstance(imstype, str): try: @@ -47,11 +47,11 @@ def list_sources( if imstype == IMSType.PIWEBAPI: if auth is None: auth = get_auth_pi() - return list_piwebapi_sources(url=url, auth=auth, verify_ssl=verifySSL) + return list_piwebapi_sources(url=url, auth=auth, verify_ssl=verify_ssl) elif imstype == IMSType.ASPENONE: if auth is None: auth = get_auth_aspen() - return list_aspenone_sources(url=url, auth=auth, verify_ssl=verifySSL) + return list_aspenone_sources(url=url, auth=auth, verify_ssl=verify_ssl) elif imstype in [IMSType.PI, IMSType.ASPEN, IMSType.IP21]: raise ValueError( f"ODBC clients are no longer supported. Given ims client type: {imstype}." @@ -120,14 +120,14 @@ def get_handler( datasource: str, url: Optional[str], options: Dict[str, Union[int, float, str]], - verifySSL: Optional[bool], + verify_ssl: Optional[Union[bool, str]], auth: Optional[Any], cache: Optional[Union[SmartCache, BucketCache]] = None, ): if imstype is None: try: if datasource in list_aspenone_sources( - url=None, auth=None, verify_ssl=verifySSL + url=None, auth=None, verify_ssl=verify_ssl ): imstype = IMSType.ASPENONE except HTTPError as e: @@ -135,7 +135,7 @@ def get_handler( if imstype is None: try: if datasource in list_piwebapi_sources( - url=None, auth=None, verify_ssl=verifySSL + url=None, auth=None, verify_ssl=verify_ssl ): imstype = IMSType.PIWEBAPI except HTTPError as e: @@ -146,7 +146,7 @@ def get_handler( url=url, datasource=datasource, options=options, - verify_ssl=verifySSL, + verify_ssl=verify_ssl, auth=auth, cache=cache, ) @@ -156,7 +156,7 @@ def get_handler( datasource=datasource, url=url, options=options, - verify_ssl=verifySSL, + verify_ssl=verify_ssl, auth=auth, ) elif imstype in [IMSType.PI, IMSType.ASPEN, IMSType.IP21]: @@ -178,7 +178,7 @@ def __init__( tz: Union[tzinfo, str] = pytz.timezone("Europe/Oslo"), url: Optional[str] = None, handler_options: Dict[str, Union[int, float, str]] = {}, # noqa: - verifySSL: bool = True, + verify_ssl: Optional[Union[bool, str]] = True, auth: Optional[Any] = None, cache: Optional[Union[SmartCache, BucketCache]] = None, ): @@ -209,7 +209,7 @@ def __init__( datasource=datasource, url=url, options=handler_options, - verifySSL=verifySSL, + verify_ssl=verify_ssl, auth=auth, cache=self.cache, ) diff --git a/tagreader/web_handlers.py b/tagreader/web_handlers.py index b8a3c61..4d72e43 100644 --- a/tagreader/web_handlers.py +++ b/tagreader/web_handlers.py @@ -95,7 +95,7 @@ def get_url_aspen(use_internal: bool = True) -> str: def list_aspenone_sources( url: Optional[str] = None, auth: Optional[Any] = None, - verify_ssl: Optional[bool] = True, + verify_ssl: Optional[Union[bool, str]] = True, ) -> List[str]: if url is None: url = get_url_aspen() @@ -124,7 +124,7 @@ def list_aspenone_sources( def list_piwebapi_sources( url: Optional[str] = None, auth: Optional[Any] = None, - verify_ssl: Optional[bool] = True, + verify_ssl: Optional[Union[bool, str]] = True, ) -> List[str]: if url is None: url = get_url_pi() @@ -152,7 +152,7 @@ def list_piwebapi_sources( def get_piwebapi_source_to_webid_dict( url: Optional[str] = None, auth: Optional[Any] = None, - verify_ssl: Optional[bool] = True, + verify_ssl: Optional[Union[bool, str]] = True, ) -> List[str]: if url is None: url = get_url_pi() @@ -182,7 +182,7 @@ def __init__( datasource: Optional[str], url: Optional[str], auth: Optional[Any], - verify_ssl: Optional[bool], + verify_ssl: Optional[Union[bool, str]], ): self.datasource = datasource self.base_url = url @@ -241,7 +241,7 @@ def __init__( datasource: Optional[str], url: Optional[str] = None, auth: Optional[Any] = None, - verify_ssl: Optional[bool] = True, + verify_ssl: Optional[Union[bool, str]] = True, options: Dict[str, Any] = dict(), ): if url is None: @@ -710,7 +710,7 @@ def __init__( url: Optional[str], datasource: Optional[str], auth: Optional[Any], - verify_ssl: bool, + verify_ssl: Optional[Union[bool, str]], options: Dict[str, Union[int, float, str]], cache: Optional[Union[SmartCache, BucketCache]], ): diff --git a/tests/test_AspenHandlerREST_connect.py b/tests/test_AspenHandlerREST_connect.py index cdbcc44..6c337be 100644 --- a/tests/test_AspenHandlerREST_connect.py +++ b/tests/test_AspenHandlerREST_connect.py @@ -25,7 +25,7 @@ VERIFY_SSL = False if is_AZURE_PIPELINE else get_verify_ssl() SOURCE = "TRB" -TAG = "xxx" +TAG = "AverageCPUTimeVals" FAKE_TAG = "so_random_it_cant_exist" START_TIME = datetime(2023, 5, 1, 10, 0, 0) STOP_TIME = datetime(2023, 5, 1, 11, 0, 0) @@ -37,7 +37,7 @@ def client() -> Generator[IMSClient, None, None]: c = IMSClient( datasource=SOURCE, imstype="aspenone", - verifySSL=bool(VERIFY_SSL), + verify_ssl=bool(VERIFY_SSL), ) c.cache = None c.connect() @@ -64,7 +64,7 @@ def test_list_all_aspen_one_sources() -> None: def test_list_sources_aspen_one() -> None: - res = list_sources(imstype=IMSType.ASPENONE, verifySSL=bool(VERIFY_SSL)) + res = list_sources(imstype=IMSType.ASPENONE, verify_ssl=bool(VERIFY_SSL)) assert isinstance(res, list) assert len(res) >= 1 assert isinstance(res[0], str) @@ -81,8 +81,8 @@ def test_search_tag(client: IMSClient) -> None: res = client.search(tag=FAKE_TAG, desc=None) assert 0 == len(res) - res = client.search(tag="AverageCPUTimeVals", desc=None) - assert res == [("AverageCPUTimeVals", "Average CPU Time")] + res = client.search(tag=TAG, desc=None) + assert res == [(TAG, "Average CPU Time")] res = client.search(tag="Aspen*", desc=None, return_desc=False) assert len(res) < 5 @@ -99,8 +99,8 @@ def test_search_tag(client: IMSClient) -> None: res = client.search("AspenCalcTrigger1", desc=None) assert res == [("AspenCalcTrigger1", "")] - res = client.search("AverageCPUTimeVals", "*CPU*") - assert res == [("AverageCPUTimeVals", "Average CPU Time")] + res = client.search(TAG, "*CPU*") + assert res == [(TAG, "Average CPU Time")] with pytest.raises(ValueError): _ = client.search(desc="Sine Input") # noqa @@ -146,7 +146,7 @@ def test_query_sql(client: IMSClient) -> None: assert isinstance(res, pd.DataFrame) assert res.empty - query = "Select name, ip_description from ip_analogdef where name = 'AverageCPUTimeVals'" + query = f"Select name, ip_description from ip_analogdef where name = '{TAG}'" res = client.query_sql(query=query, parse=True) assert isinstance(res, pd.DataFrame) assert len(res.index.values) == 1 diff --git a/tests/test_PIHandlerREST_connect.py b/tests/test_PIHandlerREST_connect.py index e96479a..0802f8a 100644 --- a/tests/test_PIHandlerREST_connect.py +++ b/tests/test_PIHandlerREST_connect.py @@ -17,7 +17,7 @@ "All tests in module require connection to PI server", allow_module_level=True ) -verifySSL = False if is_AZUREPIPELINE else get_verify_ssl() +verify_ssl = False if is_AZUREPIPELINE else get_verify_ssl() SOURCE = "PIMAM" TAGS = { @@ -36,7 +36,7 @@ def client() -> Generator[IMSClient, None, None]: c = IMSClient( datasource=SOURCE, imstype="piwebapi", - verifySSL=bool(verifySSL), + verify_ssl=bool(verify_ssl), ) c.cache = None c.connect() @@ -50,7 +50,7 @@ def client() -> Generator[IMSClient, None, None]: def pi_handler(cache: SmartCache) -> Generator[PIHandlerWeb, None, None]: h = PIHandlerWeb( datasource=SOURCE, - verify_ssl=bool(verifySSL), + verify_ssl=bool(verify_ssl), auth=None, options={}, url=None, @@ -63,7 +63,7 @@ def pi_handler(cache: SmartCache) -> Generator[PIHandlerWeb, None, None]: def test_list_all_piwebapi_sources() -> None: - res = list_piwebapi_sources(verify_ssl=bool(verifySSL), auth=None, url=None) + res = list_piwebapi_sources(verify_ssl=bool(verify_ssl), auth=None, url=None) assert isinstance(res, list) assert len(res) >= 1 for r in res: @@ -72,7 +72,7 @@ def test_list_all_piwebapi_sources() -> None: def test_list_sources_piwebapi() -> None: - res = list_sources(imstype="piwebapi", verifySSL=bool(verifySSL)) + res = list_sources(imstype="piwebapi", verify_ssl=bool(verify_ssl)) assert isinstance(res, list) assert len(res) >= 1 for r in res: From 18a3407b884eb018defe059f2c8b9386f61c5d7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85smund=20V=C3=A5ge=20Fannemel?= <34712686+asmfstatoil@users.noreply.github.com> Date: Fri, 22 Aug 2025 13:12:17 +0200 Subject: [PATCH 3/3] refact: explicitly list imports in init.py --- tagreader/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tagreader/__init__.py b/tagreader/__init__.py index f35b952..bc44219 100644 --- a/tagreader/__init__.py +++ b/tagreader/__init__.py @@ -4,11 +4,18 @@ ReaderType, add_equinor_root_certificate, is_equinor, - is_mac, - is_windows, ) if is_equinor(): add_equinor_root_certificate() from tagreader.__version__ import version as __version__ + +__all__ = [ + "IMSClient", + "list_sources", + "IMSType", + "ReaderType", + "add_equinor_root_certificate", + "__version__", +]