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