Skip to content

Commit a167c02

Browse files
committed
apib11: improve module detection, works without install
1 parent 5edf7e4 commit a167c02

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

MMVII/apib11/MMVII.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
11
import os
2-
mm_install_path = os.path.normpath(os.path.dirname(__file__) + '/../../../MMVII/MMVII')
2+
import sys
3+
from pathlib import Path
34

4-
if os.path.isdir(mm_install_path):
5-
print('MMVII path:', mm_install_path)
5+
mmv2_src_relative_path = '../'
6+
mmv2_install_relative_path = '../../../MMVII/MMVII'
7+
8+
mm_data_path = None
9+
10+
# test if run from MMVII sources
11+
test_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_src_relative_path)
12+
if os.path.isfile(test_path + '/bin/MMVII'):
13+
print("Using local MMVII")
14+
mm_data_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_src_relative_path)
15+
#search for .so file
16+
so_path = None
17+
for path in Path('build').rglob('_MMVII.*.so'):
18+
if so_path is None:
19+
so_path = path.parent
20+
else :
21+
print('Warning: multiple _MMVII.*.so files found in build directory')
22+
if so_path is not None:
23+
print("Using _MMVII.*.so file from directory ",so_path)
24+
sys.path = [ str(so_path) ] + sys.path
25+
else:
26+
# test if installed
27+
for p in sys.path:
28+
test_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_install_relative_path)
29+
if os.path.isfile(test_path + '/bin/MMVII'):
30+
mm_data_path = os.path.normpath(os.path.dirname(__file__) + '/' + mmv2_install_relative_path)
31+
break
32+
33+
if mm_data_path is not None:
34+
print('MMVII path:', mm_data_path)
635
from _MMVII import *
7-
themodule = MM_Module(mm_install_path)
36+
themodule = MM_Module(mm_data_path)
837
else:
9-
print('Error: please do not run from this directory')
38+
print('Error: impossible to find MMVII binary. Error at installation?')
1039

0 commit comments

Comments
 (0)