Skip to content

Commit 935c849

Browse files
committed
Remove duplicate code
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent bb5c03e commit 935c849

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

bpython/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,12 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
19151915
return (exit_value, clirepl.getstdout())
19161916
else:
19171917
sys.path.insert(0, '')
1918-
clirepl.startup()
1918+
try:
1919+
clirepl.startup()
1920+
except OSError as e:
1921+
# Handle this with a proper error message.
1922+
if e.errno != errno.ENOENT:
1923+
raise
19191924

19201925
if banner is not None:
19211926
clirepl.write(banner)

bpython/curtsiesfrontend/repl.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,6 @@ def sigtstp_handler(self, signum, frame):
409409
self.after_suspend()
410410
self.__enter__()
411411

412-
def run_startup(self):
413-
"""
414-
Execute PYTHONSTARTUP file if it exits. Call this after front
415-
end-specific initialisation.
416-
"""
417-
filename = os.environ.get('PYTHONSTARTUP')
418-
if filename:
419-
with open(filename, 'r') as f:
420-
if py3:
421-
#TODO runsource has a new signature in PY3
422-
self.interp.runsource(f.read(), filename, 'exec')
423-
else:
424-
self.interp.runsource(f.read(), filename, 'exec')
425-
426412
def clean_up_current_line_for_exit(self):
427413
"""Called when trying to exit to prep for final paint"""
428414
logger.debug('unhighlighting paren for exit')
@@ -475,9 +461,10 @@ def process_control_event(self, e):
475461

476462
elif isinstance(e, bpythonevents.RunStartupFileEvent):
477463
try:
478-
self.run_startup()
464+
self.startup()
479465
except IOError as e:
480-
self.status_bar.message(_('Executing PYTHONSTARTUP failed: %s') % (str(e)))
466+
self.status_bar.message(
467+
_('Executing PYTHONSTARTUP failed: %s') % (str(e)))
481468

482469
elif isinstance(e, bpythonevents.UndoEvent):
483470
self.undo(n=e.n)

bpython/repl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
22-
#
2322

2423
from __future__ import with_statement
2524
import code
@@ -406,7 +405,7 @@ def startup(self):
406405
end-specific initialisation.
407406
"""
408407
filename = os.environ.get('PYTHONSTARTUP')
409-
if filename and os.path.isfile(filename):
408+
if filename:
410409
with open(filename, 'r') as f:
411410
if py3:
412411
self.interp.runsource(f.read(), filename, 'exec')

0 commit comments

Comments
 (0)