Version 5 (modified by athomas, 10 years ago) (diff)


Migrating Trac macros from 0.8.x to 0.9.x


Global macros are now stored in ${prefix}/share/trac/wiki-macros instead of ${prefix}/pythonX.Y/site-packages/trac/wiki-macros.

Global macros are not implicitly loaded. After installing a macro into the global macro directory a trac-admin <env> upgrade must be performed, which will copy the macro into the environments <env>/wiki-macros directory. Unfortunately, trac does not appear to detect outdated macros and will not upgrade existing macros to newer versions. You will need to manually delete the copies of the global macros in each environment, then perform an environment upgrade. With mod_python, as always, this will require an apache restart.


If your macro needs to preserve state across an entire page render, place the state variables into the hdf object.


Due to Trac #1562, there is seemingly no way to pass dynamic variables to reports apart from using a fully qualified link. For example, in a perfect world this would work. This feature did work in 0.8.

API Changes

Several classes and functions used frequently in macros have changed. This table outlines some of those that I came across while migrating my macros to the 0.9.x object hierarchy:

0.8.xEquivalent in 0.9.x
trac.WikiFormatter.wiki_to_oneliner(wikitext, hdf, env, db,absurls=0), env, db=None, absurls=0)
trac.WikiFormatter.wiki_to_html(wikitext, hdf, env, db, absurls=0), env, req, db=None, absurls=0, escape_newlines=False) 1

  1. 1. If you wish to use wiki_to_html with content that itself contains macro's, you will need to create a full plugin. This seems to be because the hdf macro argument is extracted from the req object in the sub-macro.