-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_path.py
139 lines (119 loc) · 5.02 KB
/
setup_path.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Import this module to automatically setup path to local win32py module
# This module first tries to see if win32py module is installed via pip
# If it does then we don't do anything else
# Else we look up grand-parent folder to see if it has win32py folder
# and if it does then we add that in sys.path
import os,sys,logging
#this class simply tries to see if airsim
class SetupPath:
@staticmethod
def getDirLevels(path):
path_norm = os.path.normpath(path)
return len(path_norm.split(os.sep))
@staticmethod
def getCurrentPath():
cur_filepath = __file__
return os.path.dirname(cur_filepath)
@staticmethod
def getGrandParentDir():
cur_path = SetupPath.getCurrentPath()
if SetupPath.getDirLevels(cur_path) >= 2:
return os.path.dirname(os.path.dirname(cur_path))
return ''
@staticmethod
def getParentDir():
cur_path = SetupPath.getCurrentPath()
if SetupPath.getDirLevels(cur_path) >= 1:
return os.path.dirname(cur_path)
return ''
@staticmethod
def addPyWin32Module():
# if pywin32 module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
pywin32_path = os.path.join(parent, 'pywin32')
client_path = os.path.join(pywin32_path, 'pythoncom.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("pywin32 module not found in parent folder. Using installed package (pip install pywin32).")
@staticmethod
def addtwillModule():
# if twill module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
twill_path = os.path.join(parent, 'twill-3.0.1')
client_path = os.path.join(twill_path, 'setup.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("twill module not found in parent folder. Using installed package (pip install twill).")
@staticmethod
def addpandasModule():
# if pandas module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
pandas_path = os.path.join(parent, 'pandas-1.3.5')
client_path = os.path.join(pandas_path, 'setup.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("pandas module not found in parent folder. Using installed package (pip install pandas).")
@staticmethod
def addRequestsModule():
# if requests module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
r_path = os.path.join(parent, 'requests-2.26.0')
client_path = os.path.join(r_path, 'setup.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("requests module not found in parent folder. Using installed package (pip install requests).")
@staticmethod
def addZipModule():
# if zip module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
z_path = os.path.join(parent, 'zip-0.0.2')
client_path = os.path.join(z_path, 'setup.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("zip module not found in parent folder. Using installed package (pip install zip).")
@staticmethod
def addNumpyModule():
# if numpy module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
numpy_path = os.path.join(parent, 'numpy-1.21.4')
client_path = os.path.join(numpy_path, 'setup.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("numpy module not found in parent folder. Using installed package (pip install numpy).")
@staticmethod
def addMatplotlibModule():
# if matplotlib module is installed then don't do anything else
# return
parent = SetupPath.getParentDir()
if parent != '':
mat_path = os.path.join(parent, 'matplotlib-3.5.1')
client_path = os.path.join(mat_path, 'setup.py')
if os.path.exists(client_path):
sys.path.insert(0, parent)
else:
logging.warning("matplotlib module not found in parent folder. Using installed package (pip install matplotlib).")
SetupPath.addpandasModule()
SetupPath.addNumpyModule()
SetupPath.addMatplotlibModule()
SetupPath.addRequestsModule()
SetupPath.addZipModule()
SetupPath.addtwillModule()
SetupPath.addPyWin32Module()