I embedded Mako in WHIFF
(
http://whiffdoc.appspot.com/docs/W1100_1075.MakoGrading)
and it works very nicely, as long as it doesn't try to do a
relative module import.
In particular when I include a Mako template
in a WHIFF directory I would like relative
imports in the embedded Python code to
import any code file that matches in the same directory.
For example here is a fragment of a Mako
template (from an embedding in a WHIFF template)
in the directory ~/whiff/test/misc/
...
<%
# inlined python to summarize text
import shaney
text = text.strip()
if text:
do something using shaney....
else:
do something else....
%>
Here the "import shaney" I think should import
the ~/whiff/test/misc/shaney.py module in the same directory as the
template file, but instead I get an ImportError:
/Users/Aaron/work/whiff/test/root/memory:0x106b590 in
render_body(context=<mako.runtime.Context object at 0x114ef70>,
**pageargs={})
<type 'exceptions.ImportError'>: ./misc/summarize.whiff :: No module
named shaney
I haven't tested it outside of WHIFF, but this may happen
inside WHIFF because the template is passed many levels
down before it gets processed in the WHIFF configuration.
Is there any reasonable way to get the import to work
the way I expect it to work? (I don't think modifying sys.path
for this special purpose is very reasonable.) Somehow I need
to tell the evaluator "pretend you are living in this directory: a/b/
c"
so it finds the right file/module to import...
Let me know what you suggest, or any other comments.
Thanks! -- Aaron Watters
===
$ man less
less is more
--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To post to this group, send email to
mako-d...@googlegroups.com.
To unsubscribe from this group, send email to
mako-discuss...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mako-discuss?hl=en.