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

[WIP] pyrepl from PyPy #2

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f620a2f
Copy pyrepl from PyPy
blueyed Mar 10, 2019
cd77c02
tests: test_raw_input: test raw_input (again)
blueyed Mar 10, 2019
d7e72e6
raw_input: pass returns_unicode properly
blueyed Mar 10, 2019
2c0e489
Fix/re-enable quoted_insert: use self.evt.data
blueyed Mar 10, 2019
73a5249
Fix/improve qIHelp (for quoted-insert)
blueyed Mar 10, 2019
967eb91
Keep py2 fixes from master
blueyed Mar 10, 2019
9c666bb
test_readline: keep tests from master
blueyed Mar 10, 2019
fdcdd74
fixup! Keep py2 fixes from master
blueyed Mar 10, 2019
ae41c26
fixup! test_readline: keep tests from master
blueyed Mar 11, 2019
159e3a1
fixup! fixup! Keep py2 fixes from master
blueyed Mar 11, 2019
a25b7b7
Fix read_history_file/write_history_file for py2
blueyed Mar 11, 2019
998e379
fixup! fixup! fixup! Keep py2 fixes from master
blueyed Mar 11, 2019
ae4b8a2
testing/test_unix_reader.py from master
blueyed Mar 11, 2019
9308882
keep things from master for test_unix_reader
blueyed Mar 11, 2019
53d0a75
fixup! keep things from master for test_unix_reader
blueyed Mar 11, 2019
c91fcd2
keep ncursesw fix
blueyed Mar 11, 2019
d8636d1
fixup! Fix/improve qIHelp (for quoted-insert)
blueyed Mar 11, 2019
07a784d
remove testing/conftest.py: pytest_ignore_collect should not be needed
blueyed Mar 11, 2019
93d6868
testing/__init__.py: no trailing newline
blueyed Mar 11, 2019
87b1951
keep pyrepl/unix_eventqueue.py mostly from master
blueyed Mar 11, 2019
e10e082
tests: add test_write_history_file (failing on master)
blueyed Mar 11, 2019
ff54181
write_history_file: do not nuke history on errors
blueyed Mar 11, 2019
f5c935f
keep 33aac3f from master
blueyed Mar 11, 2019
4d3648c
Keep code cleanup from master
blueyed Mar 11, 2019
7f1a049
fixup! write_history_file: do not nuke history on errors
blueyed Mar 11, 2019
2d61f10
fixup! raw_input: pass returns_unicode properly
blueyed Mar 11, 2019
19d6636
fixup! Keep code cleanup from master
blueyed Mar 11, 2019
40cb460
pyrepl/completing_reader.py: keep most of master, flake8 clean
blueyed Mar 16, 2019
655cc50
Remove pyrepl/_minimal_curses.py
blueyed Mar 16, 2019
9a0ff78
keep pyrepl/cmdrepl.py from master
blueyed Mar 16, 2019
63ce133
remove pyrepl/unicodedata_.py
blueyed Mar 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 0 additions & 76 deletions pyrepl/_minimal_curses.py

This file was deleted.

8 changes: 6 additions & 2 deletions pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ def do(self):

class qIHelp(Command):
def do(self):
from .reader import disp_str

r = self.reader
r.insert((bytes(self.event) + r.console.getpending().data) * r.get_arg())
pending = r.console.getpending().data
disp = disp_str((self.event + pending))[0]
r.insert(disp * r.get_arg())
r.pop_input_trans()

from pyrepl import input
Expand All @@ -379,7 +383,7 @@ class QITrans(object):
def push(self, evt):
self.evt = evt
def get(self):
return ('qIHelp', self.evt.raw)
return ('qIHelp', self.evt.data)

class quoted_insert(Command):
kills_digit_arg = 0
Expand Down
7 changes: 3 additions & 4 deletions pyrepl/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

try:
import __builtin__ as builtins
builtins # silence broken pyflakes
except ImportError:
import builtins


class Completer(object):
class Completer:
def __init__(self, ns):
self.ns = ns

Expand Down Expand Up @@ -81,10 +79,11 @@ def attr_matches(self, text):
matches.append("%s.%s" % (expr, word))
return matches


def get_class_members(klass):
ret = dir(klass)
if hasattr(klass, '__bases__'):
for base in klass.__bases__:
ret = ret + get_class_members(base)
return ret


9 changes: 5 additions & 4 deletions pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def prefix(wordlist, j=0):

STRIPCOLOR_REGEX = re.compile(r"\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[m|K]")


def stripcolor(s):
return STRIPCOLOR_REGEX.sub('', s)

Expand All @@ -65,8 +66,8 @@ def build_menu(cons, wordlist, start, use_brackets, sort_in_column):
item = "%s "
padding = 2
maxlen = min(max(map(real_len, wordlist)), cons.width - padding)
cols = int(cons.width / (maxlen + padding))
rows = int((len(wordlist) - 1)/cols + 1)
cols = cons.width // (maxlen + padding)
rows = (len(wordlist) - 1) // cols + 1

if sort_in_column:
# sort_in_column=False (default) sort_in_column=True
Expand Down Expand Up @@ -104,7 +105,7 @@ def build_menu(cons, wordlist, start, use_brackets, sort_in_column):
# To summarise the summary of the summary:- people are a problem.
# -- The Hitch-Hikers Guide to the Galaxy, Episode 12

#### Desired behaviour of the completions commands.
# Desired behaviour of the completions commands.
# the considerations are:
# (1) how many completions are possible
# (2) whether the last command was a completion
Expand Down Expand Up @@ -275,7 +276,7 @@ def get_completions(self, stem):
reader.ps1 = "c**> "
reader.ps2 = "c/*> "
reader.ps3 = "c|*> "
reader.ps4 = "c\*> "
reader.ps4 = r"c\*> "
while reader.readline():
pass

Expand Down
3 changes: 1 addition & 2 deletions pyrepl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


class Event(object):
"""An Event. `evt' is 'key' or somesuch."""
__slots__ = 'evt', 'data', 'raw'
Expand All @@ -42,7 +41,7 @@ class Console(object):
height,
width,
"""

def refresh(self, screen, xy):
pass

Expand Down
23 changes: 22 additions & 1 deletion pyrepl/curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,26 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

# If we are running on top of pypy, we import only _minimal_curses.
# Don't try to fall back to _curses, because that's going to use cffi
# and fall again more loudly.
import sys
if '__pypy__' in sys.builtin_module_names:
# pypy case
import _minimal_curses as _curses
else:
# cpython case
try:
import _curses
except ImportError:
# Who knows, maybe some environment has "curses" but not "_curses".
# If not, at least the following import gives a clean ImportError.
try:
import curses as _curses
except ImportError:
import _curses

from ._minimal_curses import setupterm, tigetstr, tparm, error
setupterm = _curses.setupterm
tigetstr = _curses.tigetstr
tparm = _curses.tparm
error = _curses.error
3 changes: 1 addition & 2 deletions pyrepl/historical_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

from pyrepl import reader, commands
from pyrepl import reader, commands, input
from pyrepl.reader import Reader as R

isearch_keymap = tuple(
Expand Down Expand Up @@ -215,7 +215,6 @@ def __init__(self, console):
isearch_forwards, isearch_backwards, operate_and_get_next]:
self.commands[c.__name__] = c
self.commands[c.__name__.replace('_', '-')] = c
from pyrepl import input
self.isearch_trans = input.KeymapTranslator(
isearch_keymap, invalid_cls=isearch_end,
character_cls=isearch_add_character)
Expand Down
4 changes: 2 additions & 2 deletions pyrepl/keymaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(r'\M-\n', 'self-insert'),
(r'\<backslash>', 'self-insert')] + \
[(c, 'self-insert')
for c in map(chr, range(32, 127)) if c <> '\\'] + \
for c in map(chr, range(32, 127)) if c != '\\'] + \
[(c, 'self-insert')
for c in map(chr, range(128, 256)) if c.isalpha()] + \
[(r'\<up>', 'up'),
Expand Down Expand Up @@ -101,7 +101,7 @@

reader_vi_insert_keymap = tuple(
[(c, 'self-insert')
for c in map(chr, range(32, 127)) if c <> '\\'] + \
for c in map(chr, range(32, 127)) if c != '\\'] + \
[(c, 'self-insert')
for c in map(chr, range(128, 256)) if c.isalpha()] + \
[(r'\C-d', 'delete'),
Expand Down
4 changes: 2 additions & 2 deletions pyrepl/module_lister.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def _make_module_list_dir(dir, suffs, prefix=''):
return sorted(set(l))

def _make_module_list():
import imp
suffs = [x[0] for x in imp.get_suffixes() if x[0] != '.pyc']
import importlib.machinery
suffs = [x for x in importlib.machinery.all_suffixes() if x != '.pyc']
suffs.sort(reverse=True)
_packages[''] = list(sys.builtin_module_names)
for dir in sys.path:
Expand Down
7 changes: 4 additions & 3 deletions pyrepl/pygame_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def paint_margin(self):
s.fill(c, [0, 600 - bmargin, 800, bmargin])
s.fill(c, [800 - rmargin, 0, lmargin, 600])

def refresh(self, screen, (cx, cy)):
def refresh(self, screen, cxy):
self.screen = screen
self.pygame_screen.fill(colors.bg,
[0, tmargin + self.cur_top + self.scroll,
Expand All @@ -139,6 +139,7 @@ def refresh(self, screen, (cx, cy)):

line_top = self.cur_top
width, height = self.fontsize
cx, cy = cxy
self.cxy = (cx, cy)
cp = self.char_pos(cx, cy)
if cp[1] < tmargin:
Expand Down Expand Up @@ -282,7 +283,7 @@ def flushoutput(self):

def forgetinput(self):
"""Forget all pending, but not yet processed input."""
while pygame.event.poll().type <> NOEVENT:
while pygame.event.poll().type != NOEVENT:
pass

def getpending(self):
Expand All @@ -299,7 +300,7 @@ def getpending(self):

def wait(self):
"""Wait for an event."""
raise Exception, "erp!"
raise Exception("erp!")

def repaint(self):
# perhaps we should consolidate grobs?
Expand Down
38 changes: 19 additions & 19 deletions pyrepl/pygame_keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,22 @@ def _parse_key1(key, s):
s += 2
elif c == "c":
if key[s + 2] != '-':
raise KeySpecError, \
raise KeySpecError(
"\\C must be followed by `-' (char %d of %s)"%(
s + 2, repr(key))
s + 2, repr(key)))
if ctrl:
raise KeySpecError, "doubled \\C- (char %d of %s)"%(
s + 1, repr(key))
raise KeySpecError("doubled \\C- (char %d of %s)"%(
s + 1, repr(key)))
ctrl = 1
s += 3
elif c == "m":
if key[s + 2] != '-':
raise KeySpecError, \
raise KeySpecError(
"\\M must be followed by `-' (char %d of %s)"%(
s + 2, repr(key))
s + 2, repr(key)))
if meta:
raise KeySpecError, "doubled \\M- (char %d of %s)"%(
s + 1, repr(key))
raise KeySpecError("doubled \\M- (char %d of %s)"%(
s + 1, repr(key)))
meta = 1
s += 3
elif c.isdigit():
Expand All @@ -119,22 +119,22 @@ def _parse_key1(key, s):
elif c == '<':
t = key.find('>', s)
if t == -1:
raise KeySpecError, \
raise KeySpecError(
"unterminated \\< starting at char %d of %s"%(
s + 1, repr(key))
s + 1, repr(key)))
try:
ret = _keynames[key[s+2:t].lower()]
s = t + 1
except KeyError:
raise KeySpecError, \
raise KeySpecError(
"unrecognised keyname `%s' at char %d of %s"%(
key[s+2:t], s + 2, repr(key))
key[s+2:t], s + 2, repr(key)))
if ret is None:
return None, s
else:
raise KeySpecError, \
raise KeySpecError(
"unknown backslash escape %s at char %d of %s"%(
`c`, s + 2, repr(key))
repr(c), s + 2, repr(key)))
else:
if ctrl:
ret = chr(ord(key[s]) & 0x1f) # curses.ascii.ctrl()
Expand All @@ -160,9 +160,9 @@ def _compile_keymap(keymap):
r.setdefault(key[0], {})[key[1:]] = value
for key, value in r.items():
if value.has_key(()):
if len(value) <> 1:
raise KeySpecError, \
"key definitions for %s clash"%(value.values(),)
if len(value) != 1:
raise KeySpecError(
"key definitions for %s clash"%(value.values(),))
else:
r[key] = value[()]
else:
Expand Down Expand Up @@ -202,7 +202,7 @@ def unparse_key(keyseq):
return ''
name, s = keyname(keyseq)
if name:
if name <> 'escape' or s == len(keyseq):
if name != 'escape' or s == len(keyseq):
return '\\<' + name + '>' + unparse_key(keyseq[s:])
else:
return '\\M-' + unparse_key(keyseq[1:])
Expand All @@ -226,7 +226,7 @@ def _unparse_keyf(keyseq):
return []
name, s = keyname(keyseq)
if name:
if name <> 'escape' or s == len(keyseq):
if name != 'escape' or s == len(keyseq):
return [name] + _unparse_keyf(keyseq[s:])
else:
rest = _unparse_keyf(keyseq[1:])
Expand Down
2 changes: 1 addition & 1 deletion pyrepl/python_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def execute(self, text):
# ooh, look at the hack:
code = self.compile(text, '<stdin>', 'single')
except (OverflowError, SyntaxError, ValueError):
self.showsyntaxerror("<stdin>")
self.showsyntaxerror('<stdin>')
else:
self.runcode(code)
if sys.stdout and not sys.stdout.closed:
Expand Down
Loading