progrium/ginkgo — pull request #54 by hblanks (2012-04-26 02:07:35+00:00)
Title: ginkgo/runner.py: print traceback when import/key error occurs

This patch updates the ginkgo / ginkgoctl CLI's so that instead of:

[root@23.20.50.77][dev]# ginkgo ./deployment/collector.conf.py
Starting process with ./deployment/collector.conf.py...
usage: ginkgo [-v] [-h] [target]
ginkgo: error: Unable to load class path: blah.blah.foo:
No module named gar

You get:

[root@23.20.50.77][dev]# ginkgo ./deployment/collector.conf.py
Starting process with ./deployment/collector.conf.py...
usage: ginkgo [-v] [-h] [target]
ginkgo: error: Unable to load class path: blah.blah.foo:
No module named gar

Traceback (most recent call last):
File "/home/hunter/ginkgo/ginkgo/runner.py", line 98, in load_class
module = runpy.run_module(module_name + ".__init__")
File "/usr/local/python-2.7/lib/python2.7/runpy.py", line 170, in run_module
mod_name, loader, code, fname = _get_module_details(mod_name)
File "/usr/local/python-2.7/lib/python2.7/runpy.py", line 101, in _get_module_details
loader = get_loader(mod_name)
File "/usr/local/python-2.7/lib/python2.7/pkgutil.py", line 456, in get_loader
return find_loader(fullname)
File "/usr/local/python-2.7/lib/python2.7/pkgutil.py", line 466, in find_loader
for importer in iter_importers(fullname):
File "/usr/local/python-2.7/lib/python2.7/pkgutil.py", line 422, in iter_importers
__import__(pkg)
... <- your code here!
ImportError: No module named gar

In a sense, it'd be kind of nice if we didn't use argparse.error()
for cases like this, when the issue is not an invalid argument on
the command line, but rather a bug in the user's underlying ginkgo
service.