|
1 | 1 | import os |
2 | | -mm_install_path = os.path.normpath(os.path.dirname(__file__) + '/../../../MMVII/MMVII') |
| 2 | +import sys |
| 3 | +from pathlib import Path |
3 | 4 |
|
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) |
6 | 35 | from _MMVII import * |
7 | | - themodule = MM_Module(mm_install_path) |
| 36 | + themodule = MM_Module(mm_data_path) |
8 | 37 | else: |
9 | | - print('Error: please do not run from this directory') |
| 38 | + print('Error: impossible to find MMVII binary. Error at installation?') |
10 | 39 |
|
0 commit comments