Skip to content

Commit d2394f1

Browse files
authored
Merge pull request #1 from blueyed/ci
ci: Travis
2 parents 29370c3 + e12038a commit d2394f1

File tree

10 files changed

+145
-29
lines changed

10 files changed

+145
-29
lines changed

.travis.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
dist: xenial
2+
language: python
3+
4+
env:
5+
global:
6+
- PYTEST_ADDOPTS="--cov --cov-report=xml"
7+
8+
jobs:
9+
include:
10+
- python: '2.7'
11+
env: TOXENV=py27-coverage
12+
- python: '3.4'
13+
env: TOXENV=py34-coverage
14+
- python: '3.5'
15+
env: TOXENV=py35-coverage
16+
- python: '3.6'
17+
env: TOXENV=py36-coverage
18+
- python: '3.7'
19+
env: TOXENV=py37-coverage
20+
- python: 'pypy2.7-6.0'
21+
env: TOXENV=pypy-coverage
22+
- python: 'pypy3.5-6.0'
23+
env: TOXENV=pypy3-coverage
24+
# Fails currently badly.
25+
# - python: '3.7'
26+
# env: TOXENV=qa
27+
28+
install:
29+
- pip install tox
30+
31+
script:
32+
- tox
33+
34+
after_script:
35+
- |
36+
if [[ "${TOXENV%-coverage}" != "$TOXENV" ]]; then
37+
bash <(curl -s https://codecov.io/bash) -Z -X gcov -X coveragepy -X search -X xcode -X gcovout -X fix -f coverage.xml -n $TOXENV
38+
fi
39+
40+
# Only master and releases. PRs are used otherwise.
41+
branches:
42+
only:
43+
- master
44+
- /^\d+\.\d+(\.\d+)?(-\S*)?$/

pyrepl/_minimal_curses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class error(Exception):
1717

1818

1919
def _find_clib():
20-
trylibs = ['ncurses', 'curses']
20+
trylibs = ['ncursesw', 'ncurses', 'curses']
2121

2222
for lib in trylibs:
2323
path = ctypes.util.find_library(lib)

pyrepl/completing_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ def build_menu(cons, wordlist, start, use_brackets, sort_in_column):
6565
item = "%s "
6666
padding = 2
6767
maxlen = min(max(map(real_len, wordlist)), cons.width - padding)
68-
cols = cons.width / (maxlen + padding)
69-
rows = (len(wordlist) - 1)/cols + 1
68+
cols = int(cons.width / (maxlen + padding))
69+
rows = int((len(wordlist) - 1)/cols + 1)
7070

7171
if sort_in_column:
7272
# sort_in_column=False (default) sort_in_column=True

pyrepl/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import unicodedata
3737
from collections import deque
3838
import pprint
39-
from trace import trace
39+
from .trace import trace
4040

4141

4242
class InputTranslator(object):

pyrepl/readline.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
from pyrepl.historical_reader import HistoricalReader
3333
from pyrepl.completing_reader import CompletingReader
3434
from pyrepl.unix_console import UnixConsole, _error
35+
try:
36+
unicode
37+
PY3 = False
38+
except NameError:
39+
PY3 = True
40+
unicode = str
41+
unichr = chr
42+
basestring = bytes, str
3543

3644

3745
ENCODING = sys.getfilesystemencoding() or 'latin1' # XXX review
@@ -199,7 +207,14 @@ def raw_input(self, prompt=''):
199207
except _error:
200208
return _old_raw_input(prompt)
201209
reader.ps1 = prompt
202-
return reader.readline(startup_hook=self.startup_hook)
210+
211+
ret = reader.readline(startup_hook=self.startup_hook)
212+
if not PY3:
213+
return ret
214+
215+
# Unicode/str is required for Python 3 (3.5.2).
216+
# Ref: https://bitbucket.org/pypy/pyrepl/issues/20/#comment-30647029
217+
return unicode(ret, ENCODING)
203218

204219
def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
205220
"""Read an input on possibly multiple lines, asking for more
@@ -229,12 +244,15 @@ def set_completer_delims(self, string):
229244
self.config.completer_delims = dict.fromkeys(string)
230245

231246
def get_completer_delims(self):
232-
chars = self.config.completer_delims.keys()
247+
chars = list(self.config.completer_delims.keys())
233248
chars.sort()
234249
return ''.join(chars)
235250

236251
def _histline(self, line):
237252
line = line.rstrip('\n')
253+
if PY3:
254+
return line
255+
238256
try:
239257
return unicode(line, ENCODING)
240258
except UnicodeDecodeError: # bah, silently fall back...
@@ -423,9 +441,14 @@ def _old_raw_input(prompt=''):
423441

424442
else:
425443
# this is not really what readline.c does. Better than nothing I guess
426-
import __builtin__
427-
_old_raw_input = __builtin__.raw_input
428-
__builtin__.raw_input = _wrapper.raw_input
444+
try:
445+
import __builtin__
446+
_old_raw_input = __builtin__.raw_input
447+
__builtin__.raw_input = _wrapper.raw_input
448+
except ImportError:
449+
import builtins
450+
_old_raw_input = builtins.input
451+
builtins.input = _wrapper.raw_input
429452

430453
_old_raw_input = None
431454
_setup()

pyrepl/simple_interact.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ def run_multiline_interactive_console(mainmodule=None, future_flags=0):
4444
console.compile.compiler.flags |= future_flags
4545

4646
def more_lines(unicodetext):
47-
# ooh, look at the hack:
48-
src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
47+
if sys.version_info < (3, ):
48+
# ooh, look at the hack:
49+
src = "#coding:utf-8\n"+unicodetext.encode('utf-8')
50+
else:
51+
src = unicodetext
4952
try:
5053
code = console.compile(src, '<stdin>', 'single')
5154
except (OverflowError, SyntaxError, ValueError):

pyrepl/unix_eventqueue.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
#
6666
CTRL_ARROW_KEYCODE = {
6767
# for xterm, gnome-terminal, xfce terminal, etc.
68-
'\033[1;5D': 'ctrl left',
69-
'\033[1;5C': 'ctrl right',
68+
b'\033[1;5D': 'ctrl left',
69+
b'\033[1;5C': 'ctrl right',
7070
# for rxvt
71-
'\033Od': 'ctrl left',
72-
'\033Oc': 'ctrl right',
71+
b'\033Od': 'ctrl left',
72+
b'\033Oc': 'ctrl right',
7373
}
7474

7575
def general_keycodes():
@@ -120,6 +120,7 @@ def insert(self, event):
120120

121121
def push(self, char):
122122
ord_char = char if isinstance(char, int) else ord(char)
123+
char = bytes(bytearray((ord_char,)))
123124
self.buf.append(ord_char)
124125
if char in self.k:
125126
if self.k is self.ck:
@@ -133,13 +134,13 @@ def push(self, char):
133134
self.insert(Event('key', k, self.flush_buf()))
134135
self.k = self.ck
135136

136-
elif self.buf and self.buf[0] == 033: # 033 == escape
137+
elif self.buf and self.buf[0] == 27: # escape
137138
# escape sequence not recognized by our keymap: propagate it
138139
# outside so that i can be recognized as an M-... key (see also
139140
# the docstring in keymap.py, in particular the line \\E.
140141
trace('unrecognized escape sequence, propagating...')
141142
self.k = self.ck
142-
self.insert(Event('key', '\033', '\033'))
143+
self.insert(Event('key', '\033', bytearray(b'\033')))
143144
for c in self.flush_buf()[1:]:
144145
self.push(chr(c))
145146

testing/test_functional.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import sys
88

99

10-
def pytest_funcarg__child(request):
10+
@pytest.fixture
11+
def child(request):
1112
try:
1213
pexpect = pytest.importorskip('pexpect')
1314
except SyntaxError:

testing/test_readline.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1-
from pyrepl.readline import _ReadlineWrapper
21
import os
32
import pty
43
import sys
54

5+
import pytest
6+
from pyrepl.readline import _ReadlineWrapper
7+
8+
9+
@pytest.fixture
10+
def readline_wrapper():
11+
master, slave = pty.openpty()
12+
return _ReadlineWrapper(slave, slave)
13+
14+
615
if sys.version_info < (3, ):
716
bytes_type = str
8-
unicode_type = unicode
17+
unicode_type = unicode # noqa: F821
918
else:
1019
bytes_type = bytes
1120
unicode_type = str
@@ -37,5 +46,23 @@ def test_raw_input():
3746
os.write(master, b'input\n')
3847

3948
result = readline_wrapper.raw_input('prompt:')
40-
assert result == b'input'
41-
assert isinstance(result, bytes_type)
49+
if sys.version_info < (3, ):
50+
assert result == b'input'
51+
assert isinstance(result, bytes_type)
52+
else:
53+
assert result == 'input'
54+
assert isinstance(result, unicode_type)
55+
56+
57+
def test_read_history_file(readline_wrapper, tmp_path):
58+
histfile = tmp_path / "history"
59+
histfile.touch()
60+
61+
assert readline_wrapper.reader is None
62+
63+
readline_wrapper.read_history_file(str(histfile))
64+
assert readline_wrapper.reader.history == []
65+
66+
histfile.write_bytes(b"foo\nbar\n")
67+
readline_wrapper.read_history_file(str(histfile))
68+
assert readline_wrapper.reader.history == ["foo", "bar"]

tox.ini

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
[tox]
2-
envlist = py27, py33, flake8, pypy
3-
4-
2+
envlist = py{27,34,35,36,37,py,py3}, flake8
53

64
[testenv]
7-
deps=
5+
deps =
86
pytest
97
pexpect
10-
commands=
11-
py.test --junitxml={envdir}/junit.xml []
8+
coverage: pytest-cov
9+
commands =
10+
pytest {posargs}
11+
passenv =
12+
TERM
13+
setenv =
14+
coverage: PYTEST_ADDOPTS=--cov {env:PYTEST_ADDOPTS:}
1215

13-
[testenv:flake8]
16+
[testenv:qa]
1417
deps =
1518
flake8
1619
mccabe
1720
commands = flake8 --max-complexity=10 setup.py pyrepl testing pythoni pythoni1
21+
22+
[pytest]
23+
testpaths = testing
24+
25+
[coverage:run]
26+
include = pyrepl/*, testing/*
27+
parallel = 1
28+
branch = 1
29+
30+
[coverage:paths]
31+
source = pyrepl/
32+
*/lib/python*/site-packages/pyrepl/
33+
*/pypy*/site-packages/pyrepl/
34+
*\Lib\site-packages\pyrepl\

0 commit comments

Comments
 (0)