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

Import from past causes traceback #209

Open
gazpachoking opened this issue Apr 26, 2016 · 8 comments
Open

Import from past causes traceback #209

gazpachoking opened this issue Apr 26, 2016 · 8 comments

Comments

@gazpachoking
Copy link
Contributor

There seems to be an issue (on some python installations) when importing from the past package. One of our users is reporting this traceback:

from past.builtins import basestring
File "/usr/lib/python2.7/site-packages/past/__init__.py", line 88, in 
from past.translation import install_hooks as autotranslate
File "/usr/lib/python2.7/site-packages/past/translation/__init__.py", line 41, in 
from lib2to3.pgen2.parse import ParseError
ImportError: No module named lib2to3.pgen2.parse

Any ideas what's going on here? Downstream ticket, for referece: Flexget/Flexget#1093

@jayvdb
Copy link

jayvdb commented Apr 26, 2016

the only time i see this type of problem is when an ImportError is caught and ignored, and them the same name is imported again somewhere else afterwards

@stevezau
Copy link

Hi @jayvdb can you eloborate on that a little bit more? An importerror relating to python future??

@stevezau
Copy link

stevezau commented May 1, 2016

@jayvdb this error is thrown on NAS type devices as they won't have 2to3 compiled into python2..

Is it possible to maybe check for the existance for lib2to3 via a try catch block and disable the functions that use it if it does not exist?

@msj33
Copy link

msj33 commented May 1, 2016

Yes, can we please reopen this - lib2to3 is clearly broken on NAS/Router devices.

@gazpachoking
Copy link
Contributor Author

Is it possible to maybe check for the existance for lib2to3 via a try catch block and disable the functions that use it if it does not exist?

This seems like a good idea to me. Can someone comment on what these imports are actually doing? We are getting more reports of users that do not have the lib2to3 in their stdlib.

@programatix
Copy link

programatix commented May 10, 2016

Hi,

I just received a reply on my question on lib2to3 over at Entware/Entware-ng#268 (comment). I believe the answer actually state that lib2to3 is not built into our python is because it's version 2. In my case, it's version 2.7. lib2to3 is a module which convert python 2 script to python 3 automatically (https://docs.python.org/2.7/library/2to3.html). So, it make sense that our python 2 doesn't include lib2to3.

From what I see, by requiring lib2to3, you guys are removing support for python 2 automatically. Wasn't the purpose of lib2to3 is to support python 2 script in python 3? So, shouldn't a version check be done before importing lib2to3? Something like this perhaps?

if sys.version_info >= (3, 0):
    from lib2to3.pgen2.parse import ParseError

Btw, I'm not a python coder, so the above code is just my assumption.

@edschofield
Copy link
Contributor

Thanks for reporting this, Chase!

@programatix : lib2to3 is a standard package on Python 2 systems.

@gazpachoking, @stevezau: Yes, it would be possible for the past.translation package to provide an alternative autotranslate() method that raises an ImportError on some NAS-type devices that don't seem to install lib2to3. If one of you would like to contribute a pull request, I can aim to incorporate it in the next version of future (v0.16).

@blubberdiblub
Copy link

For reference, as pyglet fails to run under Python 3.6 due to this problem, I worked around it using the following change in past/translation/__init__.py (in addition to commenting out the import in line 2 in libfuturize/fixes/__init__.py):

--- past/translation/__init__.py.orig	2017-09-24 08:23:47.646644743 +0200
+++ past/translation/__init__.py	2018-01-01 10:31:36.584576652 +0100
@@ -38,8 +38,32 @@
 import os
 import sys
 import copy
-from lib2to3.pgen2.parse import ParseError
-from lib2to3.refactor import RefactoringTool
+
+try:
+    from lib2to3.pgen2.parse import ParseError
+
+except ImportError:
+
+    class ParseError(SyntaxError):
+        pass
+
+try:
+    from lib2to3.refactor import RefactoringTool
+
+except ImportError:
+
+    class RefactoringTool:
+
+        def __init__(self, *args, **kwargs):
+            self._args = [repr(a) for a in args]
+            self._args += ["{}={!r}".format(k, v) for k, v in kwargs.items()]
+
+        def __repr__(self):
+            return "{}({})".format(self.__class__.__name__, ", ".join(self._args))
+
+        def refactor_string(self, *args, **kwargs):
+            raise NotImplementedError("dummy RefactoringTool")
+
 
 from libfuturize import fixes
 

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

No branches or pull requests

8 participants