Skip to content

Commit 1f54a15

Browse files
author
Sebastian Ramacher
committed
Check if twisted is available and report and error if that's not the case.
1 parent 9d397f6 commit 1f54a15

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

bpython/urwid.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,10 +1012,14 @@ def main(args=None, locals_=None, banner=None):
10121012
]))
10131013

10141014
if options.help_reactors:
1015-
from twisted.application import reactors
1016-
# Stolen from twisted.application.app (twistd).
1017-
for r in reactors.getReactorTypes():
1018-
print ' %-4s\t%s' % (r.shortName, r.description)
1015+
try:
1016+
from twisted.application import reactors
1017+
# Stolen from twisted.application.app (twistd).
1018+
for r in reactors.getReactorTypes():
1019+
print ' %-4s\t%s' % (r.shortName, r.description)
1020+
except ImportError:
1021+
sys.stderr.write('No reactors are available. Please install '
1022+
'twisted for reactor support.')
10191023
return
10201024

10211025
palette = [
@@ -1030,7 +1034,12 @@ def main(args=None, locals_=None, banner=None):
10301034
options.reactor = 'select'
10311035

10321036
if options.reactor:
1033-
from twisted.application import reactors
1037+
try:
1038+
from twisted.application import reactors
1039+
except ImportError:
1040+
sys.stderr.write('No reactors are available. Please install '
1041+
'twisted for reactor support.')
1042+
return
10341043
try:
10351044
# XXX why does this not just return the reactor it installed?
10361045
reactor = reactors.installReactor(options.reactor)
@@ -1053,8 +1062,14 @@ def main(args=None, locals_=None, banner=None):
10531062
locals_ = main_mod.__dict__
10541063

10551064
if options.plugin:
1056-
from twisted import plugin
1057-
from twisted.application import service
1065+
try:
1066+
from twisted import plugin
1067+
from twisted.application import service
1068+
except ImportError:
1069+
sys.stderr.write('No twisted plugins are available. Please install '
1070+
'twisted for twisted plugin support.')
1071+
return
1072+
10581073
for plug in plugin.getPlugins(service.IServiceMaker):
10591074
if plug.tapname == options.plugin:
10601075
break

0 commit comments

Comments
 (0)