Skip to content

Commit

Permalink
Reworked search for library path to make it deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Mar 5, 2019
1 parent d26f3d2 commit a42773e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pyvisa/ctwrapper/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a42773e

Please sign in to comment.