Skip to content

Commit 11d34d0

Browse files
committed
PEP-8
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 94bb657 commit 11d34d0

12 files changed

+292
-170
lines changed

bpython/curtsiesfrontend/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

bpython/curtsiesfrontend/_internal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import bpython._internal
2626

27+
2728
class _Helper(bpython._internal._Helper):
2829

2930
def __init__(self, repl=None):

bpython/curtsiesfrontend/coderunner.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
"""For running Python code that could interrupt itself at any time
2-
in order to, for example, ask for a read on stdin, or a write on stdout
1+
"""For running Python code that could interrupt itself at any time in order to,
2+
for example, ask for a read on stdin, or a write on stdout
33
4-
The CodeRunner spawns a greenlet to run code in, and that code can suspend
5-
its own execution to ask the main greenlet to refresh the display or get information.
4+
The CodeRunner spawns a greenlet to run code in, and that code can suspend its
5+
own execution to ask the main greenlet to refresh the display or get
6+
information.
67
7-
Greenlets are basically threads that can explicitly switch control to each other.
8-
You can replace the word "greenlet" with "thread" in these docs if that makes more
9-
sense to you.
8+
Greenlets are basically threads that can explicitly switch control to each
9+
other. You can replace the word "greenlet" with "thread" in these docs if that
10+
makes more sense to you.
1011
"""
1112

1213
import code
@@ -16,31 +17,40 @@
1617

1718
logger = logging.getLogger(__name__)
1819

20+
1921
class SigintHappened(object):
2022
"""If this class is returned, a SIGINT happened while the main greenlet"""
2123

24+
2225
class SystemExitFromCodeGreenlet(SystemExit):
23-
"""If this class is returned, a SystemExit happened while in the code greenlet"""
26+
"""If this class is returned, a SystemExit happened while in the code
27+
greenlet"""
2428

2529

2630
class RequestFromCodeGreenlet(object):
2731
"""Message from the code greenlet"""
2832

33+
2934
class Wait(RequestFromCodeGreenlet):
3035
"""Running code would like the main loop to run for a bit"""
3136

37+
3238
class Refresh(RequestFromCodeGreenlet):
3339
"""Running code would like the main loop to refresh the display"""
3440

41+
3542
class Done(RequestFromCodeGreenlet):
3643
"""Running code is done running"""
3744

45+
3846
class Unfinished(RequestFromCodeGreenlet):
3947
"""Source code wasn't executed because it wasn't fully formed"""
4048

49+
4150
class SystemExitRequest(RequestFromCodeGreenlet):
4251
"""Running code raised a SystemExit"""
4352

53+
4454
class CodeRunner(object):
4555
"""Runs user code in an interpreter.
4656
@@ -67,31 +77,35 @@ class CodeRunner(object):
6777
just passes whatever is passed in to run_code(for_code) to the
6878
code greenlet
6979
"""
70-
def __init__(self, interp=None, request_refresh=lambda:None):
80+
def __init__(self, interp=None, request_refresh=lambda: None):
7181
"""
7282
interp is an interpreter object to use. By default a new one is
7383
created.
7484
75-
request_refresh is a function that will be called each time
76-
the running code asks for a refresh - to, for example, update the screen.
85+
request_refresh is a function that will be called each time the running
86+
code asks for a refresh - to, for example, update the screen.
7787
"""
7888
self.interp = interp or code.InteractiveInterpreter()
7989
self.source = None
8090
self.main_greenlet = greenlet.getcurrent()
8191
self.code_greenlet = None
8292
self.request_refresh = request_refresh
83-
self.code_is_waiting = False # waiting for response from main thread
84-
self.sigint_happened_in_main_greenlet = False # sigint happened while in main thread
93+
# waiting for response from main thread
94+
self.code_is_waiting = False
95+
# sigint happened while in main thread
96+
self.sigint_happened_in_main_greenlet = False
8597
self.orig_sigint_handler = None
8698

8799
@property
88100
def running(self):
89-
"""Returns greenlet if code has been loaded greenlet has been started"""
101+
"""Returns greenlet if code has been loaded greenlet has been
102+
started"""
90103
return self.source and self.code_greenlet
91104

92105
def load_code(self, source):
93106
"""Prep code to be run"""
94-
assert self.source is None, "you shouldn't load code when some is already running"
107+
assert self.source is None, "you shouldn't load code when some is " \
108+
"already running"
95109
self.source = source
96110
self.code_greenlet = None
97111

@@ -126,7 +140,8 @@ def run_code(self, for_code=None):
126140

127141
logger.debug('request received from code was %r', request)
128142
if not issubclass(request, RequestFromCodeGreenlet):
129-
raise ValueError("Not a valid value from code greenlet: %r" % request)
143+
raise ValueError("Not a valid value from code greenlet: %r" %
144+
request)
130145
if request in [Wait, Refresh]:
131146
self.code_is_waiting = True
132147
if request == Refresh:
@@ -142,12 +157,14 @@ def run_code(self, for_code=None):
142157
raise SystemExitFromCodeGreenlet()
143158

144159
def sigint_handler(self, *args):
145-
"""SIGINT handler to use while code is running or request being fulfilled"""
160+
"""SIGINT handler to use while code is running or request being
161+
fulfilled"""
146162
if greenlet.getcurrent() is self.code_greenlet:
147163
logger.debug('sigint while running user code!')
148164
raise KeyboardInterrupt()
149165
else:
150-
logger.debug('sigint while fulfilling code request sigint handler running!')
166+
logger.debug('sigint while fulfilling code request sigint handler '
167+
'running!')
151168
self.sigint_happened_in_main_greenlet = True
152169

153170
def _blocking_run_code(self):
@@ -170,18 +187,22 @@ def request_from_main_greenlet(self, force_refresh=False):
170187
raise KeyboardInterrupt()
171188
return value
172189

190+
173191
class FakeOutput(object):
174192
def __init__(self, coderunner, on_write):
175193
self.coderunner = coderunner
176194
self.on_write = on_write
195+
177196
def write(self, *args, **kwargs):
178197
self.on_write(*args, **kwargs)
179198
return self.coderunner.request_from_main_greenlet(force_refresh=True)
199+
180200
def writelines(self, l):
181201
for s in l:
182202
self.write(s)
203+
183204
def flush(self):
184205
pass
206+
185207
def isatty(self):
186208
return True
187-

bpython/curtsiesfrontend/filewatch.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,3 @@ def on_any_event(self, event):
7676
paths = [path + '.py' for path in self.dirs[dirpath]]
7777
if event.src_path in paths:
7878
self.on_change(files_modified=[event.src_path])
79-
80-
if __name__ == '__main__':
81-
pass
82-

bpython/curtsiesfrontend/interaction.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
from bpython.curtsiesfrontend.events import RefreshRequestEvent
77
from bpython.curtsiesfrontend.manual_readline import edit_keys
88

9+
910
class StatusBar(BpythonInteraction):
1011
"""StatusBar and Interaction for Repl
1112
1213
Passing of control back and forth between calls that use interact api
13-
(notify, confirm, file_prompt) like bpython.Repl.write2file and events
14-
on the main thread happens via those calls and self.wait_for_request_or_notify.
14+
(notify, confirm, file_prompt) like bpython.Repl.write2file and events on
15+
the main thread happens via those calls and
16+
self.wait_for_request_or_notify.
1517
16-
Calling one of these three is required for the main thread to regain control!
18+
Calling one of these three is required for the main thread to regain
19+
control!
1720
1821
This is probably a terrible idea, and better would be rewriting this
1922
functionality in a evented or callback style, but trying to integrate
@@ -62,7 +65,8 @@ def message(self, msg, schedule_refresh=True):
6265
self.schedule_refresh(time.time() + self.message_time)
6366

6467
def _check_for_expired_message(self):
65-
if self._message and time.time() > self.message_start_time + self.message_time:
68+
if (self._message and
69+
time.time() > self.message_start_time + self.message_time):
6670
self._message = ''
6771

6872
def process_event(self, e):
@@ -73,15 +77,17 @@ def process_event(self, e):
7377
self.request_greenlet.switch()
7478
elif isinstance(e, events.PasteEvent):
7579
for ee in e.events:
76-
self.add_normal_character(ee if len(ee) == 1 else ee[-1]) #strip control seq
80+
# strip control seq
81+
self.add_normal_character(ee if len(ee) == 1 else ee[-1])
7782
elif e in ['<ESC>'] or isinstance(e, events.SigIntEvent):
7883
self.request_greenlet.switch(False)
7984
self.escape()
8085
elif e in edit_keys:
81-
self.cursor_offset_in_line, self._current_line = edit_keys[e](self.cursor_offset_in_line, self._current_line)
82-
elif e == "<Ctrl-c>": #TODO can this be removed?
86+
self.cursor_offset_in_line, self._current_line = edit_keys[e](
87+
self.cursor_offset_in_line, self._current_line)
88+
elif e == "<Ctrl-c>": # TODO can this be removed?
8389
raise KeyboardInterrupt()
84-
elif e == "<Ctrl-d>": #TODO this isn't a very intuitive behavior
90+
elif e == "<Ctrl-d>": # TODO this isn't a very intuitive behavior
8591
raise SystemExit()
8692
elif self.in_prompt and e in ("\n", "\r", "<Ctrl-j>", "Ctrl-m>"):
8793
line = self._current_line
@@ -93,15 +99,17 @@ def process_event(self, e):
9399
else:
94100
self.request_greenlet.switch(False)
95101
self.escape()
96-
else: # add normal character
102+
else: # add normal character
97103
self.add_normal_character(e)
98104

99105
def add_normal_character(self, e):
100-
if e == '<SPACE>': e = ' '
101-
if len(e) > 1: return
106+
if e == '<SPACE>':
107+
e = ' '
108+
if len(e) > 1:
109+
return
102110
self._current_line = (self._current_line[:self.cursor_offset_in_line] +
103-
e +
104-
self._current_line[self.cursor_offset_in_line:])
111+
e +
112+
self._current_line[self.cursor_offset_in_line:])
105113
self.cursor_offset_in_line += 1
106114

107115
def escape(self):
@@ -137,7 +145,8 @@ def notify(self, msg, n=3, wait_for_keypress=False):
137145
self.request_refresh()
138146
self.main_greenlet.switch(msg)
139147

140-
# below Really ought to be called from greenlets other than main because they block
148+
# below Really ought to be called from greenlets other than main because
149+
# they block
141150
def confirm(self, q):
142151
"""Expected to return True or False, given question prompt q"""
143152
self.request_greenlet = greenlet.getcurrent()

bpython/curtsiesfrontend/interpreter.py

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@
1414
from bpython.repl import RuntimeTimer
1515

1616
default_colors = {
17-
Generic.Error:'R',
18-
Keyword:'d',
19-
Name:'c',
20-
Name.Builtin:'g',
21-
Comment:'b',
22-
String:'m',
23-
Error:'r',
24-
Literal:'d',
25-
Number:'M',
26-
Number.Integer:'d',
27-
Operator:'d',
28-
Punctuation:'d',
29-
Token:'d',
30-
Whitespace:'d',
31-
Token.Punctuation.Parenthesis:'R',
32-
Name.Function:'d',
33-
Name.Class:'d',
34-
}
17+
Generic.Error: 'R',
18+
Keyword: 'd',
19+
Name: 'c',
20+
Name.Builtin: 'g',
21+
Comment: 'b',
22+
String: 'm',
23+
Error: 'r',
24+
Literal: 'd',
25+
Number: 'M',
26+
Number.Integer: 'd',
27+
Operator: 'd',
28+
Punctuation: 'd',
29+
Token: 'd',
30+
Whitespace: 'd',
31+
Token.Punctuation.Parenthesis: 'R',
32+
Name.Function: 'd',
33+
Name.Class: 'd'
34+
}
35+
3536

3637
class BPythonFormatter(Formatter):
37-
"""This is subclassed from the custom formatter for bpython.
38-
Its format() method receives the tokensource
39-
and outfile params passed to it from the
40-
Pygments highlight() method and slops
41-
them into the appropriate format string
42-
as defined above, then writes to the outfile
43-
object the final formatted string. This does not write real strings. It writes format string (FmtStr) objects.
38+
"""This is subclassed from the custom formatter for bpython. Its format()
39+
method receives the tokensource and outfile params passed to it from the
40+
Pygments highlight() method and slops them into the appropriate format
41+
string as defined above, then writes to the outfile object the final
42+
formatted string. This does not write real strings. It writes format string
43+
(FmtStr) objects.
4444
4545
See the Pygments source for more info; it's pretty
4646
straightforward."""
@@ -60,6 +60,7 @@ def format(self, tokensource, outfile):
6060
o += "%s\x03%s\x04" % (self.f_strings[token], text)
6161
outfile.write(parse(o.rstrip()))
6262

63+
6364
class Interp(code.InteractiveInterpreter):
6465
def __init__(self, locals=None):
6566
"""Constructor.
@@ -69,8 +70,8 @@ def __init__(self, locals=None):
6970
dictionary with key "__name__" set to "__console__" and key
7071
"__doc__" set to None.
7172
72-
We include an argument for the outfile to pass to the formatter for it to write to.
73-
73+
We include an argument for the outfile to pass to the formatter for it
74+
to write to.
7475
"""
7576
if locals is None:
7677
locals = {"__name__": "__console__", "__doc__": None}
@@ -111,7 +112,7 @@ def showsyntaxerror(self, filename=None):
111112
l = traceback.format_exception_only(type, value)
112113
tbtext = ''.join(l)
113114
lexer = get_lexer_by_name("pytb")
114-
self.format(tbtext,lexer)
115+
self.format(tbtext, lexer)
115116

116117
def showtraceback(self):
117118
"""Display the exception that just occurred.
@@ -149,7 +150,8 @@ def format(self, tbtext, lexer):
149150
traceback_code_formatter.format(cur_line, self.outfile)
150151
no_format_mode = False
151152
else:
152-
traceback_informative_formatter.format(cur_line, self.outfile)
153+
traceback_informative_formatter.format(cur_line,
154+
self.outfile)
153155
cur_line = []
154156
elif text == ' ' and cur_line == []:
155157
no_format_mode = True
@@ -164,9 +166,9 @@ def runsource(self, source, filename="<input>", symbol="single"):
164166
self, source, filename=filename, symbol=symbol)
165167

166168

167-
168169
def code_finished_will_parse(s, compiler):
169-
"""Returns a tuple of whether the buffer could be complete and whether it will parse
170+
"""Returns a tuple of whether the buffer could be complete and whether it
171+
will parse
170172
171173
True, True means code block is finished and no predicted parse error
172174
True, False means code block is finished because a parse error is predicted

0 commit comments

Comments
 (0)