Python 3.9
Hey there,
Seems not to run on python 3.9:
$ python benchmark.py
Traceback (most recent call last):
File "/home/ybon/Code/py/cinje/example/benchmark.py", line 445, in <module>
import bigtable
File "/home/ybon/Code/py/cinje/example/bigtable.py", line 106
__gzmapping__ = b"eJxjYGJkAANGMEBmMDAxMTAjCWETAwsRlmBgAAAPKwBL"
^
SyntaxError: unexpected EOF while parsing
or am I missing something ?
Thanks :)
Unfortunately, Python doesn't always emit the most helpful error messages when it comes to syntax errors such as unterminated constants, as that's just pointing at the end of the generated file.
To get a clearer picture of how Python sees your template, run: python3 -m cinje source source.py
E.g. from one of my own API service projects: python3 -m cinje source web/app/sanitize/template.py
If you have Pygments installed, the output will be pretty and syntax-colored when emitting to a terminal.
web/app/sanitize/template.py raw source
# encoding: cinje
: def page content="", result=""
<!DOCTYPE html>
<title>Demonstration Interface</title>
<style>
html, body { height: 100%; padding: 0; margin: 0; font-size: 14px; font-family: sans-serif; line-height: 1; }
…
</style>
<textarea id="origin" placeholder="Enter your source markup here.">${content}</textarea>
<main id="target">${result}</main>
<button id="sanitize">Sanitize</button>
web/app/sanitize/template.py as seen by Python
import cinje
from cinje.helpers import escape as _escape, bless as _bless, iterate, xmlargs as _args, _interrupt, _json
__tmpl__ = [] # Exported template functions.
def page(content="", result="", *, _escape=_escape, _bless=_bless, _args=_args):
_buffer = []
__w, __ws = _buffer.extend, _buffer.append
__w(('<!DOCTYPE html>\n',
'<title>Demonstration Interface</title>\n',
'\n',
'<style>\n',
'html, body { height: 100%; padding: 0; margin: 0; font-size: 14px; font-family: sans-serif; line-height: 1; }\n',
'…',
'</style>\n',
'\n',
'<textarea id="origin" placeholder="Enter your source markup here.">',
_escape(content),
'</textarea>\n',
'<main id="target">',
_escape(result),
'</main>\n',
'<button id="sanitize">Sanitize</button>\n'))
yield "".join(_buffer)
__tmpl__.extend(["page"])
__mapping__ = [0,2,2,2,2,2,2,2,3,3,3,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,23,23,24,24,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,42,42,42]
__gzmapping__ = b"eJxjYGIAA0YQxgLAMtiEGQAEsQAr"
If you could Gist your source template, that'd greatly assist with debugging. 🙂 ~~The likely culprit is an unterminated string much earlier in your code.~~
Updated to include raw source of sample template. Additionally, I have been able to reproduce locally and am investigating myself.
Minimal Test Case
Environment Preparation
python3.9 -m venv sandbox
cd ./sandbox; . bin/activate
pip3 install cinje
minimal.py
"This page intentionally left blank."
# encoding: cinje
Invocation Results
python -m cinje source minimal.py
Traceback (most recent call last):
File "/usr/local/Cellar/[email protected]/3.9.2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/Cellar/[email protected]/3.9.2/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/amcgregor/Projects/sandbox/lib/python3.9/site-packages/cinje/__main__.py", line 92, in <module>
interface.go(*interface.args, **interface.kwargs)
File "/Users/amcgregor/Projects/sandbox/lib/python3.9/site-packages/cinje/__main__.py", line 26, in go
result = action(*args, **data)
File "/Users/amcgregor/Projects/sandbox/lib/python3.9/site-packages/cinje/__main__.py", line 60, in source
result = self._source_reference(file)
File "/Users/amcgregor/Projects/sandbox/lib/python3.9/site-packages/cinje/__main__.py", line 76, in _source_reference
root = __import__(reference)
File "/Users/amcgregor/Projects/sandbox/minimal.py", line 11
__gzmapping__ = b"eJxjYGJkAAMAACAABA=="
^
SyntaxError: unexpected EOF while parsing
However, if the "empty" source file is read in, and run through the Unicode decoder, correctly translated source is produced:
minimal-translated.py
import cinje
from cinje.helpers import escape as _escape, bless as _bless, iterate, xmlargs as _args, _interrupt, _json
__tmpl__ = [] # Exported template functions.
__mapping__ = [0,2,3,3,3,3,3,3,3]
__gzmapping__ = b"eJxjYGJkAAMAACAABA=="
Written to a distinct file, this module imports perfectly fine.