comparison mercurial/extensions.py @ 17217:1b2b727a885f

hooks: print out more information when loading a python hook fails When loading a python hook with file syntax fails, there is no information that this happened while loading a hook. When the python file does not exist even the file name is not printed. (Only that a file is missing.) This patch adds this information and a test for loading a non existing file and a directory not being a python module.
author Simon Heimberg <simohe@besonet.ch>
date Fri, 06 Jul 2012 18:41:25 +0200
parents 9eca39a91964
children 013fcd112f13
comparison
equal deleted inserted replaced
17216:01c1ee4bd1dd 17217:1b2b727a885f
40 # module/__init__.py style 40 # module/__init__.py style
41 d, f = os.path.split(path.rstrip('/')) 41 d, f = os.path.split(path.rstrip('/'))
42 fd, fpath, desc = imp.find_module(f, [d]) 42 fd, fpath, desc = imp.find_module(f, [d])
43 return imp.load_module(module_name, fd, fpath, desc) 43 return imp.load_module(module_name, fd, fpath, desc)
44 else: 44 else:
45 return imp.load_source(module_name, path) 45 try:
46 return imp.load_source(module_name, path)
47 except IOError, exc:
48 if not exc.filename:
49 exc.filename = path # python does not fill this
50 raise
46 51
47 def load(ui, name, path): 52 def load(ui, name, path):
48 # unused ui argument kept for backwards compatibility 53 # unused ui argument kept for backwards compatibility
49 if name.startswith('hgext.') or name.startswith('hgext/'): 54 if name.startswith('hgext.') or name.startswith('hgext/'):
50 shortname = name[6:] 55 shortname = name[6:]