D6090: packaging: extract python exe info to own function
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Fri Mar 8 00:50:13 UTC 2019
indygreg created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This is generic functionality. We'll need it for WIX.
As part of the port, we expose the full version and return
the data as a dict.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D6090
AFFECTED FILES
contrib/packaging/hgpackaging/inno.py
contrib/packaging/hgpackaging/util.py
CHANGE DETAILS
diff --git a/contrib/packaging/hgpackaging/util.py b/contrib/packaging/hgpackaging/util.py
--- a/contrib/packaging/hgpackaging/util.py
+++ b/contrib/packaging/hgpackaging/util.py
@@ -7,8 +7,10 @@
# no-check-code because Python 3 native.
+import distutils.version
import os
import pathlib
+import subprocess
import tarfile
import zipfile
@@ -46,3 +48,26 @@
d / 'msvcr90.dll',
winsxs / 'Manifests' / ('%s.manifest' % version),
]
+
+
+PRINT_PYTHON_INFO = '''
+import platform; print("%s:%s" % (platform.architecture()[0], platform.python_version()))
+'''.strip()
+
+
+def python_exe_info(python_exe: pathlib.Path):
+ """Obtain information about a Python executable."""
+
+ res = subprocess.run(
+ [str(python_exe), '-c', PRINT_PYTHON_INFO],
+ capture_output=True, check=True)
+
+ arch, version = res.stdout.decode('utf-8').split(':')
+
+ version = distutils.version.LooseVersion(version)
+
+ return {
+ 'arch': arch,
+ 'version': version,
+ 'py3': version >= distutils.version.LooseVersion('3'),
+ }
diff --git a/contrib/packaging/hgpackaging/inno.py b/contrib/packaging/hgpackaging/inno.py
--- a/contrib/packaging/hgpackaging/inno.py
+++ b/contrib/packaging/hgpackaging/inno.py
@@ -19,14 +19,10 @@
extract_tar_to_directory,
extract_zip_to_directory,
find_vc_runtime_files,
+ python_exe_info,
)
-PRINT_PYTHON_INFO = '''
-import platform, sys; print("%s:%d" % (platform.architecture()[0], sys.version_info[0]))
-'''.strip()
-
-
def build(source_dir: pathlib.Path, build_dir: pathlib.Path,
python_exe: pathlib.Path, iscc_exe: pathlib.Path,
version=None):
@@ -50,23 +46,18 @@
# architecture.
vc_x64 = r'\x64' in os.environ['LIB']
- res = subprocess.run(
- [str(python_exe), '-c', PRINT_PYTHON_INFO],
- capture_output=True, check=True)
-
- py_arch, py_version = res.stdout.decode('utf-8').split(':')
- py_version = int(py_version)
+ py_info = python_exe_info(python_exe)
if vc_x64:
- if py_arch != '64bit':
+ if py_info['arch'] != '64bit':
raise Exception('architecture mismatch: Visual C++ environment '
'is configured for 64-bit but Python is 32-bit')
else:
- if py_arch != '32bit':
+ if py_info['arch'] != '32bit':
raise Exception('architecture mismatch: Visual C++ environment '
'is configured for 32-bit but Python is 64-bit')
- if py_version != 2:
+ if py_info['py3']:
raise Exception('Only Python 2 is currently supported')
build_dir.mkdir(exist_ok=True)
To: indygreg, #hg-reviewers
Cc: mjpieters, mercurial-devel
More information about the Mercurial-devel
mailing list