Skip to content

Commit

Permalink
watcher-py: fixup solib name, event struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Oct 14, 2024
1 parent 1baa727 commit 4e55414
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion watcher-py/watcher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Filesystem watcher. Simple, efficient and friendly.
"""

from .watcher import Watch, _CEvent
from .watcher import Watch, EffectType, PathType, Event, _CEvent
27 changes: 14 additions & 13 deletions watcher-py/watcher/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,33 @@
# pylint: disable=too-few-public-methods
class _CEvent(ctypes.Structure):
_fields_ = [
("effect_time", ctypes.c_int64),
("path_name", ctypes.c_char_p),
("associated_path_name", ctypes.c_char_p),
("effect_type", ctypes.c_int8),
("path_type", ctypes.c_int8),
("effect_time", ctypes.c_int64),
("associated_path_name", ctypes.c_char_p),
]


_CCallback = ctypes.CFUNCTYPE(None, _CEvent, ctypes.c_void_p)


def _lazy_static_solib_handle() -> ctypes.CDLL:
def native_solib_file_ending():
def solib_name():
version = "0.12.1" # hook: tool/release
v_major = version.split(".")[0]
sysname = os.uname().sysname
if sysname == "Darwin":
return "dylib"
if sysname == "Windows":
return "dll"
return "so"
return f"libwatcher-c.{v_major}.dylib"
elif sysname == "Windows":
return f"libwatcher-c.dll.{version}"
else:
return f"libwatcher-c.so.{version}"

def libwatcher_c_lib_path():
version = "0.12.1" # hook: tool/release
def solib_path():
heredir = os.path.dirname(os.path.abspath(__file__))
dir_path = os.path.join(heredir, ".watcher.mesonpy.libs")
lib_name = f"libwatcher-c-{version}.{native_solib_file_ending()}"
lib_path = os.path.join(dir_path, lib_name)
dir_path = os.path.join(heredir, ".wtr_watcher.mesonpy.libs")
lib_path = os.path.join(dir_path, solib_name())
if not os.path.exists(lib_path):
raise RuntimeError(f"Library does not exist: '{lib_path}'")
return lib_path
Expand All @@ -51,7 +52,7 @@ def libwatcher_c_lib_path():
# pylint: disable=global-statement
global _LIB
if _LIB is None:
_LIB = ctypes.CDLL(libwatcher_c_lib_path())
_LIB = ctypes.CDLL(solib_path())
_LIB.wtr_watcher_open.argtypes = [ctypes.c_char_p, _CCallback, ctypes.c_void_p]
_LIB.wtr_watcher_open.restype = ctypes.c_void_p
_LIB.wtr_watcher_close.argtypes = [ctypes.c_void_p]
Expand Down

0 comments on commit 4e55414

Please sign in to comment.