weaveworks/grafanalib

README example doesn't work

mongrelion opened this issue · 4 comments

When trying to generate the output for the example in the README file I get a NameError: name 'Alert' is not defined error.

generate-dashboard -o frontend.json frontend.dashboard.py
Traceback (most recent call last):
  File "/usr/local/bin/generate-dashboard", line 11, in <module>
    sys.exit(generate_dashboard_script())
  File "/usr/local/lib/python3.4/site-packages/grafanalib/_gen.py", line 108, in generate_dashboard_script
    run_script(generate_dashboard)
  File "/usr/local/lib/python3.4/site-packages/grafanalib/_gen.py", line 98, in run_script
    sys.exit(f(sys.argv[1:]))
  File "/usr/local/lib/python3.4/site-packages/grafanalib/_gen.py", line 85, in generate_dashboard
    dashboard = load_dashboard(opts.dashboard)
  File "/usr/local/lib/python3.4/site-packages/grafanalib/_gen.py", line 18, in load_dashboard
    module = SourceFileLoader("dashboard", path).load_module()
  File "<frozen importlib._bootstrap>", line 539, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1614, in load_module
  File "<frozen importlib._bootstrap>", line 596, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/opt/code/frontend.dashboard.py", line 44, in <module>
    alert=Alert(
NameError: name 'Alert' is not defined

System

Python 3.4.6
pip 9.0.1 from /usr/local/lib/python3.4/site-packages (python 3.4)
grafanalib 0.1.2
Linux 7ccfd83caf20 4.9.27-moby #1 SMP Thu May 11 04:01:18 UTC 2017 x86_64 Linux

Ok so I found out the issue: the documentation is a little out of date. For installing grafanalib, it suggests doing so with pip install grafanalib, which will install version 0.1.2 but this version does not yet support all the stuff that is presented in the README file.
We should either release a new version that is up to date with master and so that pip can pick those changes up or update the documentation so that the example that is exposed there actually works.

jml commented

We should absolutely release a new version. In the mean time, I'll update the README to add a warning that the example works with master and not the latest release.

jml commented

Done.

jml commented

I think this has been resolved. Please let me know if not.