forked from OpenNFT/OpenNFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_matlabengine.py
48 lines (35 loc) · 1.28 KB
/
install_matlabengine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-
import sys
from pathlib import Path
import subprocess
sys.path = sys.argv[3:]
import elevate # noqa: E402
import chardet # noqa: E402
def main():
engine_dir = sys.argv[1]
ferr = sys.argv[2]
engine_setup = str(Path(engine_dir, 'setup.py'))
install_command = [sys.executable, engine_setup, 'install']
p = subprocess.run(install_command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=engine_dir)
if p.returncode != 0:
if (b"error: could not create 'build'" in p.stderr
or b"error: You do not have write permission" in p.stderr):
# Access denied, try to install as Administrator/root
elevate.elevate(show_console=False, graphical=True)
try:
stderr_text = p.stderr.decode()
except UnicodeDecodeError:
enc = chardet.detect(p.stderr)['encoding']
if enc:
stderr_text = p.stderr.decode(enc)
else:
# cannot decode bytes, return as it is
stderr_text = str(p.stderr)
with open(ferr, 'w', encoding='utf-8') as fp:
fp.write(stderr_text)
return p.returncode
if __name__ == '__main__':
sys.exit(main())