[PATCH 5 of 6] packaging: add a check to ensure the source of Mercurial modules

3 views
Skip to first unread message

Matt Harbison

unread,
May 2, 2022, 7:04:48 PMMay 2
to thg...@googlegroups.com
# 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
--- a/contrib/packaging/thgpackaging/py2exe.py
+++ b/contrib/packaging/thgpackaging/py2exe.py
@@ -8,6 +8,7 @@

# no-check-code because Python 3 native.

+import distutils.sysconfig
import os
import pathlib
import shutil
@@ -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:
+ try:
+ mod = __import__(m)
+ except ImportError:
+ continue
+ fm = mod.__file__
+ if fm.lower().startswith(site_packages_path.lower()):
+ print(
+ "Error: '%s' overrides included package '%s'"
+ % (os.path.dirname(fm), m)
+ )
+ err.add(m)
+ if err:
+ print(
+ "(uninstall or hide these installed packages: %s)" % ', '.join(err)
+ )
+ sys.exit(1)
+
# Locate the HTML Help Workshop installation
if "PROGRAMW6432" in env:
programfiles_x86 = env.get("PROGRAMFILES(X86)")

Yuya Nishihara

unread,
May 2, 2022, 10:12:18 PMMay 2
to Matt Harbison, thg...@googlegroups.com
^^^^^^^^^^^^^
Changed to ['mercurial'] in flight.
Reply all
Reply to author
Forward
0 new messages