Adrian Buehlmann committed 0a6502e

catch easy_install'ed global packages

If a package we want to include and build ourselves has also been preinstalled
globally (for example by using easy_install), the global package package may
override our own - which is unwanted.

This change prevents building a defective TortoiseHg installer that bundles
wrong versions of sub-packages.

The build is aborted for example with the error messages:

Error: 'C:\Python26_x64\lib\site-packages\iniparse-0.4-py2.6.egg\iniparse' overrides included package 'iniparse'
Error: 'C:\Python26_x64\lib\site-packages\dulwich-0.8.0-py2.6-win-amd64.egg\dulwich' overrides included package 'dulwich'
(uninstall or hide these installed packages: dulwich, iniparse)

Comments (0)

Files changed (1)

 from distutils.spawn import find_executable
+import distutils.sysconfig
 def set_syspath():
     # make sure we can use mercurial from python source
     hgrepodir = os.path.abspath('../hg')
 def verify_thg_env():
     global installenv
+    site_packages_path = distutils.sysconfig.get_python_lib()
+    included_packages = ('mercurial', 'iniparse', 'dulwich', 'keyring')
+    # 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)
         import comtypes
     except ImportError: