defunkt / pystache

Mustache in Python
http://mustache.github.com/
MIT License
1.31k stars 308 forks source link

SyntaxError with Python 3.x #181

Open FRidh opened 8 years ago

FRidh commented 8 years ago

Tested with python 3.4 and 3.5

Traceback (most recent call last):
  File "/nix/store/4fr5rgsizd5q72fr8lsixvb274awg6nk-python3-3.4.4/lib/python3.4/unittest/loader.py", line 323, in _find_tests
    module = self._get_module_from_name(name)
  File "/nix/store/4fr5rgsizd5q72fr8lsixvb274awg6nk-python3-3.4.4/lib/python3.4/unittest/loader.py", line 301, in _get_module_from_name
    __import__(name)
  File "/tmp/nix-build-python3.4-pystache-0.5.4.drv-0/pystache-0.5.4/test_pystache.py", line 20, in <module>
    from pystache.commands import test
  File "/tmp/nix-build-python3.4-pystache-0.5.4.drv-0/pystache-0.5.4/pystache/__init__.py", line 9, in <module>
    from pystache.init import parse, render, Renderer, TemplateSpec
  File "/tmp/nix-build-python3.4-pystache-0.5.4.drv-0/pystache-0.5.4/pystache/init.py", line 8, in <module>
    from pystache.parser import parse
  File "/tmp/nix-build-python3.4-pystache-0.5.4.drv-0/pystache-0.5.4/pystache/parser.py", line 15
    NON_BLANK_RE = re.compile(ur'^(.)', re.M)
                                     ^
SyntaxError: invalid syntax
jstasiak commented 8 years ago

I can't reproduce this, I have pystache 0.5.4 installed on Python 3.5.1 and it works.

ch3sn3k commented 8 years ago

I have the same issue. I am using Python '3.3.5 (default, Jun 15 2016, 19:45:40) [MSC v.1800 32 bit (Intel)]' installed in LibreOffice installation 5.1.4.2 (32bit) on Windows 7 (64bit). I just installed pip 6.1.1. and install pystache 0.5.4. After executionf the import pystache a get the same error.

JaviBecerra commented 6 years ago

Found the same issue with Python 3.6.3. Apparently pip did not update pystache code from Python 2 to Python 3 during installation (the SyntaxError initially reported stems from the invalid ur string specifier in Python 3). Solved running manually 2to3 on the pystache installation folder as per the installation instructions:

2to3 --write --nobackups --no-diffs site-packages\pystache

jgstew commented 4 years ago

I'm getting this same issue in Python 3.7.6

nicktalb commented 4 years ago

Same issue with Python 3.6.10, pip (both 18.1 and latest 20.0.2) and pystache 0.5.4. Didn't have the issue with 3.6.1.

nicktalb commented 4 years ago

This seems to be a problem with 2to3. When I run "python -m lib2to3" with Python 3.6.1 on the pystache site-packages directory I get a list of changes that would be made. When I run with Python 3.6.10 I simply get: RefactoringTool: No files need to be modified.

nicktalb commented 4 years ago

Problem went away when I removed this post-build step from our Python build:

# Pre-compile all .py files to .pyc and delete .py files
./bin/python3 -m compileall -bf .
find . -name "__pycache__" -type d -print0 | xargs -0 /bin/rm -rf
find . -name "*.py" -type f -print0 | xargs -0 /bin/rm -rf

I've not investigated why this caused the issue.

c00kiemon5ter commented 3 years ago

From the readme

Pystache is written in Python 2 and must be converted to Python 3 prior to using it with Python 3. The installation process (and tox) do this automatically.

It seems that the last working build is with pip 20.3.3. After that, the build step that compiles python2 code to python3 seems to be skipped. (see below, the real issue is setuptools)

From https://github.com/nicolargo/glances/issues/1793#issuecomment-765922759

it looks like it relies on lib2to3 to work in Python 3 and there are issues with 2to3 which is noted to be unstable with Python 3.9 and deprecated in 3.10

I am sorry to say that this signals that the project is indeed abandoned and people should look elsewhere - https://github.com/defunkt/pystache/pull/213

c00kiemon5ter commented 3 years ago

Scratch the above message. The actual reason the build is failing is not pip but setuptools.

From https://github.com/pypa/setuptools/blob/main/CHANGES.rst#v5800

v58.0.0

Breaking Changes

#2086: Removed support for 2to3 during builds. Projects should port to a unified codebase or pin to an older version of Setuptools using PEP 518 build-requires.

So, starting today, environments that pull in the new release of setuptools (v58 or later) will fail to build pystache.

bakert commented 3 years ago

I have forked pystache and dropped support for python2 in order to avoid this issue here – https://github.com/PennyDreadfulMTG/pystache