Skip to content

Commit

Permalink
Merge pull request #152 from chrisamin/master
Browse files Browse the repository at this point in the history
Only raise the 'No such command' exception if it's the actual command module that isn't found
  • Loading branch information
astrikos committed Mar 8, 2016
2 parents 700ad8a + 495db46 commit ebd167b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions scripts/ripe-atlas
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ class RipeAtlas(object):

self._setup_command()

try:
module = importlib.import_module(
"ripe.atlas.tools.commands.{}".format(self.command))

except ImportError:
raise RipeAtlasToolsException("No such command.")
module_name = "ripe.atlas.tools.commands.{}".format(self.command)

try:
module = importlib.import_module(module_name)

except ImportError as exc:
if hasattr(exc, "name"):
# Python 3.3+, exc.name will be the full module path
is_command_module = exc.name == module_name
else:
# Python 2.7, message will contain the final part of the path
is_command_module = exc.args[0].rsplit(
" ", 1)[-1] == self.command
if is_command_module:
raise RipeAtlasToolsException("No such command.")
else:
raise # We're missing a dependency
#
# If the imported module contains a `Factory` class, execute that
# to get the `cmd` we're going to use. Otherwise, we expect there
Expand Down

0 comments on commit ebd167b

Please sign in to comment.