# HG changeset patch # User Christian Ebert # Date 1168508270 -3600 # Node ID ffec227fced32575de24cce4734b665081ce19e8 # Parent c193da9eb3e411fe46b5d92fa5ba15943083862d Module detection cleaner and more reliable Stolen from mercurial.lsprof diff -r c193da9eb3e4 -r ffec227fced3 hgkw/keyword.py --- a/hgkw/keyword.py Thu Jan 11 02:22:56 2007 +0100 +++ b/hgkw/keyword.py Thu Jan 11 10:37:50 2007 +0100 @@ -130,15 +130,19 @@ filelog.filelog = kwfilelog repo.__class__ = kwrepo # 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]+'.' + for k, v in sys.modules.iteritems(): + if v is None: + continue + if not hasattr(v, '__file__'): + continue + if v.__file__.startswith(__file__): + mod = k + break 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 + sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) + mod = os.path.splitext(os.path.basename(__file__))[0] + ui.setconfig('hooks', 'pretxncommit.keyword', 'python:%s.pretxnkw' % mod) + del mod def pretxnkw(ui, repo, hooktype, **args):