##// END OF EJS Templates
fsmonitor: refresh pywatchman with upstream...
fsmonitor: refresh pywatchman with upstream This commit vendors pywatchman commit 259dc66dc9591f9b7ce76d0275bb1065f390c9b1 from upstream without modifications. The previously vendored pywatchman from changeset 16f4b341288d was from Git commit c77452. This commit effectively undoes the following Mercurial changesets: * dd35abc409ee fsmonitor: correct an error message * b1f62cd39b5c fsmonitor: layer on another hack in bser.c for os.stat() compat (issue5811) * c31ce080eb75 py3: convert arguments, cwd and env to native strings when spawning subprocess * 876494fd967d cleanup: delete lots of unused local variables * 57264906a996 watchman: add the possibility to set the exact watchman binary location The newly-vendored code has support for specifying the binary location, so 57264906a996 does not need applied. But we do need to modify our code to specify a proper argument name. 876494fd967d is not important, so it will be ignored. c31ce080eb75 globally changed the code base to always pass str to subprocess. But pywatchman's code is Python 3 clean, so we don't need to do this. This leaves dd35abc409ee and b1f62cd39b5c, which will be re-applied in subsequent commits. Differential Revision: https://phab.mercurial-scm.org/D7201

File last commit:

r43346:2372284d default
r43703:6469c23a stable
Show More
py2exe.py
171 lines | 5.3 KiB | text/x-python | PythonLexer
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 # py2exe.py - Functionality for performing py2exe builds.
#
# Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
# no-check-code because Python 3 native.
import os
import pathlib
import subprocess
Augie Fackler
formatting: blacken the codebase...
r43346 from .downloads import download_entry
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 from .util import (
extract_tar_to_directory,
extract_zip_to_directory,
python_exe_info,
)
Augie Fackler
formatting: blacken the codebase...
r43346 def build_py2exe(
source_dir: pathlib.Path,
build_dir: pathlib.Path,
python_exe: pathlib.Path,
build_name: str,
venv_requirements_txt: pathlib.Path,
extra_packages=None,
extra_excludes=None,
extra_dll_excludes=None,
extra_packages_script=None,
):
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 """Build Mercurial with py2exe.
Build files will be placed in ``build_dir``.
py2exe's setup.py doesn't use setuptools. It doesn't have modern logic
for finding the Python 2.7 toolchain. So, we require the environment
to already be configured with an active toolchain.
"""
if 'VCINSTALLDIR' not in os.environ:
Augie Fackler
formatting: blacken the codebase...
r43346 raise Exception(
'not running from a Visual C++ build environment; '
'execute the "Visual C++ <version> Command Prompt" '
'application shortcut or a vcsvarsall.bat file'
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
# Identity x86/x64 and validate the environment matches the Python
# architecture.
vc_x64 = r'\x64' in os.environ['LIB']
py_info = python_exe_info(python_exe)
if vc_x64:
if py_info['arch'] != '64bit':
Augie Fackler
formatting: blacken the codebase...
r43346 raise Exception(
'architecture mismatch: Visual C++ environment '
'is configured for 64-bit but Python is 32-bit'
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 else:
if py_info['arch'] != '32bit':
Augie Fackler
formatting: blacken the codebase...
r43346 raise Exception(
'architecture mismatch: Visual C++ environment '
'is configured for 32-bit but Python is 64-bit'
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
if py_info['py3']:
raise Exception('Only Python 2 is currently supported')
build_dir.mkdir(exist_ok=True)
gettext_pkg, gettext_entry = download_entry('gettext', build_dir)
gettext_dep_pkg = download_entry('gettext-dep', build_dir)[0]
virtualenv_pkg, virtualenv_entry = download_entry('virtualenv', build_dir)
py2exe_pkg, py2exe_entry = download_entry('py2exe', build_dir)
Augie Fackler
formatting: blacken the codebase...
r43346 venv_path = build_dir / (
'venv-%s-%s' % (build_name, 'x64' if vc_x64 else 'x86')
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
Augie Fackler
formatting: blacken the codebase...
r43346 gettext_root = build_dir / ('gettext-win-%s' % gettext_entry['version'])
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
if not gettext_root.exists():
extract_zip_to_directory(gettext_pkg, gettext_root)
extract_zip_to_directory(gettext_dep_pkg, gettext_root)
# This assumes Python 2. We don't need virtualenv on Python 3.
virtualenv_src_path = build_dir / (
Augie Fackler
formatting: blacken the codebase...
r43346 'virtualenv-%s' % virtualenv_entry['version']
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 virtualenv_py = virtualenv_src_path / 'virtualenv.py'
if not virtualenv_src_path.exists():
extract_tar_to_directory(virtualenv_pkg, build_dir)
py2exe_source_path = build_dir / ('py2exe-%s' % py2exe_entry['version'])
if not py2exe_source_path.exists():
extract_zip_to_directory(py2exe_pkg, build_dir)
if not venv_path.exists():
print('creating virtualenv with dependencies')
subprocess.run(
Augie Fackler
formatting: blacken the codebase...
r43346 [str(python_exe), str(virtualenv_py), str(venv_path)], check=True
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
venv_python = venv_path / 'Scripts' / 'python.exe'
venv_pip = venv_path / 'Scripts' / 'pip.exe'
Augie Fackler
formatting: blacken the codebase...
r43346 subprocess.run(
[str(venv_pip), 'install', '-r', str(venv_requirements_txt)], check=True
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
# Force distutils to use VC++ settings from environment, which was
# validated above.
env = dict(os.environ)
env['DISTUTILS_USE_SDK'] = '1'
env['MSSdk'] = '1'
Augie Fackler
wix: add a hook for a prebuild script to inject extra libraries...
r42214 if extra_packages_script:
Augie Fackler
formatting: blacken the codebase...
r43346 more_packages = set(
subprocess.check_output(extra_packages_script, cwd=build_dir)
.split(b'\0')[-1]
.strip()
.decode('utf-8')
.splitlines()
)
Augie Fackler
wix: add a hook for a prebuild script to inject extra libraries...
r42214 if more_packages:
if not extra_packages:
extra_packages = more_packages
else:
extra_packages |= more_packages
Gregory Szorc
setup: configure py2exe config via environment variables...
r42082 if extra_packages:
env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages))
Augie Fackler
py2exe: add workaround to allow bundling of hgext3rd.* extensions...
r42221 hgext3rd_extras = sorted(
Augie Fackler
formatting: blacken the codebase...
r43346 e for e in extra_packages if e.startswith('hgext3rd.')
)
Augie Fackler
py2exe: add workaround to allow bundling of hgext3rd.* extensions...
r42221 if hgext3rd_extras:
env['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'] = ' '.join(hgext3rd_extras)
Gregory Szorc
setup: configure py2exe config via environment variables...
r42082 if extra_excludes:
env['HG_PY2EXE_EXTRA_EXCLUDES'] = ' '.join(sorted(extra_excludes))
if extra_dll_excludes:
env['HG_PY2EXE_EXTRA_DLL_EXCLUDES'] = ' '.join(
Augie Fackler
formatting: blacken the codebase...
r43346 sorted(extra_dll_excludes)
)
Gregory Szorc
setup: configure py2exe config via environment variables...
r42082
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 py2exe_py_path = venv_path / 'Lib' / 'site-packages' / 'py2exe'
if not py2exe_py_path.exists():
print('building py2exe')
Augie Fackler
formatting: blacken the codebase...
r43346 subprocess.run(
[str(venv_python), 'setup.py', 'install'],
cwd=py2exe_source_path,
env=env,
check=True,
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
# Register location of msgfmt and other binaries.
env['PATH'] = '%s%s%s' % (
Augie Fackler
formatting: blacken the codebase...
r43346 env['PATH'],
os.pathsep,
str(gettext_root / 'bin'),
)
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081
print('building Mercurial')
subprocess.run(
Augie Fackler
formatting: blacken the codebase...
r43346 [str(venv_python), 'setup.py', 'py2exe', 'build_doc', '--html'],
Gregory Szorc
packaging: extract py2exe functionality to own module...
r42081 cwd=str(source_dir),
env=env,
Augie Fackler
formatting: blacken the codebase...
r43346 check=True,
)