Context: simplify waf tool loading error handling

- Assuming that an exception could have been raised, the worst thing
  we do is presenting the wrong exception to the user.
- Actually, the exception is more precise now:

  - if we want to load('pouet'), the error will always be::

      ``No module named pouet``.

  - if we want to load('pouet.coin') the error will always be::

      ``No module named pouet.coin``

    Before it could be either::

      ``No module named pouet.coin``

    or::

      ``No module named coin``
This commit is contained in:
Jérôme Carretero 2013-08-14 11:30:38 -04:00
parent 5db6202ce1
commit 8c2c8f1615
1 changed files with 4 additions and 10 deletions

View File

@ -619,18 +619,12 @@ def load_tool(tool, tooldir=None):
for d in tooldir:
sys.path.remove(d)
else:
for x in ('waflib.extras.%s', 'waflib.Tools.%s', 'waflib.%s', '%s'):
full = x % tool
for x in ('waflib.Tools.%s', 'waflib.extras.%s', 'waflib.%s', '%s'):
try:
__import__(full)
__import__(x % tool)
break
except ImportError as e:
if e.args[0].endswith(tool):
x = None
elif e.args[0].endswith("'%s'" % full):
x = None
else:
raise
except ImportError:
x = None
if x is None: # raise an exception
__import__(tool)
ret = sys.modules[x % tool]