forked from Esri/raster-functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
152 lines (117 loc) · 4.95 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
'''
====================================================================================
setup.py: Automated installation of dependencies required for Python raster function
====================================================================================
Installation
------------
To execute **setup.py** within the package directory run:
$ python setup.py
'''
import sys
import logging
from os import path, makedirs
from subprocess import call
from time import sleep
'''
ErrorLevel on exit:
0 : Installation successful.
1 : PIP installation unsuccessful.
2 : File cannot be downloaded.
4 : VC++ Compiler for Python installation failed.
5 : Requirements.txt file not found.
6 : Python package installation failed.
99 : ArcGIS 10.3.1 or above not found.
'''
def log(s):
print(">>> {0}".format(s))
def die(errorLog, errorCode):
print("\n\n")
logging.error(errorLog)
print("\n")
sleep(2)
exit(errorCode)
def downloadFile(url, filePath):
try:
log("Downloading: {0} to {1}".format(url, filePath))
try:
from urllib2 import urlopen
except:
from urllib.request import urlopen
d = path.dirname(filePath)
if not path.exists(d):
makedirs(d)
with open(filePath, 'wb') as f:
f.write(urlopen(url).read())
except:
die("Unable to download URL", 2)
def locateFile(url, filePath):
if not path.isfile(filePath):
downloadFile(url, filePath)
log("Located: {0}".format(filePath))
def main():
pipURL = "http://bootstrap.pypa.io/get-pip.py"
vcURL = "http://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi"
pipExePath = path.join(path.dirname(sys.executable), r"Scripts\pip.exe")
setupHome = path.join(path.abspath(path.dirname(__file__)), "scripts")
distHome = path.join(path.abspath(path.dirname(__file__)), "dist")
try:
log("Installing PIP")
pipPyPath = path.join(setupHome, "get-pip.py")
locateFile(pipURL, pipPyPath)
call([sys.executable, pipPyPath])
if path.isfile(pipExePath):
log("PIP installed successfully")
else:
raise Exception("PIP failed")
call([pipExePath, "install", "--upgrade", "--no-index", "--find-links={0}".format(distHome), "pip"])
call([pipExePath, "install", "--upgrade", "--no-index", "--find-links={0}".format(distHome), "wheel"])
except:
die("PIP installation failed!", 1)
try:
if sys.version_info[0] == 2:
log("Installing Microsoft Visual C++ Compiler")
vcSetupPath = path.join(distHome, "VCForPython27.msi")
locateFile(vcURL, vcSetupPath)
c = ["msiexec", "/i", vcSetupPath, "/qb-"]
log("Executing: {0}".format(" ".join(c)))
call(c)
log("C++ Compiler for Python installed successfully")
except:
die("VC++ Compiler for Python installation failed!.", 4)
try:
log("Installing Python dependencies")
reqFilePath = path.join(setupHome, "requirements.txt")
if not path.isfile(reqFilePath):
die("Dependency listing file not found: {0}".format(reqFilePath), 5)
c = [pipExePath, "install", "--upgrade", "--no-index", "--find-links={0}".format(distHome), "-r", reqFilePath]
log("Executing: {0}".format(" ".join(c)))
call(c)
except:
die("Dependency installation failed!", 6)
try:
arcpy = __import__('arcpy')
info = arcpy.GetInstallInfo()
bVersionOK = True
minArcGISVersion = '10.3.1'
if info['Version'].split(".")[0] == 10 and (tuple(map(int, (info['Version'].split(".")))) < tuple(map(int, (minArcGISVersion.split("."))))):
bVersionOK = False
minProVersion = '1.0'
if info['Version'].split(".")[0] == 1 and (tuple(map(int, (info['Version'].split(".")))) < tuple(map(int, (minProVersion.split("."))))):
bVersionOK = False
if not bVersionOK:
raise Exception("No ArcGIS")
print("\n\n")
if info['Version'][0] == 10:
log("Python extensions for raster functions in ArcGIS {} {} build {} successfully installed.".format(
info['ProductName'], info['Version'], info['BuildNumber']))
else:
log("Python extensions for raster functions in {} {} build {} successfully installed.".format(
info['ProductName'], info['Version'], info['BuildNumber']))
except:
logging.warn("Unable to find ArcGIS 10.3.1/ArcGIS Pro 1.0 or above.")
log("Done.")
sleep(2)
exit(0)
if __name__ == '__main__':
main()
# Uninstall using: pip uninstall --yes -r requirements.txt