Skip to content

Commit cebc0a0

Browse files
authored
Merge pull request #19 from manthey/latest-python
Install the latest point version of python.
2 parents c15b591 + ee24861 commit cebc0a0

File tree

3 files changed

+148
-9
lines changed

3 files changed

+148
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Set program icon.
2020
- When running a Python program, the globals are closer to native Python.
2121
- Update to setuptools 39.1.0.
22+
- Update to Python 2.7.15, 3.5.4, 3.6.5.
2223

2324
### Bug Fixes
2425

appveyor.yml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,68 @@
11
environment:
22
matrix:
33
- PYTHON: "C:\\Python27"
4+
INSTALL_OPTIONS: 2.7 --min=15
45
OUTPUT: "py27.exe"
6+
ALTPYTHON: "C:\\Python36-x64"
57
- PYTHON: "C:\\Python27-x64"
8+
INSTALL_OPTIONS: 2.7 --min=15 --64
69
OUTPUT: "py27-64.exe"
10+
ALTPYTHON: "C:\\Python36-x64"
711
- PYTHON: "C:\\Python35"
12+
INSTALL_OPTIONS: 3.5 --min=4
813
OUTPUT: "py35.exe"
14+
ALTPYTHON: "C:\\Python36-x64"
915
- PYTHON: "C:\\Python35-x64"
16+
INSTALL_OPTIONS: 3.5 --min=4 --64
1017
OUTPUT: "py35-64.exe"
18+
ALTPYTHON: "C:\\Python36-x64"
1119
- PYTHON: "C:\\Python36"
20+
INSTALL_OPTIONS: 3.6 --min=5
1221
OUTPUT: "py36.exe"
22+
ALTPYTHON: "C:\\Python36-x64"
1323
- PYTHON: "C:\\Python36-x64"
24+
INSTALL_OPTIONS: 3.6 --min=5 --64
1425
OUTPUT: "py36-64.exe"
26+
ALTPYTHON: "C:\\Python36"
1527

1628
init:
1729
- SET PROJDIR=%cd%
1830
- SET ORIGPATH=%PATH%
19-
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
20-
- python -m pip install --upgrade pip
21-
- python -m pip install --upgrade setuptools
22-
- python -m pip install pywin32 psutil six setuptools
23-
- python -m pip install pyinstaller
24-
# Remove the site module hook from PyInstaller; we need the site module as is
25-
- "del /q %PYTHON%\\Lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.*"
26-
- "del /q /s %PYTHON%\\Lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\__pycache__"
2731
- mkdir c:\u
2832
- cd c:\u
2933
- curl -L -O "https://github.com/upx/upx/releases/download/v3.94/upx394w.zip"
3034
- unzip upx394w.zip
3135
- cd %PROJDIR%
3236

3337
build_script:
38+
# Upgrade the appveyor python version
39+
- "SET PATH=%ALTPYTHON%;%ALTPYTHON%\\Scripts;%ORIGPATH%"
40+
- python -m pip install --upgrade requests
41+
- "python install_python.py %INSTALL_OPTIONS% --out=%PYTHON% --force"
42+
- del /S /Q %PYTHON%\*.pyc >NUL
43+
- del /S /Q %PYTHON%\*.pyo >NUL
44+
# Use the specific python version for building
45+
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%ORIGPATH%"
46+
- python -m pip install --upgrade pip
47+
- python -m pip install --upgrade setuptools
48+
- python -m pip install --upgrade pywin32 psutil six setuptools
49+
# Generate the list of modules we need to import
50+
- del /S /Q %PYTHON%\*.pyc >NUL
51+
- del /S /Q %PYTHON%\*.pyo >NUL
52+
- python modules_pyexe.py pyexe.py
53+
# Install PyInstaller
54+
- python -m pip install pyinstaller
55+
# Remove the site module hook from PyInstaller; we need the site module as is
56+
- "del /q %PYTHON%\\Lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.*"
57+
- "del /q /s %PYTHON%\\Lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\__pycache__"
3458
# Copy a build hook to PyInstaller to include the cacerts.pem file for pip.
3559
- "copy hooks\\hook*.* %PYTHON%\\Lib\\site-packages\\PyInstaller\\hooks\\."
3660
# Replace the multiprocessing loader hook
3761
- "copy hooks\\pyi_rth*.* %PYTHON%\\Lib\\site-packages\\PyInstaller\\loader\\rthooks\\."
3862
# Replace the stage 3 importer
3963
- "copy hooks\\pyimod03_importers.py %PYTHON%\\Lib\\site-packages\\PyInstaller\\loader\\."
40-
- python modules_pyexe.py pyexe.py
64+
- del /S /Q %PYTHON%\*.pyc >NUL
65+
- del /S /Q %PYTHON%\*.pyo >NUL
4166
# Save the artifact immediately
4267
- appveyor PushArtifact pyexe.py
4368
- "python -m PyInstaller --onefile pyexe.py --upx-dir C:\\u\\upx394w\\upx.exe --exclude-module FixTk --exclude-module tcl --exclude-module tk --exclude-module _tkinter --exclude-module tkinter --exclude-module Tkinter --runtime-hook hooks\\rth_subprocess.py --icon %PYTHON%\\pythonw.exe"

install_python.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import os
2+
import requests
3+
import subprocess
4+
import sys
5+
6+
if __name__ == '__main__': # noqa
7+
dest = '.'
8+
instdest = None
9+
force = False
10+
help = False
11+
is64 = False
12+
keep = False
13+
minpoint = 0
14+
remove = False
15+
version = None
16+
for arg in sys.argv[1:]:
17+
if arg.startswith('-'):
18+
if arg in ('-f', '--force'):
19+
force = True
20+
elif arg in ('-k', '--keep'):
21+
keep = True
22+
elif arg.startswith('--inst='):
23+
instdest = arg.split('=', 1)[1]
24+
elif arg.startswith('--min='):
25+
minpoint = int(arg.split('=', 1)[1])
26+
elif arg.startswith('--out='):
27+
dest = arg.split('=', 1)[1]
28+
elif arg in ('-r', '--remove'):
29+
remove = True
30+
elif arg == '--32':
31+
is64 = False
32+
elif arg == '--64':
33+
is64 = True
34+
else:
35+
help = True
36+
elif not version:
37+
version = arg
38+
else:
39+
help = True
40+
if help or not version:
41+
print("""Install the latest revision of a version of python.
42+
43+
Syntax: install_python.py (version) [--32|--64] [--out=(destination directory)]
44+
[--inst=(installation directory)] [--force]
45+
[--min=(minimum point release)] [--keep] [--remove]
46+
47+
Specify just the major and minor version, such as 2.7 or 3.6.
48+
--force will overwrite an existing installation file.
49+
--keep keeps the install file.
50+
--remove first uninstalls the specified version of python.""")
51+
sys.exit(0)
52+
baseurl = 'https://www.python.org/ftp/python/'
53+
versionList = requests.get(baseurl).text
54+
versionList = [part.split('"')[0] for part in versionList.split('<a href="')[1:]]
55+
versionList = sorted([(int(ver[len(version) + 1:].strip('/')), ver)
56+
for ver in versionList if ver.startswith(version + '.')],
57+
reverse=True)
58+
for subver, ver in versionList:
59+
if subver < minpoint:
60+
continue
61+
url = baseurl + ver + 'python-' + version + '.' + str(subver) + (
62+
'' if not is64 else ('.amd64' if version.startswith('2') else '-amd64')) + (
63+
'.msi' if version.startswith('2') else '.exe')
64+
try:
65+
response = requests.get(url).content
66+
if len(response) < 1000000:
67+
continue
68+
break
69+
except Exception:
70+
continue
71+
if len(response) < 1000000:
72+
raise Exception('Failed to find install file')
73+
print('Size: %d, url: %s' % (len(response), url))
74+
if instdest is None:
75+
instdest = os.path.split(dest)[0]
76+
if not os.path.exists(instdest):
77+
os.makedirs(instdest)
78+
installer = os.path.join(instdest, url.rsplit('/', 1)[-1])
79+
if os.path.exists(installer) and not force:
80+
raise Exception('Path already exists: %s' % installer)
81+
open(installer, 'wb').write(response)
82+
if installer.endswith('.msi'):
83+
uncmd = ['msiexec', '/uninstall', installer, '/quiet', '/norestart']
84+
cmd = ['msiexec', '/i', installer, '/quiet', '/norestart']
85+
altcmd = ['msiexec', '/fa', installer, '/quiet', '/norestart']
86+
else:
87+
uncmd = [installer, '/quiet', '/uninstall']
88+
cmd = [installer, '/quiet']
89+
altcmd = [installer, '/quiet', '/repair']
90+
cmdopts = [
91+
'TargetDir=' + dest, 'AssociateFiles=0', 'CompileAll=0',
92+
'PrependPath=0', 'Shortcuts=0', 'Include_doc=0', 'Include_dev=0',
93+
'Include_debug=0', 'Include_exe=1', 'Include_launcher=0',
94+
'InstallLauncherAllUsers=0', 'Include_lib=1', 'Include_symbols=0',
95+
'Include_tcltk=0', 'Include_test=0', 'Include_tools=0',
96+
'SimpleInstall=1']
97+
if remove:
98+
print('Remove: ' + ' '.join(uncmd))
99+
try:
100+
subprocess.check_call(uncmd)
101+
except Exception:
102+
pass
103+
print('Install: ' + ' '.join(cmd + cmdopts))
104+
try:
105+
subprocess.check_call(cmd + cmdopts)
106+
except Exception:
107+
pass
108+
if not os.path.exists(os.path.join(dest, 'python.exe')):
109+
print('Update ' + ' '.join(altcmd + cmdopts))
110+
subprocess.check_call(altcmd + cmdopts)
111+
print('Done')
112+
if not keep:
113+
os.unlink(installer)

0 commit comments

Comments
 (0)