Only extend sys.path if needed self_initializing_hook
authorChristian Ebert <blacktrash@gmx.net>
Thu, 11 Jan 2007 02:22:56 +0100
branchself_initializing_hook
changeset 87 c193da9eb3e4
parent 86 790aa37e93aa
child 88 ffec227fced3
Only extend sys.path if needed
hgkw/keyword.py
--- a/hgkw/keyword.py	Wed Jan 10 18:52:09 2007 +0100
+++ b/hgkw/keyword.py	Thu Jan 11 02:22:56 2007 +0100
@@ -129,10 +129,16 @@
 
     filelog.filelog = kwfilelog
     repo.__class__ = kwrepo
-    # import keyword from pretxncommit hook even if it is not in hgext folder
-    sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
-    ui.setconfig('hooks', 'pretxncommit.keyword', 'python:%s.pretxnkw'
-            % os.path.splitext(os.path.basename(__file__))[0])
+    # make pretxncommit hook import kwmodule regardless of where it's located
+    moddir = os.path.abspath(os.path.dirname(__file__))
+    if os.path.dirname(moddir) in sys.path:
+        moddir = os.path.split(moddir)[1]+'.'
+    else:
+        sys.path.insert(0, moddir)
+        moddir = ''
+    ui.setconfig('hooks', 'pretxncommit.keyword', 'python:%s%s.pretxnkw'
+            % (moddir, os.path.splitext(os.path.basename(__file__))[0]))
+    del moddir
 
 
 def pretxnkw(ui, repo, hooktype, **args):