Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how PyGMT finds the GMT library #702

Merged
merged 23 commits into from
Feb 12, 2021
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2cc5a0d
Improve how PyGMT find the GMT library
seisman Oct 27, 2020
50dae17
Check library names for FreeBSD
seisman Nov 29, 2020
cbc4eb5
loading works even though the given library path is invalid
seisman Nov 29, 2020
c9e142e
Fix a lint issue
seisman Nov 29, 2020
b1c9a6a
Merge branch 'master' into gmt-library
seisman Nov 30, 2020
c43f9bb
Merge branch 'master' into gmt-library
seisman Dec 1, 2020
131676a
Merge branch 'master' into gmt-library
seisman Dec 16, 2020
5ad4f56
Merge branch 'master' into gmt-library
seisman Dec 23, 2020
7712bcc
Merge branch 'master' into gmt-library
seisman Dec 23, 2020
5e28f31
Merge branch 'master' into gmt-library
seisman Dec 29, 2020
671db53
Merge branch 'master' into gmt-library
seisman Dec 29, 2020
54f9664
Merge branch 'master' into gmt-library
seisman Jan 2, 2021
7108301
Merge branch 'master' into gmt-library
seisman Jan 8, 2021
5f17f1e
Use generator yield in clib_full_names function
weiji14 Jan 15, 2021
11c2c9b
Merge branch 'master' into gmt-library
weiji14 Jan 20, 2021
20728f9
Refactor test_load_libgmt_with_a_bad_library_path to use monkeypatch
weiji14 Jan 20, 2021
243ad13
Monkeypatch test to check that GMTCLibNotFoundError is raised properly
weiji14 Jan 20, 2021
ba5a715
Merge branch 'master' into gmt-library
seisman Feb 2, 2021
c27b565
Merge branch 'master' into gmt-library
seisman Feb 12, 2021
dbfd7e2
Check if the GMT shared library exists in GMT_LIBRARY_PATH
seisman Feb 12, 2021
6769dc3
Format codes
seisman Feb 12, 2021
c3887ce
Change Returns to Yields
seisman Feb 12, 2021
fbad831
Merge branch 'master' into gmt-library
weiji14 Feb 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use generator yield in clib_full_names function
  • Loading branch information
weiji14 committed Jan 15, 2021
commit 5f17f1e96ec9cc2d33dd41ad86beba77c7a2675f
22 changes: 10 additions & 12 deletions pygmt/clib/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"""
import ctypes
import os
import subprocess as sp
import sys
from ctypes.util import find_library
import subprocess as sp

from pygmt.exceptions import GMTCLibError, GMTCLibNotFoundError, GMTOSError

Expand All @@ -33,9 +33,10 @@ def load_libgmt():
couldn't access the functions).

"""
lib_fullnames = clib_full_names()
lib_fullnames = []
error = True
for libname in lib_fullnames:
for libname in clib_full_names():
lib_fullnames.append(libname)
try:
libgmt = ctypes.CDLL(libname)
check_libgmt(libgmt)
Expand Down Expand Up @@ -100,22 +101,20 @@ def clib_full_names(env=None):
env = os.environ

libnames = clib_names(os_name=sys.platform) # e.g. libgmt.so, libgmt.dylib, gmt.dll
libpath = env.get("GMT_LIBRARY_PATH", "") # e.g. $HOME/miniconda/envs/pygmt/lib

# list of libraries paths to search, sort by priority from high to low
lib_fullnames = []

# Search for libraries in GMT_LIBRARY_PATH if defined.
libpath = env.get("GMT_LIBRARY_PATH", "") # e.g. $HOME/miniconda/envs/pygmt/lib
if libpath:
for libname in libnames:
lib_fullnames.append(os.path.join(libpath, libname))
yield os.path.join(libpath, libname)

# Search for the library returned by command "gmt --show-library"
try:
lib_fullpath = sp.check_output(
["gmt", "--show-library"], encoding="utf-8"
).rstrip("\n")
lib_fullnames.append(lib_fullpath)
yield lib_fullpath
except FileNotFoundError: # command not found
pass

Expand All @@ -124,12 +123,11 @@ def clib_full_names(env=None):
for libname in libnames:
libfullpath = find_library(libname)
if libfullpath:
lib_fullnames.append(libfullpath)
yield libfullpath

# Search for library names in the system default path [the lowest priority]
lib_fullnames.extend(libnames)

return lib_fullnames
for libname in libnames:
yield libname


def check_libgmt(libgmt):
Expand Down