From 572c205b31844893476cc8439f38b1d5b5de9ec8 Mon Sep 17 00:00:00 2001 From: Rachmadani Haryono Date: Fri, 18 Feb 2022 17:27:50 +0800 Subject: [PATCH 1/5] fix: SyntaxError --- pyrepl/keymaps.py | 177 +++++++++++++++++++-------------------- pyrepl/pygame_console.py | 13 +-- pyrepl/pygame_keymap.py | 60 +++++++------ 3 files changed, 127 insertions(+), 123 deletions(-) diff --git a/pyrepl/keymaps.py b/pyrepl/keymaps.py index 76ba896..ec30152 100644 --- a/pyrepl/keymaps.py +++ b/pyrepl/keymaps.py @@ -18,68 +18,69 @@ # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. reader_emacs_keymap = tuple( - [(r'\C-a', 'beginning-of-line'), - (r'\C-b', 'left'), - (r'\C-c', 'interrupt'), - (r'\C-d', 'delete'), - (r'\C-e', 'end-of-line'), - (r'\C-f', 'right'), - (r'\C-g', 'cancel'), - (r'\C-h', 'backspace'), - (r'\C-j', 'self-insert'), - (r'\', 'accept'), - (r'\C-k', 'kill-line'), - (r'\C-l', 'clear-screen'), -# (r'\C-m', 'accept'), - (r'\C-q', 'quoted-insert'), - (r'\C-t', 'transpose-characters'), - (r'\C-u', 'unix-line-discard'), - (r'\C-v', 'quoted-insert'), - (r'\C-w', 'unix-word-rubout'), - (r'\C-x\C-u', 'upcase-region'), - (r'\C-y', 'yank'), - (r'\C-z', 'suspend'), - - (r'\M-b', 'backward-word'), - (r'\M-c', 'capitalize-word'), - (r'\M-d', 'kill-word'), - (r'\M-f', 'forward-word'), - (r'\M-l', 'downcase-word'), - (r'\M-t', 'transpose-words'), - (r'\M-u', 'upcase-word'), - (r'\M-y', 'yank-pop'), - (r'\M--', 'digit-arg'), - (r'\M-0', 'digit-arg'), - (r'\M-1', 'digit-arg'), - (r'\M-2', 'digit-arg'), - (r'\M-3', 'digit-arg'), - (r'\M-4', 'digit-arg'), - (r'\M-5', 'digit-arg'), - (r'\M-6', 'digit-arg'), - (r'\M-7', 'digit-arg'), - (r'\M-8', 'digit-arg'), - (r'\M-9', 'digit-arg'), - (r'\M-\n', 'self-insert'), - (r'\', 'self-insert')] + \ - [(c, 'self-insert') - 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'), - (r'\', 'down'), - (r'\', 'left'), - (r'\', 'right'), - (r'\', 'quoted-insert'), - (r'\', 'delete'), - (r'\', 'backspace'), - (r'\M-\', 'backward-kill-word'), - (r'\', 'end'), - (r'\', 'home'), - (r'\', 'help'), - (r'\EOF', 'end'), # the entries in the terminfo database for xterms - (r'\EOH', 'home'), # seem to be wrong. this is a less than ideal - # workaround - ]) + [ + (r"\C-a", "beginning-of-line"), + (r"\C-b", "left"), + (r"\C-c", "interrupt"), + (r"\C-d", "delete"), + (r"\C-e", "end-of-line"), + (r"\C-f", "right"), + (r"\C-g", "cancel"), + (r"\C-h", "backspace"), + (r"\C-j", "self-insert"), + (r"\", "accept"), + (r"\C-k", "kill-line"), + (r"\C-l", "clear-screen"), + # (r'\C-m', 'accept'), + (r"\C-q", "quoted-insert"), + (r"\C-t", "transpose-characters"), + (r"\C-u", "unix-line-discard"), + (r"\C-v", "quoted-insert"), + (r"\C-w", "unix-word-rubout"), + (r"\C-x\C-u", "upcase-region"), + (r"\C-y", "yank"), + (r"\C-z", "suspend"), + (r"\M-b", "backward-word"), + (r"\M-c", "capitalize-word"), + (r"\M-d", "kill-word"), + (r"\M-f", "forward-word"), + (r"\M-l", "downcase-word"), + (r"\M-t", "transpose-words"), + (r"\M-u", "upcase-word"), + (r"\M-y", "yank-pop"), + (r"\M--", "digit-arg"), + (r"\M-0", "digit-arg"), + (r"\M-1", "digit-arg"), + (r"\M-2", "digit-arg"), + (r"\M-3", "digit-arg"), + (r"\M-4", "digit-arg"), + (r"\M-5", "digit-arg"), + (r"\M-6", "digit-arg"), + (r"\M-7", "digit-arg"), + (r"\M-8", "digit-arg"), + (r"\M-9", "digit-arg"), + (r"\M-\n", "self-insert"), + (r"\", "self-insert"), + ] + + [(c, "self-insert") 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"), + (r"\", "down"), + (r"\", "left"), + (r"\", "right"), + (r"\", "quoted-insert"), + (r"\", "delete"), + (r"\", "backspace"), + (r"\M-\", "backward-kill-word"), + (r"\", "end"), + (r"\", "home"), + (r"\", "help"), + (r"\EOF", "end"), # the entries in the terminfo database for xterms + (r"\EOH", "home"), # seem to be wrong. this is a less than ideal + # workaround + ] +) hist_emacs_keymap = reader_emacs_keymap + ( (r'\C-n', 'next-history'), @@ -98,37 +99,34 @@ python_emacs_keymap = comp_emacs_keymap + ( (r'\n', 'maybe-accept'), (r'\M-\n', 'self-insert')) - + reader_vi_insert_keymap = tuple( - [(c, 'self-insert') - 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'), - (r'\', 'backspace'), - ('')]) + [(c, "self-insert") 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"), (r"\", "backspace"), ("")] +) reader_vi_command_keymap = tuple( [ - ('E', 'enter-emacs-mode'), - ('R', 'enter-replace-mode'), - ('dw', 'delete-word'), - ('dd', 'delete-line'), - - ('h', 'left'), - ('i', 'enter-insert-mode'), - ('j', 'down'), - ('k', 'up'), - ('l', 'right'), - ('r', 'replace-char'), - ('w', 'forward-word'), - ('x', 'delete'), - ('.', 'repeat-edit'), # argh! - (r'\', 'enter-insert-mode'), - ] + - [(c, 'digit-arg') for c in '01234567689'] + - []) - + ("E", "enter-emacs-mode"), + ("R", "enter-replace-mode"), + ("dw", "delete-word"), + ("dd", "delete-line"), + ("h", "left"), + ("i", "enter-insert-mode"), + ("j", "down"), + ("k", "up"), + ("l", "right"), + ("r", "replace-char"), + ("w", "forward-word"), + ("x", "delete"), + (".", "repeat-edit"), # argh! + (r"\", "enter-insert-mode"), + ] + + [(c, "digit-arg") for c in "01234567689"] + + [] +) + reader_keymaps = { 'emacs' : reader_emacs_keymap, @@ -137,4 +135,3 @@ } del c # from the listcomps - diff --git a/pyrepl/pygame_console.py b/pyrepl/pygame_console.py index cb90b8b..0c5b9cf 100644 --- a/pyrepl/pygame_console.py +++ b/pyrepl/pygame_console.py @@ -89,7 +89,7 @@ class PyGameConsole(Console): height, width, """ - + def __init__(self): self.pygame_screen = pygame.display.set_mode((800, 600)) pygame.font.init() @@ -105,7 +105,7 @@ def __init__(self): pygame.display.update() pygame.event.set_allowed(None) pygame.event.set_allowed(KEYDOWN) - + def install_keymap(self, keymap): """Install a given keymap. @@ -130,7 +130,8 @@ 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, c): + c = cx, cy self.screen = screen self.pygame_screen.fill(colors.bg, [0, tmargin + self.cur_top + self.scroll, @@ -282,9 +283,9 @@ 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): """Return the characters that have been typed but not yet processed.""" @@ -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? diff --git a/pyrepl/pygame_keymap.py b/pyrepl/pygame_keymap.py index 5531f1c..3ad8981 100644 --- a/pyrepl/pygame_keymap.py +++ b/pyrepl/pygame_keymap.py @@ -89,23 +89,27 @@ def _parse_key1(key, s): ret = _escapes[c] s += 2 elif c == "c": - if key[s + 2] != '-': - raise KeySpecError, \ - "\\C must be followed by `-' (char %d of %s)"%( - s + 2, repr(key)) + if key[s + 2] != "-": + raise KeySpecError( + "\\C must be followed by `-' (char %d of %s)" + % (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, \ - "\\M must be followed by `-' (char %d of %s)"%( - s + 2, repr(key)) + if key[s + 2] != "-": + raise KeySpecError( + "\\M must be followed by `-' (char %d of %s)" + % (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(): @@ -119,22 +123,25 @@ def _parse_key1(key, s): elif c == '<': t = key.find('>', s) if t == -1: - raise KeySpecError, \ - "unterminated \\< starting at char %d of %s"%( - s + 1, repr(key)) + raise KeySpecError( + "unterminated \\< starting at char %d of %s" + % (s + 1, repr(key)) + ) try: ret = _keynames[key[s+2:t].lower()] s = t + 1 except KeyError: - raise KeySpecError, \ - "unrecognised keyname `%s' at char %d of %s"%( - key[s+2:t], s + 2, repr(key)) + raise KeySpecError( + "unrecognised keyname `%s' at char %d of %s" + % (key[s + 2 : t], s + 2, repr(key)) + ) if ret is None: return None, s else: - raise KeySpecError, \ - "unknown backslash escape %s at char %d of %s"%( - `c`, s + 2, repr(key)) + raise KeySpecError( + "unknown backslash escape %s at char %d of %s" + % (repr(c), s + 2, repr(key)) + ) else: if ctrl: ret = chr(ord(key[s]) & 0x1f) # curses.ascii.ctrl() @@ -160,9 +167,8 @@ 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: @@ -202,8 +208,8 @@ def unparse_key(keyseq): return '' name, s = keyname(keyseq) if name: - if name <> 'escape' or s == len(keyseq): - return '\\<' + name + '>' + unparse_key(keyseq[s:]) + if name != "escape" or s == len(keyseq): + return "\\<" + name + ">" + unparse_key(keyseq[s:]) else: return '\\M-' + unparse_key(keyseq[1:]) else: @@ -226,7 +232,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:]) From 7ed1044d1e0c522c80e40d4812ac14b2cb926994 Mon Sep 17 00:00:00 2001 From: Rachmadani Haryono Date: Fri, 18 Feb 2022 17:28:31 +0800 Subject: [PATCH 2/5] ci: test compileall --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76e8e84..f0f3e52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,6 +102,9 @@ jobs: TOX_TESTENV_PASSENV: "PYTHONUTF8" run: python -m tox -v --durations -e ${{ matrix.tox_env }} + - name: Test compile + run: python -m compileall pyrepl pythoni pythoni1 + - name: Report coverage if: always() && (steps.setup-tox.outcome == 'success' && contains(matrix.tox_env, '-coverage')) uses: codecov/codecov-action@v1 From 8669e51fa91eaa5f42a0900c5c08c7f1b9f2f2fe Mon Sep 17 00:00:00 2001 From: Rachmadani Haryono Date: Sat, 23 Jul 2022 17:06:31 +0800 Subject: [PATCH 3/5] refactor(keymaps): remove unnecessary list addition --- pyrepl/keymaps.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyrepl/keymaps.py b/pyrepl/keymaps.py index ec30152..202af01 100644 --- a/pyrepl/keymaps.py +++ b/pyrepl/keymaps.py @@ -124,7 +124,6 @@ (r"\", "enter-insert-mode"), ] + [(c, "digit-arg") for c in "01234567689"] - + [] ) From 1582e6dab5d9bd4cd180eabb45ac1dbc3f7bbde2 Mon Sep 17 00:00:00 2001 From: Rachmadani Haryono Date: Wed, 27 Jul 2022 05:15:25 +0800 Subject: [PATCH 4/5] style(keymaps): fix comment --- pyrepl/keymaps.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyrepl/keymaps.py b/pyrepl/keymaps.py index 202af01..dbc192c 100644 --- a/pyrepl/keymaps.py +++ b/pyrepl/keymaps.py @@ -77,8 +77,7 @@ (r"\", "home"), (r"\", "help"), (r"\EOF", "end"), # the entries in the terminfo database for xterms - (r"\EOH", "home"), # seem to be wrong. this is a less than ideal - # workaround + (r"\EOH", "home"), # seem to be wrong. this is a less than ideal workaround ] ) From 0262f36a1fa1815a9789706fac50190ca58eef75 Mon Sep 17 00:00:00 2001 From: Rachmadani Haryono Date: Wed, 27 Jul 2022 18:32:02 +0800 Subject: [PATCH 5/5] style(keymaps): more clear comment on home and end --- pyrepl/keymaps.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyrepl/keymaps.py b/pyrepl/keymaps.py index dbc192c..f7ab0a6 100644 --- a/pyrepl/keymaps.py +++ b/pyrepl/keymaps.py @@ -76,8 +76,10 @@ (r"\", "end"), (r"\", "home"), (r"\", "help"), - (r"\EOF", "end"), # the entries in the terminfo database for xterms - (r"\EOH", "home"), # seem to be wrong. this is a less than ideal workaround + # the entries in the terminfo database for xterms seem to be wrong. + # this is a less than ideal workaround + (r"\EOF", "end"), + (r"\EOH", "home"), ] )