Skip to content
This repository

PyPy compatibility #722

Merged
merged 2 commits into from over 2 years ago

2 participants

Thomas Kluyver Min RK
Thomas Kluyver
Collaborator

So far, this just gets it to start. It still has trouble with readline, and there a lot of test failures - a combination of nose, the limitations of PyPy's numpy module, small differences in output for doctests, and unicode.

Will liaise with PyPy developers - first off, about readline, because without tab completion, one of the big advantages of IPython is missing.

Closes gh-719

Thomas Kluyver
Collaborator

The shell is now working OK with PyPy's readline. Haven't tried to make all the tests pass.

Min RK
Owner

Do we want to wait for further PyPy compatibility, or should we just merge this now? It seems fine as-is to me.

Thomas Kluyver
Collaborator

I'm happy to merge this now. We can always do more later if we need to. I just made a PR to check that it was OK to store the original raw_input at instantiation, rather than at import.

Min RK
Owner

Yes, I think this makes sense. I think it's actually better, because IPython should use the raw_input of the environment into which it is launched, not that of the top of the first file to import it.

Thomas Kluyver takluyver merged commit d8f3d17 into from September 07, 2011
Thomas Kluyver takluyver closed this September 07, 2011
Thomas Kluyver
Collaborator

OK, great. I've merged it in.

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

Showing 2 unique commits by 1 author.

Aug 22, 2011
Thomas Kluyver Use casting trait for session number in history, so IPython will star…
…t on PyPy.

Closes gh-719
4d5d46f
Thomas Kluyver Defer saving raw_input to shell initialisation, so that we pick up th…
…e modified version needed for PyPy's readline to work.
d8f3d17
This page is out of date. Refresh to see the latest.
4  IPython/core/history.py
@@ -25,7 +25,7 @@
25 25
 
26 26
 from IPython.testing.skipdoctest import skip_doctest
27 27
 from IPython.utils import io
28  
-from IPython.utils.traitlets import Bool, Dict, Instance, Int, List, Unicode
  28
+from IPython.utils.traitlets import Bool, Dict, Instance, Int, CInt, List, Unicode
29 29
 from IPython.utils.warn import warn
30 30
 
31 31
 #-----------------------------------------------------------------------------
@@ -63,7 +63,7 @@ def _dir_hist_default(self):
63 63
     # The SQLite database
64 64
     db = Instance(sqlite3.Connection)
65 65
     # The number of the current session in the history database
66  
-    session_number = Int()
  66
+    session_number = CInt()
67 67
     # Should we log output to the database? (default no)
68 68
     db_log_output = Bool(False, config=True)
69 69
     # Write to database every x commands (higher values save disk access & power)
8  IPython/core/interactiveshell.py
@@ -86,10 +86,6 @@
86 86
 # Utilities
87 87
 #-----------------------------------------------------------------------------
88 88
 
89  
-# store the builtin raw_input globally, and use this always, in case user code
90  
-# overwrites it (like wx.py.PyShell does)
91  
-raw_input_original = raw_input
92  
-
93 89
 def softspace(file, newvalue):
94 90
     """Copied from code.py, to remove the dependency"""
95 91
 
@@ -411,6 +407,10 @@ def __init__(self, config=None, ipython_dir=None, profile_dir=None,
411 407
         # init_readline() must come before init_io(), because init_io uses
412 408
         # readline related things.
413 409
         self.init_readline()
  410
+        # We save this here in case user code replaces raw_input, but it needs
  411
+        # to be after init_readline(), because PyPy's readline works by replacing
  412
+        # raw_input.
  413
+        self.raw_input_original = raw_input
414 414
         # init_completer must come after init_readline, because it needs to
415 415
         # know whether readline is present or not system-wide to configure the
416 416
         # completers, since the completion machinery can now operate
2  IPython/core/magic.py
@@ -3175,7 +3175,7 @@ def _get_pasted_lines(self, sentinel):
3175 3175
         from IPython.core import interactiveshell
3176 3176
         print "Pasting code; enter '%s' alone on the line to stop." % sentinel
3177 3177
         while True:
3178  
-            l = interactiveshell.raw_input_original(':')
  3178
+            l = self.shell.raw_input_original(':')
3179 3179
             if l == sentinel:
3180 3180
                 return
3181 3181
             else:
7  IPython/frontend/terminal/interactiveshell.py
@@ -47,11 +47,6 @@ def get_default_editor():
47 47
             ed = 'notepad' # same in Windows!
48 48
     return ed
49 49
 
50  
-
51  
-# store the builtin raw_input globally, and use this always, in case user code
52  
-# overwrites it (like wx.py.PyShell does)
53  
-raw_input_original = raw_input
54  
-
55 50
 #-----------------------------------------------------------------------------
56 51
 # Main class
57 52
 #-----------------------------------------------------------------------------
@@ -337,7 +332,7 @@ def raw_input(self, prompt=''):
337 332
             self.set_readline_completer()
338 333
         
339 334
         try:
340  
-            line = raw_input_original(prompt).decode(self.stdin_encoding)
  335
+            line = self.raw_input_original(prompt).decode(self.stdin_encoding)
341 336
         except ValueError:
342 337
             warn("\n********\nYou or a %run:ed script called sys.stdin.close()"
343 338
                  " or sys.stdout.close()!\nExiting IPython!")
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.