Skip to content

Commit 7f4b2a5

Browse files
committed
Fixes the find_library import and adds an 'initialized' variable to the Dyad class
1 parent 286ec05 commit 7f4b2a5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pydyad/pydyad/bindings.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ctypes
2+
from ctypes.util import find_library
23
import os
34
from pathlib import Path
45
import warnings
@@ -37,6 +38,7 @@ class DyadCtxWrapper(ctypes.Structure):
3738
class Dyad:
3839

3940
def __init__(self):
41+
self.initialized = False
4042
self.dyad_core_lib = None
4143
self.ctx = None
4244
self.dyad_init = None
@@ -47,7 +49,7 @@ def __init__(self):
4749
dyad_core_lib_file = None
4850
self.cons_path = None
4951
self.prod_path = None
50-
dyad_core_lib_file = ctypes.util.find_library("dyad_core")
52+
dyad_core_lib_file = find_library("dyad_core")
5153
if dyad_core_lib_file is None:
5254
raise FileNotFoundError("Cannot find libdyad_core.so using 'ctypes'")
5355
self.dyad_core_lib = ctypes.CDLL(dyad_core_lib_file)
@@ -122,6 +124,7 @@ def init(self, debug, check, shared_storage, key_depth,
122124
self.cons_path = None
123125
else:
124126
self.cons_path = Path(self.ctx.contents.cons_managed_path.decode("utf-8")).expanduser().resolve()
127+
self.initialized = True
125128

126129
def init_env(self):
127130
if self.dyad_init_env is None:
@@ -176,6 +179,8 @@ def consume(self, fname):
176179
raise RuntimeError("Cannot consume data with DYAD!")
177180

178181
def finalize(self):
182+
if not self.initialized:
183+
return
179184
if self.dyad_finalize is None:
180185
warnings.warn(
181186
"Trying to finalize DYAD when libdyad_core.so was not found",

0 commit comments

Comments
 (0)