# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com
# Date 1651523847 14400
# Mon May 02 16:37:27 2022 -0400
# Node ID 4558a46f5216cb06632190c22e17e9bc89b38722
# Parent c4005eaf652ffa264a90e297e20cdbebe00d77ad
# EXP-Topic windows-py3-packaging
packaging: add a check to ensure the source of Mercurial modules
This is a carryover from the winbuild repo, which ends up checking that the
imported module doesn't come from the root `venv-packaging` environment. The
check in the winbuild repo also looks for `iniparse`, `keyring`, `hg-git`, and
`hgsubversion`, but we'll take those from the `venv-wix-x*` venvs.
Honestly, IDK if this is needed now that there are controlled venv based builds,
but I did manage to trigger it when I was messing with `PYTHONPATH` or the
`MERCURIAL_PATH`/`HGEXT_PATH`, so I ported it for a safety factor.
diff --git a/contrib/packaging/thgpackaging/py2exe.py b/contrib/packaging/thgpackaging/py2exe.py
@@ -8,6 +8,7 @@
# no-check-code because Python 3 native.
@@ -80,6 +81,31 @@
env["HGPLAIN"] = "1"
env["HGRCPATH"] = ""
+ site_packages_path = distutils.sysconfig.get_python_lib()
+ included_packages = ('mercurial')
+ # make sure that packages globally installed with e.g. easy_install
+ # don't override packages we want to bundle and build ourselves
+ err = set()
+ for m in included_packages:
+ mod = __import__(m)
+ except ImportError:
+ fm = mod.__file__
+ if fm.lower().startswith(site_packages_path.lower()):
+ "Error: '%s' overrides included package '%s'"
+ % (os.path.dirname(fm), m)
+ if err:
+ "(uninstall or hide these installed packages: %s)" % ', '.join(err)
# Locate the HTML Help Workshop installation
if "PROGRAMW6432" in env:
programfiles_x86 = env.get("PROGRAMFILES(X86)")