Adrian Buehlmann avatar 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)
+
     try:
         import comtypes
     except ImportError:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.