6
6
"""
7
7
import ctypes
8
8
import os
9
+ import subprocess as sp
9
10
import sys
10
11
from ctypes .util import find_library
11
- import subprocess as sp
12
12
13
13
from pygmt .exceptions import GMTCLibError , GMTCLibNotFoundError , GMTOSError
14
14
@@ -33,9 +33,10 @@ def load_libgmt():
33
33
couldn't access the functions).
34
34
35
35
"""
36
- lib_fullnames = clib_full_names ()
36
+ lib_fullnames = []
37
37
error = True
38
- for libname in lib_fullnames :
38
+ for libname in clib_full_names ():
39
+ lib_fullnames .append (libname )
39
40
try :
40
41
libgmt = ctypes .CDLL (libname )
41
42
check_libgmt (libgmt )
@@ -100,22 +101,20 @@ def clib_full_names(env=None):
100
101
env = os .environ
101
102
102
103
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
103
105
104
106
# list of libraries paths to search, sort by priority from high to low
105
- lib_fullnames = []
106
-
107
107
# Search for libraries in GMT_LIBRARY_PATH if defined.
108
- libpath = env .get ("GMT_LIBRARY_PATH" , "" ) # e.g. $HOME/miniconda/envs/pygmt/lib
109
108
if libpath :
110
109
for libname in libnames :
111
- lib_fullnames . append ( os .path .join (libpath , libname ) )
110
+ yield os .path .join (libpath , libname )
112
111
113
112
# Search for the library returned by command "gmt --show-library"
114
113
try :
115
114
lib_fullpath = sp .check_output (
116
115
["gmt" , "--show-library" ], encoding = "utf-8"
117
116
).rstrip ("\n " )
118
- lib_fullnames . append ( lib_fullpath )
117
+ yield lib_fullpath
119
118
except FileNotFoundError : # command not found
120
119
pass
121
120
@@ -124,12 +123,11 @@ def clib_full_names(env=None):
124
123
for libname in libnames :
125
124
libfullpath = find_library (libname )
126
125
if libfullpath :
127
- lib_fullnames . append ( libfullpath )
126
+ yield libfullpath
128
127
129
128
# 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
133
131
134
132
135
133
def check_libgmt (libgmt ):
0 commit comments