1. Andrey Vlasovskikh
  2. obraz
  3. Issues
Issue #7 resolved

Can't add attributes after 0.3

Brent Huisman
created an issue

I have a few plugins that add an attribute to a page which I later on use.

The plugins load fine, but during the processing stage Python generates an error for each missing attribute (any that I added with my plugins). Here's what used to work in 0.2:

for post in site.get('posts', []):
        post['custom_sort_key'] = "this or that"

And then in some page or layout:


What changed?

Comments (15)

  1. Andrey Vlasovskikh repo owner

    This actually should work in 0.3 as well as in 0.2. Please share your plugin code (you can email me (the address is in the commit messages) if it is more convenient for you. I will certainly try to help you.

  2. Andrey Vlasovskikh repo owner

    I guess you are using the latest version from the repository, not 0.3?

    Has your plugin been actually executed? Place some invalid code in process_sortmeister() and check the output for stack traces. You can also print debug info in your plugins to sys.stderr.

    Note, that test/test_obraz.py contains a test named test_plugins() that actually adds an attribute to a page. You can take a look at it.

    FYI, I've just pushed a commit for printing more info if an exception in a processor function occurs.

  3. Brent Huisman reporter

    The description of the plugin is not printed anymore, does that count as a verification of it not actually loading?

    I grabbed the latest from your repo just now, but I see no new errors. The error I get originates in yaml, and complains about the missing attribute:

    Error when generating page /index.html: 'dict object' has no attribute 'relpath'
    Traceback (most recent call last):
  4. Andrey Vlasovskikh repo owner

    The new scheme of explicitly importing the obraz in plugins is broken. The imported module object may differ from the module you run from the command line if there is no explicit import in your command line script (e. g. if you are running python obraz.py /path/to/file instead of pip install obraz and obraz /path/to/file).

    Possible solutions in Obraz itself:

    • Return to the old implicit scheme of injecting obraz into the plugin's namespace
    • Check before importing if the obraz module has been already loaded into the modules cache (assert sys.modules.get('obraz') is not None)

    Any alternative proposals?

    As a workaround, please use the released version 0.3 with the old plugin interface.

  5. Andrey Vlasovskikh repo owner

    Brent, thanks for your bug report! I need more feedback on Obraz in order to drive its development further. The core values (Jekyll compatibility, < 500 lines of Python) will remain untouched, but any other ideas are welcome :)

  6. Brent Huisman reporter

    I was indeed using obraz.py locally, so I ran it with "python obraz.py ." All works perfectly now with .3, thanks!

    By the way, as you saw I have written a few plugins for obraz. As I don't use mercurial I havn't been able to give a pull request, but I you want to store them in your repo, go ahead! And you could add huisman.tk to the obraz users list.

    I have one more question, if I may. I want to use the new template_filters, because there is a regex I want to apply on all final generated pages. I see however no way of adding such a template without editing obraz.py, is that correct?

  7. Andrey Vlasovskikh repo owner

    Yes, I'll definitely add a link to your site. Are its sources available?

    Note, that I will change extension points for template rendering including template_fitlers in the near future. I don't quite get what are you trying to achieve with template_filters. Could you describe your example in more detail?

  8. Brent Huisman reporter

    Yes, I suppose so (I havn't tried, I'm lazy :P). But if at all possible I prefer to not edit obraz.py, just to make it easier to upgrade. If you want to include it permanently however, I can give it a go and post back.

  9. Log in to comment