pfalcon / utemplate

Micro template engine in Python with low memory usage, designed for Pycopy, a minimalist Python dialect, but also compatible with other Pythons.
https://github.com/pfalcon/pycopy
76 stars 8 forks source link

Cannot run include.tpl #3

Closed cefn closed 7 years ago

cefn commented 7 years ago

Was trying to test out some include logic. I can successfully run the more complex test...

$ python3 ./utemplate_util.py run examples/test1.tpl "something" "else"

...but if I try to run "include.tpl" it triggers this error...

$ python3 ./utemplate_util.py run examples/include.tpl 
Traceback (most recent call last):
  File "./utemplate_util.py", line 45, in <module>
    c.compile()
  File "/home/cefn/Documents/shrimping/git/utemplate/utemplate/source.py", line 128, in compile
    self.parse_line(l)
  File "/home/cefn/Documents/shrimping/git/utemplate/utemplate/source.py", line 105, in parse_line
    self.parse_statement(stmt)
  File "/home/cefn/Documents/shrimping/git/utemplate/utemplate/source.py", line 61, in parse_statement
    with open(self.loader.file_path(tokens[0][1:-1])) as inc:
AttributeError: 'NoneType' object has no attribute 'file_path'

What is the proper invocation of a template which might draw upon the loader argument?

P.S. Probably not related, but trying to use the compile or render commands create different errors...

$ python3 ./utemplate_util.py compile examples/include.tpl 
Traceback (most recent call last):
  File "./utemplate_util.py", line 33, in <module>
    render = loader.load(sys.argv[2])
  File "/home/cefn/Documents/shrimping/git/utemplate/utemplate/source.py", line 163, in load
    return super().load(name)
  File "/home/cefn/Documents/shrimping/git/utemplate/utemplate/compiled.py", line 13, in load
    return __import__(self.p + name, None, None, (name,)).render
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 896, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1148, in find_spec
  File "<frozen importlib._bootstrap_external>", line 947, in __init__
  File "<frozen importlib._bootstrap_external>", line 962, in _get_parent_path
KeyError: ''
$ python3 ./utemplate_util.py render examples/include.tpl 
Traceback (most recent call last):
  File "./utemplate_util.py", line 37, in <module>
    render = loader.load(sys.argv[2])
  File "/home/cefn/Documents/shrimping/git/utemplate/utemplate/compiled.py", line 13, in load
    return __import__(self.p + name, None, None, (name,)).render
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 896, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1148, in find_spec
  File "<frozen importlib._bootstrap_external>", line 947, in __init__
  File "<frozen importlib._bootstrap_external>", line 962, in _get_parent_path
KeyError: ''
pfalcon commented 7 years ago

Kinda fixed now.