66"""
77import ctypes
88import os
9+ import subprocess as sp
910import sys
1011from ctypes .util import find_library
11- import subprocess as sp
1212
1313from pygmt .exceptions import GMTCLibError , GMTCLibNotFoundError , GMTOSError
1414
@@ -33,9 +33,10 @@ def load_libgmt():
3333 couldn't access the functions).
3434
3535 """
36- lib_fullnames = clib_full_names ()
36+ lib_fullnames = []
3737 error = True
38- for libname in lib_fullnames :
38+ for libname in clib_full_names ():
39+ lib_fullnames .append (libname )
3940 try :
4041 libgmt = ctypes .CDLL (libname )
4142 check_libgmt (libgmt )
@@ -100,22 +101,20 @@ def clib_full_names(env=None):
100101 env = os .environ
101102
102103 libnames = clib_names (os_name = sys .platform ) # e.g. libgmt.so, libgmt.dylib, gmt.dll
104+ libpath = env .get ("GMT_LIBRARY_PATH" , "" ) # e.g. $HOME/miniconda/envs/pygmt/lib
103105
104106 # list of libraries paths to search, sort by priority from high to low
105- lib_fullnames = []
106-
107107 # Search for libraries in GMT_LIBRARY_PATH if defined.
108- libpath = env .get ("GMT_LIBRARY_PATH" , "" ) # e.g. $HOME/miniconda/envs/pygmt/lib
109108 if libpath :
110109 for libname in libnames :
111- lib_fullnames . append ( os .path .join (libpath , libname ) )
110+ yield os .path .join (libpath , libname )
112111
113112 # Search for the library returned by command "gmt --show-library"
114113 try :
115114 lib_fullpath = sp .check_output (
116115 ["gmt" , "--show-library" ], encoding = "utf-8"
117116 ).rstrip ("\n " )
118- lib_fullnames . append ( lib_fullpath )
117+ yield lib_fullpath
119118 except FileNotFoundError : # command not found
120119 pass
121120
@@ -124,12 +123,11 @@ def clib_full_names(env=None):
124123 for libname in libnames :
125124 libfullpath = find_library (libname )
126125 if libfullpath :
127- lib_fullnames . append ( libfullpath )
126+ yield libfullpath
128127
129128 # Search for library names in the system default path [the lowest priority]
130- lib_fullnames .extend (libnames )
131-
132- return lib_fullnames
129+ for libname in libnames :
130+ yield libname
133131
134132
135133def check_libgmt (libgmt ):
0 commit comments