# HG changeset patch # User Gregory Szorc # Date 2019-03-07 20:15:32 # Node ID 260305e8ddbdb7940d0ab158a8d2d318cd712827 # Parent a2e191a937a9e1582dfb37bb48788f6755d10895 setup: configure py2exe config via environment variables The Inno Setup and WiX installers ship a different set of packages with py2exe builds. And there are multiple WiX installer variants (e.g. TortoiseHG). Since there are multiple variants of py2exe configs and they can be defined by entities not in our repository, let's provide a mechanism for setup.py to supplement behavior via environment variables. This is slighly less hacky than a setup.cfg file IMO since the caller doesn't need to worry about mutating global state of the source directory. Differential Revision: https://phab.mercurial-scm.org/D6092 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 @@ -20,6 +20,14 @@ from .util import ( ) +EXTRA_PACKAGES = { + 'dulwich', + 'keyring', + 'pygments', + 'win32ctypes', +} + + def build(source_dir: pathlib.Path, build_dir: pathlib.Path, python_exe: pathlib.Path, iscc_exe: pathlib.Path, version=None): @@ -40,7 +48,7 @@ def build(source_dir: pathlib.Path, buil 'inno' / 'requirements.txt') build_py2exe(source_dir, build_dir, python_exe, 'inno', - requirements_txt) + requirements_txt, extra_packages=EXTRA_PACKAGES) # hg.exe depends on VC9 runtime DLLs. Copy those into place. for f in find_vc_runtime_files(vc_x64): diff --git a/contrib/packaging/hgpackaging/py2exe.py b/contrib/packaging/hgpackaging/py2exe.py --- a/contrib/packaging/hgpackaging/py2exe.py +++ b/contrib/packaging/hgpackaging/py2exe.py @@ -23,7 +23,9 @@ from .util import ( def build_py2exe(source_dir: pathlib.Path, build_dir: pathlib.Path, python_exe: pathlib.Path, build_name: str, - venv_requirements_txt: pathlib.Path): + venv_requirements_txt: pathlib.Path, + extra_packages=None, extra_excludes=None, + extra_dll_excludes=None): """Build Mercurial with py2exe. Build files will be placed in ``build_dir``. @@ -103,6 +105,14 @@ def build_py2exe(source_dir: pathlib.Pat env['DISTUTILS_USE_SDK'] = '1' env['MSSdk'] = '1' + if extra_packages: + env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages)) + if extra_excludes: + env['HG_PY2EXE_EXTRA_EXCLUDES'] = ' '.join(sorted(extra_excludes)) + if extra_dll_excludes: + env['HG_PY2EXE_EXTRA_DLL_EXCLUDES'] = ' '.join( + sorted(extra_dll_excludes)) + py2exe_py_path = venv_path / 'Lib' / 'site-packages' / 'py2exe' if not py2exe_py_path.exists(): print('building py2exe') diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1251,6 +1251,9 @@ py2exepackages = [ 'mercurial.pure', ] +py2exeexcludes = [] +py2exedllexcludes = [] + if issetuptools: extra['python_requires'] = supportedpy @@ -1264,33 +1267,20 @@ if py2exeloaded: # put dlls in sub directory so that they won't pollute PATH extra['zipfile'] = 'lib/library.zip' - try: - import dulwich - dulwich.__version__ - py2exepackages.append('dulwich') - except ImportError: - pass - - try: - import keyring - keyring.util - py2exepackages.append('keyring') - except ImportError: - pass + # We allow some configuration to be supplemented via environment + # variables. This is better than setup.cfg files because it allows + # supplementing configs instead of replacing them. + extrapackages = os.environ.get('HG_PY2EXE_EXTRA_PACKAGES') + if extrapackages: + py2exepackages.extend(extrapackages.split(' ')) - try: - import pygments - pygments.__version__ - py2exepackages.append('pygments') - except ImportError: - pass + excludes = os.environ.get('HG_PY2EXE_EXTRA_EXCLUDES') + if excludes: + py2exeexcludes.extend(excludes.split(' ')) - try: - import win32ctypes - win32ctypes.__version__ - py2exepackages.append('win32ctypes') - except ImportError: - pass + dllexcludes = os.environ.get('HG_PY2EXE_EXTRA_DLL_EXCLUDES') + if dllexcludes: + py2exedllexcludes.extend(dllexcludes.split(' ')) if os.name == 'nt': # Windows binary file versions for exe/dll files must have the @@ -1371,6 +1361,8 @@ setup(name='mercurial', distclass=hgdist, options={ 'py2exe': { + 'dll_excludes': py2exedllexcludes, + 'excludes': py2exeexcludes, 'packages': py2exepackages, }, 'bdist_mpkg': {