@@ -17,32 +17,89 @@ local REQUEST_HEADERS = {
1717
1818-- download source
1919local DOWNLOAD_SOURCE = {
20- --- TODO support zip or web-based installers
21- WEB_BASED = PYTHON_URL .. " %s/python-%s%s-webinstall.exe" ,
22- ZIP = PYTHON_URL .. " %s/python-%s-embed-%s.zip" ,
23- MSI = " " ,
24- --- Currently only exe installers are supported
20+ MSI = PYTHON_URL .. " %s/python-%s.%s.msi" ,
2521 EXE = PYTHON_URL .. " %s/python-%s%s.exe" ,
26- SOURCE = PYTHON_URL .. " %s/Python-%s.tar.xz "
22+ SOURCE = PYTHON_URL .. " %s/Python-%s.tar" ,
2723}
2824
2925function checkIsReleaseVersion (version )
3026 local resp , err = http .head ({
31- url = DOWNLOAD_SOURCE .SOURCE :format (version , version ),
27+ url = DOWNLOAD_SOURCE .SOURCE :format (version , version ) .. ' .xz ' ,
3228 headers = REQUEST_HEADERS
3329 })
34- if err ~= nil or resp .status_code ~ = 200 then
35- return false
30+ if err == nil and resp .status_code = = 200 then
31+ return true
3632 end
37- return true
33+
34+ local resp , err = http .head ({
35+ url = DOWNLOAD_SOURCE .SOURCE :format (version , version ) .. ' .bz2' ,
36+ headers = REQUEST_HEADERS
37+ })
38+ if err == nil and resp .status_code == 200 then
39+ return true
40+ end
41+
42+ return false
3843end
3944
40- function windowsCompile (ctx )
45+ function windowsInstall (ctx )
4146 local sdkInfo = ctx .sdkInfo [' python' ]
4247 local path = sdkInfo .path
4348 local version = sdkInfo .version
44- local url , filename = getReleaseForWindows (version )
49+ local url = getReleaseForWindows (version )
50+ local filename = url :match (" [^/\\ ]+$" )
51+ if string.sub (filename , - 3 ) == " msi" then
52+ windowsInstallMsi (path , url , version , filename )
53+ elseif string.sub (filename , - 3 ) == " exe" then
54+ windowsInstallExe (path , url , version , filename )
55+ end
56+
57+ end
4558
59+ function windowsInstallMsi (path , url , version , filename )
60+ -- WARNNING:
61+ -- The msi installer for python 2.x must be downloaded to another directory
62+ -- it cannot be installed in the current directory.
63+ local qInstallFile = RUNTIME .pluginDirPath .. " \\ " .. filename
64+ local qInstallPath = path
65+
66+ -- download
67+ print (" Downloading installer..." )
68+ print (" from:\t " .. url )
69+ print (" to:\t " .. qInstallFile )
70+ local err = http .download_file ({
71+ url = url ,
72+ headers = REQUEST_HEADERS
73+ }, qInstallFile )
74+
75+ if err ~= nil then
76+ error (" Downloading installer failed" )
77+ end
78+
79+ -- Install msi
80+ print (" Installing python..." )
81+ local command = ' msiexec /quiet /a ' .. qInstallFile .. ' TargetDir=' .. qInstallPath
82+ local exitCode = os.execute (command )
83+ os.remove (qInstallFile )
84+ if exitCode ~= 0 then
85+ error (" Install msi failed: " .. qInstallFile )
86+ end
87+
88+ -- Install pip
89+ local ensurepipPath = qInstallPath .. " \\ Lib\\ ensurepip\\ __init__.py"
90+ local file = io.open (ensurepipPath , " r" )
91+ if file then
92+ io.close (file )
93+ print (" Installing pip..." )
94+ local command = qInstallPath .. ' \\ python -E -s -m ensurepip -U --default-pip > NUL'
95+ local exitCode = os.execute (command )
96+ if exitCode ~= 0 then
97+ error (" Install pip failed. exit " .. exitCode )
98+ end
99+ end
100+ end
101+
102+ function windowsInstallExe (path , url , version , filename )
46103 --- Attention system difference
47104 local qInstallFile = path .. " \\ " .. filename
48105 local qInstallPath = path
@@ -178,20 +235,29 @@ function getReleaseForWindows(version)
178235 local archType = RUNTIME .archType
179236 if archType == " 386" then
180237 archType = " "
181- else
182- archType = " -" .. archType
183238 end
184- --- Currently only exe installers are supported
185- --- TODO support zip or web-based installers
186- local url = DOWNLOAD_SOURCE .EXE :format (version , version , archType )
239+
240+ -- try get exe file
241+ local url = DOWNLOAD_SOURCE .EXE :format (version , version , ' - ' .. archType )
187242 local resp , err = http .head ({
188243 url = url ,
189244 headers = REQUEST_HEADERS
190245 })
191- if err ~= nil or resp .status_code ~= 200 then
192- error (" No available installer found for current version" )
246+ if err == nil and resp .status_code == 200 then
247+ return url
248+ end
249+
250+ -- try get msi file
251+ local url = DOWNLOAD_SOURCE .MSI :format (version , version , archType )
252+ local resp , err = http .head ({
253+ url = url ,
254+ headers = REQUEST_HEADERS
255+ })
256+ if err == nil and resp .status_code == 200 then
257+ return url
193258 end
194- return url , " python-" .. version .. archType .. " .exe"
259+ print (" url:\t " .. url )
260+ error (" No available installer found for current version" )
195261end
196262function parseVersion ()
197263 local resp , err = http .get ({
@@ -209,7 +275,7 @@ function parseVersion()
209275 if sn and es then
210276 local vn = string.sub (href , 1 , - 2 )
211277 if RUNTIME .osType == " windows" then
212- if compare_versions (vn , " 3 .5.0" ) >= 0 then
278+ if compare_versions (vn , " 2 .5.0" ) >= 0 then
213279 table.insert (result , {
214280 version = string.sub (href , 1 , - 2 ),
215281 note = " "
0 commit comments