From a1dc8961eacd9f7cc6bcb9fc8983611e51cb35df Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Wed, 12 Feb 2025 08:47:46 -0800 Subject: [PATCH 1/4] feat: Enable turning down the verbosity of failure messages during reboot of a VISA device. --- CHANGELOG.md | 4 ++++ .../driver_mixins/device_control/pi_control.py | 1 + src/tm_devices/helpers/functions.py | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a3c308e..91a8b82d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ Valid subsections within a version are: Things to be included in the next release go here. +### Added + +- Added a new parameter to the `create_visa_connection()` function which can be used to turn down the verbosity of the printouts to stdout during a reboot from `ERROR` to `DEBUG` to avoid cluttering the console with unnecessary failures while the device is still rebooting. + --- ## v3.1.1 (2025-02-04) diff --git a/src/tm_devices/driver_mixins/device_control/pi_control.py b/src/tm_devices/driver_mixins/device_control/pi_control.py index 54fa70f6..a54e5357 100644 --- a/src/tm_devices/driver_mixins/device_control/pi_control.py +++ b/src/tm_devices/driver_mixins/device_control/pi_control.py @@ -1028,6 +1028,7 @@ def _open(self) -> bool: self._visa_resource = create_visa_connection( self._config_entry, visa_library=self._visa_library_path, + verbose_connection_failure_logging=False, ) opened = True if iteration < 1 and not bool( diff --git a/src/tm_devices/helpers/functions.py b/src/tm_devices/helpers/functions.py index f40f9b0a..e53f62b1 100644 --- a/src/tm_devices/helpers/functions.py +++ b/src/tm_devices/helpers/functions.py @@ -303,6 +303,7 @@ def create_visa_connection( *, retry_connection: bool = False, second_connection_attempt_delay: int = 60, + verbose_connection_failure_logging: bool = True, ) -> MessageBasedResource: """Create a VISA resource. @@ -314,6 +315,8 @@ def create_visa_connection( between each attempt. second_connection_attempt_delay: The number of seconds to wait in between the first and second connection attempts when `retry_connection=True`. + verbose_connection_failure_logging: Indicates if the connections failures should be logged + with an ERROR level. If False, the failures will be logged with a DEBUG level. Returns: A VISA resource that can be passed into the device driver. @@ -321,6 +324,7 @@ def create_visa_connection( Raises: ConnectionError: The VISA connection couldn't be created to the device. """ + failure_logging_level = logging.ERROR if verbose_connection_failure_logging else logging.DEBUG # Set up the VISA resource that will be used for communicating with the VISA device resource_expression = device_config_entry.get_visa_resource_expression() try: @@ -351,8 +355,9 @@ def create_visa_connection( f" using the resource expression '{resource_expression}'" f" and the {repr(visa_library) if visa_library else 'default'} VISA library" ) - _logger.error(error_message) # noqa: TRY400 - _logger.error( # noqa: TRY400 + _logger.log(failure_logging_level, error_message) + _logger.log( + failure_logging_level, "1st exception: %s.%s: %s", error_1.__class__.__module__, error_1.__class__.__qualname__, @@ -379,14 +384,16 @@ def create_visa_connection( f" using the resource expression '{resource_expression}'" f" and the {repr(visa_library) if visa_library else 'default'} VISA library" ) - _logger.error(error_message) # noqa: TRY400 - _logger.error( # noqa: TRY400 + _logger.log(failure_logging_level, error_message) + _logger.log( + failure_logging_level, "1st exception: %s.%s: %s", error_1.__class__.__module__, error_1.__class__.__qualname__, error_1, ) - _logger.error( # noqa: TRY400 + _logger.log( + failure_logging_level, "2nd exception: %s.%s: %s:", error_2.__class__.__module__, error_2.__class__.__qualname__, From dd4eae074d1983eb69e98c2c2bbf018d8b0ba3ae Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Wed, 12 Feb 2025 09:46:31 -0800 Subject: [PATCH 2/4] fix: Remove cleanup from the `.open()` method of the `DeviceManager` since the creation of the device performs the cleanup as well --- src/tm_devices/device_manager.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tm_devices/device_manager.py b/src/tm_devices/device_manager.py index d0f43824..4fdec18b 100644 --- a/src/tm_devices/device_manager.py +++ b/src/tm_devices/device_manager.py @@ -1047,8 +1047,6 @@ def open(self) -> bool: _logger.info("Opening Connections to Devices") for device_name, device_config in self.__config.devices.items(): self.__create_device(device_name, device_config, 3) - if self.__setup_cleanup_enabled: - self.cleanup_all_devices() self.__is_open = True self._suppress_protection = False From 51f4bbfa3484ef391df1bcc864374e03cceb5bd0 Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Wed, 12 Feb 2025 10:09:36 -0800 Subject: [PATCH 3/4] chore(dev-deps): Update dependency specifiers for cryptography to resolve a security vulnerability --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index e51f3b69..ba2f1243 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,6 +99,10 @@ urllib3 = "^2.0" zeroconf = "^0.136.0" [tool.poetry.group.dev.dependencies] +cryptography = [ + {python = ">=3.10", version = "^44.0.1"}, + {python = "<3.10", version = "^43.0"} +] docutils = "^0.20" # TODO: Drop Python 3.8: remove this when the minimum Python version is >=3.9 nodeenv = "^1.9.1" pip = "^24.0" From 32159dfdbd36456420f67a8936f747ea8e4d23bd Mon Sep 17 00:00:00 2001 From: Nicholas Felt Date: Wed, 12 Feb 2025 11:07:08 -0800 Subject: [PATCH 4/4] chore(dev-deps): Update dependency specifiers for the main python version to resolve a security vulnerability in the cryptography development dependency --- pyproject.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ba2f1243..40bc6e3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ libusb-package = "^1.0.26.0,!=1.0.26.2" # 1.0.26.2 doesn't work with Python 3.1 packaging = "^24.0" psutil = "^6.0.0" pyserial = "^3.5" -python = "^3.8" # This is the main Python version requirement +python = "^3.8,!=3.9.0,!=3.9.1" # This is the main Python version requirement, the excluded versions of Python had major bugs and shouldn't be used python-dateutil = "^2.8.2" pyusb = "^1.2.1" pyvicp = "^1.1.0" @@ -99,10 +99,6 @@ urllib3 = "^2.0" zeroconf = "^0.136.0" [tool.poetry.group.dev.dependencies] -cryptography = [ - {python = ">=3.10", version = "^44.0.1"}, - {python = "<3.10", version = "^43.0"} -] docutils = "^0.20" # TODO: Drop Python 3.8: remove this when the minimum Python version is >=3.9 nodeenv = "^1.9.1" pip = "^24.0"