- commit
- f2e4765a94b21680d3855644f665d43b4dc7d7ca
- parent
- e38d6e2378914b956affc3cc3948e983ee384616
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2022-08-27 08:42
allow to include xipd files from package
Diffstat
| M | test/test.xipd | 2 | +- |
| M | xipd/renderer.py | 10 | +++++++++- |
2 files changed, 10 insertions, 2 deletions
diff --git a/test/test.xipd b/test/test.xipd
@@ -1,4 +1,4 @@1 -1 include "../std.xipd"-1 1 include "std.xipd" 2 2 3 3 osc(node, freq) { 4 4 freq -> node
diff --git a/xipd/renderer.py b/xipd/renderer.py
@@ -9,6 +9,14 @@ def abspath(path, start): 9 9 return os.path.normpath(joined) 10 10 11 11 -1 12 def find_include(path, start): -1 13 p = abspath(path, start) -1 14 if os.path.exists(p): -1 15 return p -1 16 else: -1 17 return abspath(path, __file__) -1 18 -1 19 12 20 class Scope: 13 21 def __init__(self, parent=None): 14 22 self.parent = parent @@ -97,7 +105,7 @@ class Renderer: 97 105 def render_with_scope(self, ast, scope, path): 98 106 for stmt in ast: 99 107 if stmt[0] == 'include':100 -1 _path = abspath(stmt[1], path)-1 108 _path = find_include(stmt[1], path) 101 109 with open(_path) as fh: 102 110 ast = self.parser.parse_file(fh) 103 111 self.render_with_scope(ast, scope, _path)