Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ladyada opened this issue Apr 4, 2021 · 5 comments · Fixed by #177
Closed

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

ladyada opened this issue Apr 4, 2021 · 5 comments · Fixed by #177

Comments

@ladyada
Copy link
Member

ladyada commented Apr 4, 2021

$ 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
Copy link
Contributor

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
Copy link
Contributor

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: cookiecutter/cookiecutter#943

@milador
Copy link

milador commented Jul 13, 2021

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
Copy link
Member

jepler commented Mar 28, 2022

The other issue I found was cookiecutter/cookiecutter#1632 and cookiecutter/cookiecutter#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
Copy link
Member

jepler commented Mar 28, 2022

To try out the fix in #177:

  • Install the 2.0.2 version of cookiecutter in either of these two ways: pip install cookiecutter@https://github.com/cookiecutter/cookiecutter/archive/2.0.2.zip or pip install ansys-cookiecutter
  • Run cookiecutter as follows: cookiecutter https://github.com/jepler/cookiecutter-adafruit-circuitpython/archive/refs/heads/ansys-cookiecutter.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants