adafruit / cookiecutter-adafruit-circuitpython

Cookiecutter template for Adafruit's CircuitPython libraries.
MIT License
22 stars 37 forks source link

jinja2.exceptions.TemplateSyntaxError: when running from msys2 (windows) #123

Closed ladyada closed 2 years ago

ladyada commented 3 years ago
$ cookiecutter gh:adafruit/cookiecutter-adafruit-circuitpython
You've downloaded C:/Users/ladyada/.cookiecutters/cookiecutter-adafruit-circuitpython before. Is it okay to delete and re-download it? [yes]:
Select target_bundle:
1 - Adafruit
2 - Community
Choose from 1, 2 [1]: 1
github_user [adafruit]:
author_name: ladyada
company [Adafruit Industries]:
library_name: NeoKey
library_description []: Python library for seesaw-based NeoKey boards
library_keywords []: python circuitpython neopixel seesaw mechanical keyboard
library_prefix [adafruit]:
adafruit_pid []: 4980
requires_bus_device []:
requires_register []:
other_requirements []: adafruit-circuitpython-seesaw
pypi_release [yes]:
sphinx_docs [yes]:
Select default_branch:
1 - master
2 - main
Choose from 1, 2 [1]: 2
Traceback (most recent call last):
  File "C:/msys64/mingw32/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:/msys64/mingw32/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:/msys64/mingw32/bin/cookiecutter.exe/__main__.py", line 7, in <module>
  File "C:/msys64/mingw32/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/cookiecutter/cli.py", line 140, in main
    cookiecutter(
  File "C:/msys64/mingw32/lib/python3.8/site-packages/cookiecutter/main.py", line 101, in cookiecutter
    result = generate_files(
  File "C:/msys64/mingw32/lib/python3.8/site-packages/cookiecutter/generate.py", line 272, in generate_files
    project_dir, output_directory_created = render_and_create_dir(
  File "C:/msys64/mingw32/lib/python3.8/site-packages/cookiecutter/generate.py", line 190, in render_and_create_dir
    name_tmpl = environment.from_string(dirname)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/jinja2/environment.py", line 941, in from_string
    return cls.from_code(self, self.compile(source), globals, None)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/jinja2/environment.py", line 638, in compile
    self.handle_exception(source=source_hint)
  File "C:/msys64/mingw32/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "C:/msys64/mingw32/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: unexpected char '\uf07c' at 67
lesamouraipourpre commented 3 years ago

I've just tried this with a fresh install of msys2 uname -a => MSYS_NT-10.0-19042 dolores 3.2.0-340.x86_64 2021-05-24 19:32 UTC x86_64 Msys and it runs without error:

$ cookiecutter gh:adafruit/cookiecutter-adafruit-circuitpython
You've downloaded /home/PC/.cookiecutters/cookiecutter-adafruit-circuitpython before. Is it okay to delete and re-download it? [yes]:
Select target_bundle:
1 - Adafruit
2 - Community
Choose from 1, 2 [1]:
github_user [adafruit]:
author_name: ladyada
company [Adafruit Industries]:
library_name: NeoKey
library_description []: Python library for seesaw-based NeoKey boards
library_keywords []: python circuitpython neopixel seesaw mechanical keyboard
library_prefix [adafruit]:
adafruit_pid []: 4980
requires_bus_device []:
requires_register []:
other_requirements []: adafruit-circuitpython-seesaw
pypi_release [yes]:
sphinx_docs [yes]:

python --version => Python 3.9.5

The unexpected char '\uf07c' is technically in the Private Use Area range : https://www.unicode.org/charts/PDF/UE000.pdf I've seen it listed as folder-open in a Font : https://fontawesome.com/v5.15/icons/folder-open?style=solid

Can you try again with an upgraded msys2 and see if it still gives an error?

lesamouraipourpre commented 3 years ago

The unexpected char '\uf07c' is technically in the Private Use Area range : https://www.unicode.org/charts/PDF/UE000.pdf I've seen it listed as folder-open in a Font : https://fontawesome.com/v5.15/icons/folder-open?style=solid

While reading through other issues, I've found the source of the '\uf07c'

Somehow the pipe character in the filename (not the best idea probably) somehow gets read as \uf07c which then of course is not correctly parsed.

Ref: https://github.com/cookiecutter/cookiecutter/issues/943

milador commented 3 years ago

I am running to similar issue on windows as well, any solution found yet?

    result = generate_files(
  File "c:\users\milador\appdata\local\programs\python\python39\lib\site-packages\cookiecutter\generate.py", line 272, in generate_files
    project_dir, output_directory_created = render_and_create_dir(
  File "c:\users\milador\appdata\local\programs\python\python39\lib\site-packages\cookiecutter\generate.py", line 190, in render_and_create_dir
    name_tmpl = environment.from_string(dirname)
  File "c:\users\milador\appdata\local\programs\python\python39\lib\site-packages\jinja2\environment.py", line 1092, in from_string
    return cls.from_code(self, self.compile(source), gs, None)
  File "c:\users\milador\appdata\local\programs\python\python39\lib\site-packages\jinja2\environment.py", line 757, in compile
    self.handle_exception(source=source_hint)
  File "c:\users\milador\appdata\local\programs\python\python39\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<unknown>", line 1, in template
jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got 'C'
jepler commented 2 years ago

The other issue I found was https://github.com/cookiecutter/cookiecutter/issues/1632 and https://github.com/cookiecutter/cookiecutter/issues/1636

One option we have is to switch to ansys-cookiecutter, fix any problems that arise due to the 2.x major version bump, and change our templates to use the workaround.

In any case, our CI should include "test that the cookie cutter works on Windows".

jepler commented 2 years ago

To try out the fix in #177: