summaryrefslogtreecommitdiff
path: root/scheme2rst.py
diff options
context:
space:
mode:
Diffstat (limited to 'scheme2rst.py')
-rw-r--r--scheme2rst.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/scheme2rst.py b/scheme2rst.py
index 4aa0a37..ad45337 100644
--- a/scheme2rst.py
+++ b/scheme2rst.py
@@ -12,6 +12,15 @@ SNIPPET = re.compile(r'\n;\s*([-A-Z\d_/!\?]+)\s*\n(.*?)\n\s*;END', re.DOTALL)
SNIPPETNAME = re.compile(r'\n\$\$([-A-Z\d_/!\?]+)\n')
INCLUDE = re.compile(r'@@([-\w\d_\.]+)')
+PATH = os.environ['IKARUS_LIBRARY_PATH']
+
+def include(fname):
+ try:
+ txt = file(fname).read()
+ except IOError:
+ txt = file(os.path.join(PATH, fname)).read()
+ return txt
+
def indent(text):
return '\n'.join(' ' + ln for ln in text.splitlines())
@@ -30,7 +39,7 @@ def scheme2rst(fname, codeblock=False):
name = mo.group(1)
return templ % indent(snippet[name])
def include_file(mo):
- return templ % indent(file(mo.group(1)).read())
+ return templ % indent(include(mo.group(1)))
rst = INCLUDE.sub(include_file, SNIPPETNAME.sub(repl, text))
rstfile = os.path.splitext(fname)[0] + '.rst'
file(rstfile, 'w').write(rst)