Skip to content

Commit 431d898

Browse files
committed
fix module-relative imports in rendered .py templates
1 parent c23ab5f commit 431d898

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

scripts/cfn

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ def render_python_template(file):
3737
# just capture sys.stdout.
3838

3939
from cStringIO import StringIO
40-
import sys
40+
import os
4141
import runpy
42+
import sys
4243

4344
capture = StringIO()
45+
orig_path = sys.path
4446

4547
try:
48+
sys.path = sys.path[:]
49+
sys.path[0] = os.path.dirname(file)
4650
sys.stdout = capture
4751
runpy.run_path(file)
4852
finally:
4953
sys.stdout = sys.__stdout__
54+
sys.path = orig_path
5055
res = capture.getvalue()
5156
capture.close()
5257

0 commit comments

Comments
 (0)