pystache icon indicating copy to clipboard operation
pystache copied to clipboard

SyntaxError with Python 3.x

Open FRidh opened this issue 9 years ago • 10 comments

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

FRidh avatar Jan 23 '16 20:01 FRidh

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

jstasiak avatar Apr 14 '16 10:04 jstasiak

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.

ch3sn3k avatar Jul 28 '16 07:07 ch3sn3k

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

JaviBecerra avatar Dec 18 '17 16:12 JaviBecerra

I'm getting this same issue in Python 3.7.6

jgstew avatar Mar 10 '20 19:03 jgstew

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 avatar Apr 06 '20 20:04 nicktalb

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 avatar Apr 09 '20 08:04 nicktalb

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.

nicktalb avatar Apr 14 '20 10:04 nicktalb

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 avatar Sep 06 '21 10:09 c00kiemon5ter

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.

c00kiemon5ter avatar Sep 06 '21 12:09 c00kiemon5ter

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

bakert avatar Sep 19 '21 15:09 bakert