##// END OF EJS Templates
packaging: extract python exe info to own function...
Gregory Szorc -
r42080:7d121116 default
parent child Browse files
Show More
@@ -19,14 +19,10 b' from .util import ('
19 extract_tar_to_directory,
19 extract_tar_to_directory,
20 extract_zip_to_directory,
20 extract_zip_to_directory,
21 find_vc_runtime_files,
21 find_vc_runtime_files,
22 python_exe_info,
22 )
23 )
23
24
24
25
25 PRINT_PYTHON_INFO = '''
26 import platform, sys; print("%s:%d" % (platform.architecture()[0], sys.version_info[0]))
27 '''.strip()
28
29
30 def build(source_dir: pathlib.Path, build_dir: pathlib.Path,
26 def build(source_dir: pathlib.Path, build_dir: pathlib.Path,
31 python_exe: pathlib.Path, iscc_exe: pathlib.Path,
27 python_exe: pathlib.Path, iscc_exe: pathlib.Path,
32 version=None):
28 version=None):
@@ -50,23 +46,18 b' def build(source_dir: pathlib.Path, buil'
50 # architecture.
46 # architecture.
51 vc_x64 = r'\x64' in os.environ['LIB']
47 vc_x64 = r'\x64' in os.environ['LIB']
52
48
53 res = subprocess.run(
49 py_info = python_exe_info(python_exe)
54 [str(python_exe), '-c', PRINT_PYTHON_INFO],
55 capture_output=True, check=True)
56
57 py_arch, py_version = res.stdout.decode('utf-8').split(':')
58 py_version = int(py_version)
59
50
60 if vc_x64:
51 if vc_x64:
61 if py_arch != '64bit':
52 if py_info['arch'] != '64bit':
62 raise Exception('architecture mismatch: Visual C++ environment '
53 raise Exception('architecture mismatch: Visual C++ environment '
63 'is configured for 64-bit but Python is 32-bit')
54 'is configured for 64-bit but Python is 32-bit')
64 else:
55 else:
65 if py_arch != '32bit':
56 if py_info['arch'] != '32bit':
66 raise Exception('architecture mismatch: Visual C++ environment '
57 raise Exception('architecture mismatch: Visual C++ environment '
67 'is configured for 32-bit but Python is 64-bit')
58 'is configured for 32-bit but Python is 64-bit')
68
59
69 if py_version != 2:
60 if py_info['py3']:
70 raise Exception('Only Python 2 is currently supported')
61 raise Exception('Only Python 2 is currently supported')
71
62
72 build_dir.mkdir(exist_ok=True)
63 build_dir.mkdir(exist_ok=True)
@@ -7,8 +7,10 b''
7
7
8 # no-check-code because Python 3 native.
8 # no-check-code because Python 3 native.
9
9
10 import distutils.version
10 import os
11 import os
11 import pathlib
12 import pathlib
13 import subprocess
12 import tarfile
14 import tarfile
13 import zipfile
15 import zipfile
14
16
@@ -46,3 +48,26 b' def find_vc_runtime_files(x64=False):'
46 d / 'msvcr90.dll',
48 d / 'msvcr90.dll',
47 winsxs / 'Manifests' / ('%s.manifest' % version),
49 winsxs / 'Manifests' / ('%s.manifest' % version),
48 ]
50 ]
51
52
53 PRINT_PYTHON_INFO = '''
54 import platform; print("%s:%s" % (platform.architecture()[0], platform.python_version()))
55 '''.strip()
56
57
58 def python_exe_info(python_exe: pathlib.Path):
59 """Obtain information about a Python executable."""
60
61 res = subprocess.run(
62 [str(python_exe), '-c', PRINT_PYTHON_INFO],
63 capture_output=True, check=True)
64
65 arch, version = res.stdout.decode('utf-8').split(':')
66
67 version = distutils.version.LooseVersion(version)
68
69 return {
70 'arch': arch,
71 'version': version,
72 'py3': version >= distutils.version.LooseVersion('3'),
73 }
General Comments 0
You need to be logged in to leave comments. Login now