-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
85 lines (71 loc) · 2.75 KB
/
setup.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# numpy, ply, ipdb, sympy
#
#
# clingo, sdd,
import os
current_path = os.path.dirname(os.path.abspath(__file__))
package_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lib')
packages_to_install = ["numpy","sympy","ply","Cython"]
def install(packages):
import importlib
try:
from pip._internal import main as pip
except ImportError:
print("Cannot import pip module. Please install pip first.")
exit(0)
try:
import clingo
except ImportError:
print("Cannot import Clingo module. Please install Clingo, and enable Clingo Python Interface.")
exit(0)
try:
from lib.sdd_source import setup
print("Installing SDD library")
setup.build_sdd()
print("Finished installing SDD library")
except:
print("error during installing SDD library. ")
exit(0)
global package_dir
global current_path
try:
print("Installing PySDD library")
pip(['install', os.path.join(package_dir, 'pysdd')])
# For unknown reason, in order to import pysdd.sdd, the pysdd package has to be installed twice
pip(['install', os.path.join(package_dir, 'pysdd')])
print("Finished installing PySDD library")
except:
print("error during installing PySDD library")
exit(0)
try:
print("Installing all other dependencies")
for package in packages:
import subprocess
subprocess.check_call(['pip', 'install', package])
print("Finished installing all other dependencies")
except:
print("error during installing dependencies.")
exit(0)
try:
import sys
with open(current_path + "/lpmln_infer.py", 'r+') as file:
originalContent = file.read()
file.seek(0, 0) # Move the cursor to top line
file.write("#! " + sys.executable + '\n') # Add a new blank line
file.write(originalContent)
with open(current_path + "/lpmln_dec.py", 'r+') as file:
originalContent = file.read()
file.seek(0, 0) # Move the cursor to top line
file.write("#! " + sys.executable + '\n') # Add a new blank line
file.write(originalContent)
with open(current_path + "/lpmln_learn.py", 'r+') as file:
originalContent = file.read()
file.seek(0, 0) # Move the cursor to top line
file.write("#! " + sys.executable + '\n') # Add a new blank line
file.write(originalContent)
except:
print("error during writing entry file path")
exit(0)
print("All Done!")
if __name__ == '__main__':
install(packages_to_install)