[PATCH] hg script: remove current directory from sys.path (issue2557)
Dan Villiom Podlaski Christiansen
danchr at gmail.com
Thu Dec 16 14:24:07 CST 2010
# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1292530833 -3600
# Node ID 72f669c3f555295fb1fc7b7c73ae4053c69441fd
# Parent aae2d5cbde647da49fb1927d02faabfc37975c63
hg script: remove current directory from sys.path (issue2557)
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -13,6 +13,11 @@ import sys
libdir = '@LIBDIR@'
if libdir != '@' 'LIBDIR' '@':
+ # issue2557: remove current directory from path
+ if 'PYTHONPATH' in os.environ and '' in os.environ['PYTHONPATH'].split(':'):
+ curdir = os.path.abspath(os.curdir)
+ sys.path = [p for p in sys.path if p and p != curdir]
+
if not os.path.isabs(libdir):
libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
libdir)
diff --git a/tests/test-issue2557.t b/tests/test-issue2557.t
new file mode 100644
--- /dev/null
+++ b/tests/test-issue2557.t
@@ -0,0 +1,30 @@
+Script to create Python modules that raise an exception on import
+
+ $ mkfailures () {
+ > for arg in $*
+ > do
+ > echo 'raise Exception("Goodbye world!")' > $arg.py
+ > done
+ > }
+ $ hg init xxx
+ $ cd xxx
+
+Create modules with suspicious filenames
+
+ $ mkfailures cmdutil hg command dispatch
+
+Test that these modules don't conflict
+
+ $ hg diff
+ $ PYTHONPATH='' hg diff
+ $ PYTHONPATH=':' hg diff
+
+Create modules with even more suspicious filenames
+
+ $ mkfailures array signal socket termios struct
+
+Test that these modules don't conflict
+
+ $ hg diff
+ $ PYTHONPATH='' hg diff
+ $ PYTHONPATH=':' hg diff
More information about the Mercurial-devel
mailing list