Skip to content

Commit 634b9a0

Browse files
committed
REPOFIX: Revert to before bpdb branch
1 parent 3f737f5 commit 634b9a0

28 files changed

+1120
-142
lines changed

AUTHORS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ bpython is written and maintained by Bob Farrell and Andreas Stuehrk
66
Other contributors are (in alphabetical order):
77

88
* Federico Ceratto <federico dot ceratto at gmail dot com>
9-
* Łukasz Langa <lukasz at langa dot pl>
109
* Pavel Panchekha <pavpanchekha at gmail dot com>
1110
* Simon de Vlieger <simon at ikanobori dot jp>
12-
11+
* Marien Zwart <marien dot zwart at gmail dot com>
1312

1413
Many thanks for all contributions!

ROADMAP

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ bpython.gtk_
2222

2323
common
2424
- test suite
25+
26+
v1.0
27+
----
28+
- Ditch curses for an urwid/twisted loop

TODO

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bpython.gtk_
2+
- make font configurable (pango.FontDescription)
3+
- make gtk have a seperate config/theme from the cli version
4+
5+
bpython.urwid
6+
7+
bpython.cli

bpdb/__init__.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

bpdb/debugger.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

bpython/args.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77
import sys
88
import code
99
from optparse import OptionParser, OptionGroup
10-
from itertools import takewhile
1110

1211
from bpython import __version__
1312
from bpython.config import loadini, Struct, migrate_rc
1413

14+
15+
class OptionParserFailed(ValueError):
16+
"""Raised by the RaisingOptionParser for a bogus commandline."""
17+
18+
19+
class RaisingOptionParser(OptionParser):
20+
def error(self, msg):
21+
raise OptionParserFailed()
22+
23+
1524
def parse(args, extras=None):
1625
"""Receive an argument list - if None, use sys.argv - parse all args and
1726
take appropriate action. Also receive optional extra options: this should
@@ -39,10 +48,16 @@ def parse(args, extras=None):
3948
if args is None:
4049
args = sys.argv[1:]
4150

42-
parser = OptionParser(usage='Usage: %prog [options] [file [args]]\n'
43-
'NOTE: If bpython sees an argument it does '
44-
'not know, execution falls back to the '
45-
'regular Python interpreter.')
51+
parser = RaisingOptionParser(
52+
usage='Usage: %prog [options] [file [args]]\n'
53+
'NOTE: If bpython sees an argument it does '
54+
'not know, execution falls back to the '
55+
'regular Python interpreter.')
56+
# This is not sufficient if bpython gains its own -m support
57+
# (instead of falling back to Python itself for that).
58+
# That's probably fixable though, for example by having that
59+
# option swallow all remaining arguments in a callback.
60+
parser.disable_interspersed_args()
4661
parser.add_option('--config', '-c', default='~/.bpython/config',
4762
help='use CONFIG instead of default config file')
4863
parser.add_option('--interactive', '-i', action='store_true',
@@ -59,17 +74,11 @@ def parse(args, extras=None):
5974
extras_group.add_option(option)
6075
parser.add_option_group(extras_group)
6176

62-
all_args = set(parser._short_opt.keys() + parser._long_opt.keys())
63-
if args and not all_args.intersection(arg.split('=')[0] for arg in args):
77+
try:
78+
options, args = parser.parse_args(args)
79+
except OptionParserFailed:
6480
# Just let Python handle this
6581
os.execv(sys.executable, [sys.executable] + args)
66-
else:
67-
# Split args in bpython args and args for the executed file
68-
real_args = list(takewhile(lambda arg: arg.split('=')[0] in all_args,
69-
args))
70-
exec_args = args[len(real_args):]
71-
72-
options, args = parser.parse_args(real_args)
7382

7483
if options.version:
7584
print 'bpython version', __version__,
@@ -91,7 +100,7 @@ def parse(args, extras=None):
91100

92101
loadini(config, options.config)
93102

94-
return config, options, exec_args
103+
return config, options, args
95104

96105
def exec_code(interpreter, args):
97106
"""

bpython/cli.py

100644100755
Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def make_colors(config):
237237
class CLIRepl(Repl):
238238

239239
def __init__(self, scr, interp, statusbar, config, idle=None):
240-
Repl.__init__(self, interp, config, idle)
240+
Repl.__init__(self, interp, config)
241241
interp.writetb = self.writetb
242242
self.scr = scr
243243
self.list_win = newwin(get_colpair(config, 'background'), 1, 1, 1, 1)
@@ -250,6 +250,7 @@ def __init__(self, scr, interp, statusbar, config, idle=None):
250250
self.last_key_press = time.time()
251251
self.s = ''
252252
self.statusbar = statusbar
253+
self.formatter = BPythonFormatter(config.color_scheme)
253254

254255
def addstr(self, s):
255256
"""Add a string to the current input line and figure out
@@ -833,6 +834,10 @@ def p_key(self, key):
833834
elif key == 'KEY_BTAB':
834835
return self.tab(back=True)
835836

837+
elif key in key_dispatch[config.suspend_key]:
838+
self.suspend()
839+
return ''
840+
836841
elif len(key) == 1 and not unicodedata.category(key) == 'Cc':
837842
self.addstr(key)
838843
self.print_line(self.s)
@@ -855,8 +860,7 @@ def print_line(self, s, clr=False, newline=False):
855860
self.highlighted_paren = None
856861

857862
if self.config.syntax and (not self.paste_mode or newline):
858-
o = format(self.tokenize(s, newline),
859-
BPythonFormatter(self.config.color_scheme))
863+
o = format(self.tokenize(s, newline), self.formatter)
860864
else:
861865
o = s
862866

@@ -1096,20 +1100,24 @@ def lsize():
10961100
if v_items:
10971101
self.list_win.addstr('\n ')
10981102

1103+
if not py3:
1104+
encoding = getpreferredencoding()
10991105
for ix, i in enumerate(v_items):
11001106
padding = (wl - len(i)) * ' '
11011107
if i == current_item:
11021108
color = get_colpair(self.config, 'operator')
11031109
else:
11041110
color = get_colpair(self.config, 'main')
11051111
if not py3:
1106-
i = i.encode(getpreferredencoding())
1112+
i = i.encode(encoding)
11071113
self.list_win.addstr(i + padding, color)
11081114
if ((cols == 1 or (ix and not (ix + 1) % cols))
11091115
and ix + 1 < len(v_items)):
11101116
self.list_win.addstr('\n ')
11111117

11121118
if self.docstring is not None:
1119+
if not py3:
1120+
docstring_string = docstring_string.encode(encoding, 'ignore')
11131121
self.list_win.addstr('\n' + docstring_string,
11141122
get_colpair(self.config, 'comment'))
11151123
# XXX: After all the trouble I had with sizing the list box (I'm not very good
@@ -1142,6 +1150,11 @@ def size(self):
11421150
self.h = h - 1
11431151
self.x = 0
11441152

1153+
def suspend(self):
1154+
"""Suspend the current process for shell job control."""
1155+
curses.endwin()
1156+
os.kill(os.getpid(), signal.SIGSTOP)
1157+
11451158
def tab(self, back=False):
11461159
"""Process the tab key being hit. If there's only whitespace
11471160
in the line or the line is blank then process a normal tab,
@@ -1403,6 +1416,10 @@ def sigwinch(unused_scr):
14031416
global DO_RESIZE
14041417
DO_RESIZE = True
14051418

1419+
def sigcont(unused_scr):
1420+
sigwinch(unused_scr)
1421+
# Forces the redraw
1422+
curses.ungetch('')
14061423

14071424
def gethw():
14081425
"""I found this code on a usenet post, and snipped out the bit I needed,
@@ -1522,9 +1539,10 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
15221539
global colors
15231540
DO_RESIZE = False
15241541

1525-
# FIXME: Handle window resize without signals
1526-
#old_sigwinch_handler = signal.signal(signal.SIGWINCH,
1527-
# lambda *_: sigwinch(scr))
1542+
old_sigwinch_handler = signal.signal(signal.SIGWINCH,
1543+
lambda *_: sigwinch(scr))
1544+
# redraw window after being suspended
1545+
old_sigcont_handler = signal.signal(signal.SIGCONT, lambda *_: sigcont(scr))
15281546

15291547
stdscr = scr
15301548
try:
@@ -1577,9 +1595,9 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
15771595
statusbar.win.refresh()
15781596
curses.raw(False)
15791597

1580-
# Restore SIGWINCH handler
1581-
# FIXME: handle window resizes without signals
1582-
# signal.signal(signal.SIGWINCH, old_sigwinch_handler)
1598+
# Restore signal handlers
1599+
signal.signal(signal.SIGWINCH, old_sigwinch_handler)
1600+
signal.signal(signal.SIGCONT, old_sigcont_handler)
15831601

15841602
return repl.getstdout()
15851603

@@ -1612,6 +1630,7 @@ def main(args=None, locals_=None, banner=None):
16121630

16131631

16141632
if __name__ == '__main__':
1633+
from bpython.cli import main
16151634
main()
16161635

16171636
# vim: sw=4 ts=4 sts=4 ai et

bpython/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ def loadini(struct, configfile):
6262
'pastebin': 'F8',
6363
'save': 'C-s',
6464
'show_source': 'F2',
65+
'suspend': 'C-z',
6566
'undo': 'C-r',
6667
'up_one_line': 'C-p',
67-
'yank_from_buffer': 'C-y'}})
68+
'yank_from_buffer': 'C-y'},
69+
'gtk': {
70+
'font': 'monospace 10'}})
6871
config.read(config_path)
6972

7073
struct.dedent_after = config.getint('general', 'dedent_after')
@@ -82,6 +85,7 @@ def loadini(struct, configfile):
8285
struct.pastebin_key = config.get('keyboard', 'pastebin')
8386
struct.save_key = config.get('keyboard', 'save')
8487
struct.show_source_key = config.get('keyboard', 'show_source')
88+
struct.suspend_key = config.get('keyboard', 'suspend')
8589
struct.undo_key = config.get('keyboard', 'undo')
8690
struct.up_one_line_key = config.get('keyboard', 'up_one_line')
8791
struct.down_one_line_key = config.get('keyboard', 'down_one_line')
@@ -99,6 +103,8 @@ def loadini(struct, configfile):
99103
struct.pastebin_url = config.get('general', 'pastebin_url')
100104
struct.pastebin_show_url = config.get('general', 'pastebin_show_url')
101105

106+
struct.gtk_font = config.get('gtk', 'font')
107+
102108
color_scheme_name = config.get('general', 'color_scheme')
103109

104110
default_colors = {

bpython/formatter.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@ class BPythonFormatter(Formatter):
8383
See the Pygments source for more info; it's pretty
8484
straightforward."""
8585

86-
f_strings = {}
87-
8886
def __init__(self, color_scheme, **options):
89-
if not self.f_strings:
90-
for k, v in theme_map.iteritems():
91-
self.f_strings[k] = '\x01%s' % (color_scheme[v],)
92-
if k is Parenthesis:
93-
# FIXME: Find a way to make this the inverse of the current
94-
# background colour
95-
self.f_strings[k] += 'I'
87+
self.f_strings = {}
88+
for k, v in theme_map.iteritems():
89+
self.f_strings[k] = '\x01%s' % (color_scheme[v],)
90+
if k is Parenthesis:
91+
# FIXME: Find a way to make this the inverse of the current
92+
# background colour
93+
self.f_strings[k] += 'I'
9694
Formatter.__init__(self, **options)
9795

9896
def format(self, tokensource, outfile):

bpython/gtk_.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def __init__(self, interpreter, config):
260260
interpreter.writetb = self.writetb
261261
self.editing = Nested()
262262
self.reset_indent = False
263-
self.modify_font(pango.FontDescription('terminus'))
263+
self.modify_font(pango.FontDescription(self.config.gtk_font))
264264
self.set_wrap_mode(gtk.WRAP_CHAR)
265265
self.list_win = SuggestionWindow()
266266
self.list_win.connect('selection-changed',
@@ -695,4 +695,5 @@ def main(args=None):
695695

696696

697697
if __name__ == '__main__':
698+
from bpython.gtk_ import main
698699
main()

0 commit comments

Comments
 (0)