Skip to content

Commit

Permalink
Fix finder.load() for conda and LD path search
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Jan 16, 2024
1 parent 4fd6fc9 commit d46bec2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pypestutils/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ctypes
import os
import platform
import sys
from ctypes.util import find_library
from pathlib import Path

Expand Down Expand Up @@ -29,6 +30,13 @@ def load() -> ctypes.CDLL:
if os.name == "nt":
lib_name = "pestutils.dll"

# add search paths for conda installs
if (
os.path.exists(os.path.join(sys.prefix, "conda-meta"))
or "conda" in sys.version
):
_candidates.append(os.path.join(sys.prefix, "Library", "bin"))

# get the current PATH
oldenv = os.environ.get("PATH", "").strip().rstrip(";")
# run through our list of candidate locations
Expand All @@ -41,7 +49,6 @@ def load() -> ctypes.CDLL:
try:
rt = ctypes.cdll.LoadLibrary(os.path.join(path, lib_name))
if rt is not None:
print("lib found at",path)
return rt
except OSError:
pass
Expand Down Expand Up @@ -86,7 +93,6 @@ def load() -> ctypes.CDLL:
# try loading the target file candidate
rt = ctypes.cdll.LoadLibrary(target)
if rt is not None:
print("lib found at",path)
return rt
except BaseException as err:
print(f"pypestutils.finder ({target}) unexpected error: {err!s}")
Expand All @@ -95,9 +101,8 @@ def load() -> ctypes.CDLL:

try:
# try loading library using LD path search
path = find_library("libpestutils")
path = find_library("pestutils")
if path is not None:
print("lib found at",path)
return ctypes.cdll.LoadLibrary(path)

except BaseException:
Expand Down

0 comments on commit d46bec2

Please sign in to comment.