Skip to content

Commit 18b9f23

Browse files
committed
WIP: Add ability to use shipped edfapi shared library (macos and linux)
1 parent 6a17f29 commit 18b9f23

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
sudo ldconfig
2222
python -m pip install --upgrade pip
2323
pip install -e ".[dev]"
24+
name: Setup environment
25+
export EYELINKIO_USE_INSTALLED_EDFAPI=true
2426

2527
- run:
2628
name: Run tests

eyelinkio/edf/_edf2py.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Wrapper for libedfapi.so."""
22

3+
import os
34
import struct
45
import sys
56
from ctypes import (
@@ -17,15 +18,52 @@
1718
c_ushort,
1819
util,
1920
)
21+
from pathlib import Path
22+
2023

2124
# find and load the library
22-
if sys.platform.startswith('win') and (8 * struct.calcsize("P") == 64):
23-
name = 'edfapi64' # on windows you can install both
25+
def find_installed_library():
26+
"""Try to find edfapi that is installed on the users system."""
27+
if sys.platform.startswith('win') and (8 * struct.calcsize("P") == 64):
28+
name = 'edfapi64' # on windows you can install both
29+
else:
30+
name = 'edfapi'
31+
fname = util.find_library(name)
32+
if fname is None:
33+
raise OSError('edfapi not found')
34+
return fname
35+
36+
37+
def get_lib_path():
38+
"""Get the path to the edfapi shared library that we ship with eyelinkio."""
39+
lib_path = Path(__file__).parent.parent.parent / "libedfapi"
40+
if sys.platform.startswith('win'):
41+
if (8 * struct.calcsize("P") == 64): # 64 bit
42+
lib_path = lib_path / "win64" / "edfapi64.dll"
43+
else: # 32 bit
44+
lib_path = lib_path / "win32" / "edfapi.dll"
45+
elif sys.platform.startswith('darwin'):
46+
lib_path = (lib_path /
47+
"macos" /
48+
"edfapi.framework" /
49+
"Versions" /
50+
"Current" /
51+
"edfapi"
52+
)
53+
elif sys.platform.startswith('linux'):
54+
lib_path = lib_path / "linux" / "libedfapi.so"
55+
else:
56+
raise OSError('Unsupported platform')
57+
assert lib_path.exists(), f"libedfapi.so not found at {lib_path}"
58+
return lib_path.resolve()
59+
60+
61+
if os.environ.get("EYELINKIO_USE_INSTALLED_EDFAPI") == "true":
62+
# Then we will use the edfapi that is installed on the users system
63+
fname = find_installed_library()
2464
else:
25-
name = 'edfapi'
26-
fname = util.find_library(name)
27-
if fname is None:
28-
raise OSError('edfapi not found')
65+
# Otherwise we will use the edfapi that we ship with eyelinkio
66+
fname = get_lib_path()
2967
edfapi = CDLL(fname)
3068

3169

0 commit comments

Comments
 (0)