From 0bec51ff0c35ff60071c2cabc84c40f6edc3ed12 Mon Sep 17 00:00:00 2001 From: Ian Gillingham Date: Wed, 21 May 2025 11:25:32 +0100 Subject: [PATCH 1/5] channel_access_exceptions.py: Ruff formatted, but still need to address exception class name suffix --- src/genie_python/channel_access_exceptions.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/genie_python/channel_access_exceptions.py b/src/genie_python/channel_access_exceptions.py index ee587a2b..ba2f0909 100644 --- a/src/genie_python/channel_access_exceptions.py +++ b/src/genie_python/channel_access_exceptions.py @@ -1,5 +1,6 @@ """ -Useful and slightly more explit exceptions that can be thrown. In general catch the super class of these. +Useful and slightly more explicit exceptions that can be thrown. +In general catch the super class of these. """ @@ -8,9 +9,9 @@ class UnableToConnectToPVException(IOError): The system is unable to connect to a PV for some reason. """ - def __init__(self, pv_name, err): + def __init__(self, pv_name: str, err: str) -> None: super(UnableToConnectToPVException, self).__init__( - "Unable to connect to PV {0}: {1}".format(pv_name, err) + f"Unable to connect to PV {pv_name}: {err}" ) @@ -19,11 +20,9 @@ class InvalidEnumStringException(KeyError): The enum string that is trying to be set is not listed in the pv. """ - def __init__(self, pv_name, valid_states): + def __init__(self, pv_name: str, valid_states: str) -> None: super(InvalidEnumStringException, self).__init__( - "Invalid string value entered for {}. Valid strings are {}".format( - pv_name, valid_states - ) + f"Invalid string value entered for {pv_name}. Valid strings are {valid_states}" ) @@ -32,8 +31,8 @@ class ReadAccessException(IOError): PV exists but its value is unavailable to read. """ - def __init__(self, pv_name): - super(ReadAccessException, self).__init__("Read access denied for PV {}".format(pv_name)) + def __init__(self, pv_name: str) -> None: + super(ReadAccessException, self).__init__(f"Read access denied for PV {pv_name}") class WriteAccessException(IOError): @@ -41,5 +40,5 @@ class WriteAccessException(IOError): PV was written to but does not allow writes. """ - def __init__(self, pv_name): - super(WriteAccessException, self).__init__("Write access denied for PV {}".format(pv_name)) + def __init__(self, pv_name: str) -> None: + super(WriteAccessException, self).__init__(f"Write access denied for PV {pv_name}") From 4f3a3ad42cd9f52bbaeba97d6b9555b594b792d5 Mon Sep 17 00:00:00 2001 From: Ian Gillingham Date: Wed, 21 May 2025 14:26:32 +0100 Subject: [PATCH 2/5] genie_alerts.py: Ruff and pyright formatted --- src/genie_python/genie_alerts.py | 41 +++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/genie_python/genie_alerts.py b/src/genie_python/genie_alerts.py index 2a9c6a28..a0175058 100644 --- a/src/genie_python/genie_alerts.py +++ b/src/genie_python/genie_alerts.py @@ -4,8 +4,6 @@ This module is used for setting alerts on blocks. """ -from __future__ import absolute_import, print_function - from genie_python.genie_api_setup import ( __api, helparglist, @@ -25,9 +23,10 @@ @usercommand -@helparglist("block, lowlimit, highlimit, [delay_in, delay_out]") +@helparglist("block, lowlimit, highlimit, [set_enable, delay_in, delay_out]") @log_command_and_handle_exception -def set_range(block, lowlimit, highlimit, set_enable=True, delay_in=None, delay_out=None): +def set_range(block: str, lowlimit: float, highlimit: float, set_enable: bool=True, + delay_in: float|None=None, delay_out: float|None=None) -> None: """ Sets alert range on block. @@ -36,19 +35,22 @@ def set_range(block, lowlimit, highlimit, set_enable=True, delay_in=None, delay_ lowlimit (float): low limit highlimit (float): high limit set_enable (bool): (optional setting True will enable alerts on the block. Defaults to True. - delay_in (float): (optional) delay /s before triggering in range. If not specified the delay remains unchanged. - delay_out (float): (optional) delay /s before triggering out of range. If not specified the delay remains unchanged. + delay_in (float): (optional) delay /s before triggering in range. If not specified the delay + remains unchanged. + delay_out (float): (optional) delay /s before triggering out of range. + If not specified the delay remains unchanged. """ if not __api.block_exists(block): raise Exception('No block with the name "{}" exists'.format(block)) - __api.set_pv_value(_ALERT_LOW.format(block), lowlimit, wait=False, is_local=True) - __api.set_pv_value(_ALERT_HIGH.format(block), highlimit, wait=False, is_local=True) + __api.set_pv_value(_ALERT_LOW.format(block), f"{lowlimit}", wait=False, is_local=True) + __api.set_pv_value(_ALERT_HIGH.format(block), f"{highlimit}", wait=False, is_local=True) if delay_in is not None: - __api.set_pv_value(_ALERT_DELAY_IN.format(block), delay_in, wait=False, is_local=True) + __api.set_pv_value(_ALERT_DELAY_IN.format(block), f"{delay_in}", wait=False, is_local=True) if delay_out is not None: - __api.set_pv_value(_ALERT_DELAY_OUT.format(block), delay_out, wait=False, is_local=True) + __api.set_pv_value(_ALERT_DELAY_OUT.format(block), f"{delay_out}", + wait=False, is_local=True) if set_enable: enable(block) @@ -56,7 +58,7 @@ def set_range(block, lowlimit, highlimit, set_enable=True, delay_in=None, delay_ @usercommand @helparglist("block [, is_enabled]") @log_command_and_handle_exception -def enable(block, set_enabled=True): +def enable(block: str, set_enabled: bool=True) -> None: """ Enable alerts on a block. @@ -73,7 +75,7 @@ def enable(block, set_enabled=True): @usercommand @helparglist("message") @log_command_and_handle_exception -def send(message): +def send(message: str) -> None: """ Send a message to all alert recipients. @@ -87,7 +89,7 @@ def send(message): ## no log decorator so mobile numbers not sent to log file @usercommand @helparglist("numbers") -def set_sms(numbers): +def set_sms(numbers:list[str] | str) -> None: """ Set SMS text numbers for alerts on blocks. @@ -107,7 +109,7 @@ def set_sms(numbers): ## no log decorator so email addresses not sent to log file @usercommand @helparglist("emails") -def set_email(emails): +def set_email(emails: list[str]|str) -> None: """ Set email addresses for alerts on blocks. @@ -124,7 +126,7 @@ def set_email(emails): print("Unable to set alert email addresses: {}".format(e)) -def _print_block(block, only_if_enabled=False): +def _print_block(block: str, only_if_enabled: bool=False) -> None: enabled = ( __api.get_pv_value(_ALERT_ENABLE.format(block), to_string=True, is_local=True) == "YES" ) @@ -157,7 +159,7 @@ def _print_block(block, only_if_enabled=False): @usercommand @helparglist("[block, all]") @log_command_and_handle_exception -def status(block=None, all=False): +def status(block: str|None=None, all:bool=False) -> None: """ Prints the emails and mobiles used for alerts and the current status of specified block. Args: @@ -177,12 +179,13 @@ def status(block=None, all=False): # used as part of tests, returns a dictionary of details -def _dump(block): +def _dump(block: str) -> dict[str,str]: if not __api.block_exists(block): raise Exception('No block with the name "{}" exists'.format(block)) res = {} - res["emails"] = __api.get_pv_value(_ALERT_EMAILS, to_string=True, is_local=True).split(";") - res["mobiles"] = __api.get_pv_value(_ALERT_MOBILES, to_string=True, is_local=True).split(";") + res["emails"] = str(__api.get_pv_value(_ALERT_EMAILS, to_string=True, is_local=True)).split(";") + res["mobiles"] = (str(__api.get_pv_value(_ALERT_MOBILES, to_string=True, is_local=True)) + .split(";")) res["enabled"] = __api.get_pv_value(_ALERT_ENABLE.format(block), to_string=False, is_local=True) res["lowlimit"] = __api.get_pv_value(_ALERT_LOW.format(block), to_string=False, is_local=True) res["highlimit"] = __api.get_pv_value(_ALERT_HIGH.format(block), to_string=False, is_local=True) From e9e85f6fac4570ea6435c25fb20a56dea01c3cdf Mon Sep 17 00:00:00 2001 From: Ian Gillingham Date: Wed, 21 May 2025 15:02:57 +0100 Subject: [PATCH 3/5] genie_alerts.py: Ruff reformat (yet another) --- src/genie_python/genie_alerts.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/genie_python/genie_alerts.py b/src/genie_python/genie_alerts.py index a0175058..a14f4bee 100644 --- a/src/genie_python/genie_alerts.py +++ b/src/genie_python/genie_alerts.py @@ -25,8 +25,14 @@ @usercommand @helparglist("block, lowlimit, highlimit, [set_enable, delay_in, delay_out]") @log_command_and_handle_exception -def set_range(block: str, lowlimit: float, highlimit: float, set_enable: bool=True, - delay_in: float|None=None, delay_out: float|None=None) -> None: +def set_range( + block: str, + lowlimit: float, + highlimit: float, + set_enable: bool = True, + delay_in: float | None = None, + delay_out: float | None = None, +) -> None: """ Sets alert range on block. @@ -49,8 +55,9 @@ def set_range(block: str, lowlimit: float, highlimit: float, set_enable: bool=Tr if delay_in is not None: __api.set_pv_value(_ALERT_DELAY_IN.format(block), f"{delay_in}", wait=False, is_local=True) if delay_out is not None: - __api.set_pv_value(_ALERT_DELAY_OUT.format(block), f"{delay_out}", - wait=False, is_local=True) + __api.set_pv_value( + _ALERT_DELAY_OUT.format(block), f"{delay_out}", wait=False, is_local=True + ) if set_enable: enable(block) @@ -58,7 +65,7 @@ def set_range(block: str, lowlimit: float, highlimit: float, set_enable: bool=Tr @usercommand @helparglist("block [, is_enabled]") @log_command_and_handle_exception -def enable(block: str, set_enabled: bool=True) -> None: +def enable(block: str, set_enabled: bool = True) -> None: """ Enable alerts on a block. @@ -89,7 +96,7 @@ def send(message: str) -> None: ## no log decorator so mobile numbers not sent to log file @usercommand @helparglist("numbers") -def set_sms(numbers:list[str] | str) -> None: +def set_sms(numbers: list[str] | str) -> None: """ Set SMS text numbers for alerts on blocks. @@ -109,7 +116,7 @@ def set_sms(numbers:list[str] | str) -> None: ## no log decorator so email addresses not sent to log file @usercommand @helparglist("emails") -def set_email(emails: list[str]|str) -> None: +def set_email(emails: list[str] | str) -> None: """ Set email addresses for alerts on blocks. @@ -126,7 +133,7 @@ def set_email(emails: list[str]|str) -> None: print("Unable to set alert email addresses: {}".format(e)) -def _print_block(block: str, only_if_enabled: bool=False) -> None: +def _print_block(block: str, only_if_enabled: bool = False) -> None: enabled = ( __api.get_pv_value(_ALERT_ENABLE.format(block), to_string=True, is_local=True) == "YES" ) @@ -159,7 +166,7 @@ def _print_block(block: str, only_if_enabled: bool=False) -> None: @usercommand @helparglist("[block, all]") @log_command_and_handle_exception -def status(block: str|None=None, all:bool=False) -> None: +def status(block: str | None = None, all: bool = False) -> None: """ Prints the emails and mobiles used for alerts and the current status of specified block. Args: @@ -179,13 +186,14 @@ def status(block: str|None=None, all:bool=False) -> None: # used as part of tests, returns a dictionary of details -def _dump(block: str) -> dict[str,str]: +def _dump(block: str) -> dict[str, str]: if not __api.block_exists(block): raise Exception('No block with the name "{}" exists'.format(block)) res = {} res["emails"] = str(__api.get_pv_value(_ALERT_EMAILS, to_string=True, is_local=True)).split(";") - res["mobiles"] = (str(__api.get_pv_value(_ALERT_MOBILES, to_string=True, is_local=True)) - .split(";")) + res["mobiles"] = str(__api.get_pv_value(_ALERT_MOBILES, to_string=True, is_local=True)).split( + ";" + ) res["enabled"] = __api.get_pv_value(_ALERT_ENABLE.format(block), to_string=False, is_local=True) res["lowlimit"] = __api.get_pv_value(_ALERT_LOW.format(block), to_string=False, is_local=True) res["highlimit"] = __api.get_pv_value(_ALERT_HIGH.format(block), to_string=False, is_local=True) From 09fb1b8c9a5510a11a43707809fcaf72ecbe7768 Mon Sep 17 00:00:00 2001 From: Ian Gillingham Date: Wed, 21 May 2025 15:08:30 +0100 Subject: [PATCH 4/5] channel_access_exceptions.py: Ruff and pyright --- src/genie_python/channel_access_exceptions.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/genie_python/channel_access_exceptions.py b/src/genie_python/channel_access_exceptions.py index ba2f0909..585942d0 100644 --- a/src/genie_python/channel_access_exceptions.py +++ b/src/genie_python/channel_access_exceptions.py @@ -4,7 +4,7 @@ """ -class UnableToConnectToPVException(IOError): +class UnableToConnectToPVException(IOError): # noqa N818 Historic name """ The system is unable to connect to a PV for some reason. """ @@ -15,7 +15,7 @@ def __init__(self, pv_name: str, err: str) -> None: ) -class InvalidEnumStringException(KeyError): +class InvalidEnumStringException(KeyError): # noqa N818 Historic name """ The enum string that is trying to be set is not listed in the pv. """ @@ -26,7 +26,7 @@ def __init__(self, pv_name: str, valid_states: str) -> None: ) -class ReadAccessException(IOError): +class ReadAccessException(IOError): # noqa N818 Historic name """ PV exists but its value is unavailable to read. """ @@ -35,7 +35,7 @@ def __init__(self, pv_name: str) -> None: super(ReadAccessException, self).__init__(f"Read access denied for PV {pv_name}") -class WriteAccessException(IOError): +class WriteAccessException(IOError): # noqa N818 Historic name """ PV was written to but does not allow writes. """ From ce227c4844036e487e4487eef2694a5cae7d4555 Mon Sep 17 00:00:00 2001 From: Ian Gillingham Date: Wed, 21 May 2025 15:32:47 +0100 Subject: [PATCH 5/5] genie_alerts.py: Ruff reformat (yet another 2) --- src/genie_python/genie_alerts.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/genie_python/genie_alerts.py b/src/genie_python/genie_alerts.py index a14f4bee..1d0b7cf2 100644 --- a/src/genie_python/genie_alerts.py +++ b/src/genie_python/genie_alerts.py @@ -50,14 +50,12 @@ def set_range( if not __api.block_exists(block): raise Exception('No block with the name "{}" exists'.format(block)) - __api.set_pv_value(_ALERT_LOW.format(block), f"{lowlimit}", wait=False, is_local=True) - __api.set_pv_value(_ALERT_HIGH.format(block), f"{highlimit}", wait=False, is_local=True) + __api.set_pv_value(_ALERT_LOW.format(block), lowlimit, wait=False, is_local=True) + __api.set_pv_value(_ALERT_HIGH.format(block), highlimit, wait=False, is_local=True) if delay_in is not None: - __api.set_pv_value(_ALERT_DELAY_IN.format(block), f"{delay_in}", wait=False, is_local=True) + __api.set_pv_value(_ALERT_DELAY_IN.format(block), delay_in, wait=False, is_local=True) if delay_out is not None: - __api.set_pv_value( - _ALERT_DELAY_OUT.format(block), f"{delay_out}", wait=False, is_local=True - ) + __api.set_pv_value(_ALERT_DELAY_OUT.format(block), delay_out, wait=False, is_local=True) if set_enable: enable(block)