From a42773eaa525360d9dd5db534dc8879e4baae3a5 Mon Sep 17 00:00:00 2001 From: Hernan Date: Tue, 5 Mar 2019 20:59:40 -0300 Subject: [PATCH] Reworked search for library path to make it deterministic --- pyvisa/ctwrapper/highlevel.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pyvisa/ctwrapper/highlevel.py b/pyvisa/ctwrapper/highlevel.py index 8d51a714..6a1da958 100644 --- a/pyvisa/ctwrapper/highlevel.py +++ b/pyvisa/ctwrapper/highlevel.py @@ -43,6 +43,13 @@ def _args_to_str(args): return tuple(out) +def unique(seq): + """Keep unique while preserving order. + """ + seen = set() + return [x for x in seq if not (x in seen or seen.add(x))] + + @add_visa_methods class NIVisaLibrary(highlevel.VisaLibraryBase): """High level NI-VISA Library wrapper using ctypes. @@ -70,24 +77,22 @@ def get_library_paths(): from ..util import LibraryPath, read_user_library_path - user_lib = read_user_library_path() + # Try to find NI libraries using known names. tmp = [find_library(library_path) for library_path in ('visa', 'visa32', 'visa32.dll', 'visa64', 'visa64.dll')] - tmp = [LibraryPath(library_path) - for library_path in set(tmp) - if library_path is not None] - logger.debug('Automatically found library files: %s' % tmp) + # Prepend the path provided by the user in configuration files (if any). + user_lib = read_user_library_path() if user_lib: - user_lib = LibraryPath(user_lib, 'user') - try: - tmp.remove(user_lib) - except ValueError: - pass tmp.insert(0, user_lib) + # Deduplicate and convert string paths to LibraryPath objects + tmp = [LibraryPath(library_path) + for library_path in unique(tmp) + if library_path is not None] + return tuple(tmp) @staticmethod