Skip to content

Commit

Permalink
AUTHORS.rst file added.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanslenders committed Sep 29, 2014
1 parent efca3ea commit 200dc03
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
11 changes: 11 additions & 0 deletions AUTHORS.rst
@@ -0,0 +1,11 @@
Authors
=======

Creator
-------
Jonathan Slenders <jonathan AT slenders.be>

Contributors
------------

- Amjith Ramanujam <amjith.r AT gmail.com>
22 changes: 15 additions & 7 deletions bin/ptpython
Expand Up @@ -4,14 +4,16 @@ ptpython: Interactive Python shell.
Usage:
ptpython [ --vi ] [ --history=<filename> ] [ --no-colors ]
[ --autocompletion=<type> ] [ --always-multiline ]
[ --interactive=<filename> ]
ptpython -h | --help
Options:
--vi : Use Vi keybindings instead of Emacs bindings.
--history=<filename> : Path to history file.
--autocompletion=<type> : Type of autocompletion. This can be 'popup-menu'
or 'horizontal-menu'.
--always-multiline : Always enable multiline mode.
--vi : Use Vi keybindings instead of Emacs bindings.
--history=<filename> : Path to history file.
--autocompletion=<type> : Type of autocompletion. This can be 'popup-menu'
or 'horizontal-menu'.
--always-multiline : Always enable multiline mode.
--interactive=<filename> : Start interactive shell after executing this file.
Other environment variables:
PYTHONSTARTUP: file executed on interactive startup (no default)
Expand Down Expand Up @@ -52,12 +54,18 @@ def _run_repl():
always_multiline = bool(a['--always-multiline'])

# Startup path
startup_path = os.environ.get('PYTHONSTARTUP', None)
startup_paths = []
if 'PYTHONSTARTUP' in os.environ:
startup_paths.append(os.environ['PYTHONSTARTUP'])

# --interactive
if a['--interactive']:
startup_paths.append(a['--interactive'])

# Run interactive shell.
embed(globals_, locals_, vi_mode=vi_mode, history_filename=history_filename,
no_colors=no_colors, autocompletion_style=autocompletion_style,
startup_path=startup_path, always_multiline=always_multiline)
startup_paths=startup_paths, always_multiline=always_multiline)

if __name__ == '__main__':
_run_repl()
21 changes: 12 additions & 9 deletions prompt_toolkit/contrib/repl.py
Expand Up @@ -30,11 +30,13 @@


class PythonRepl(PythonCommandLineInterface):
def start_repl(self, startup_path=None):
def start_repl(self, startup_paths=None):
"""
Start the Read-Eval-Print Loop.
:param startup_paths: Array of paths to Python files.
"""
self._execute_startup(startup_path)
self._execute_startup(startup_paths)

# Run REPL loop until Exit.
try:
Expand All @@ -59,14 +61,15 @@ def start_repl(self, startup_path=None):
except Exit:
pass

def _execute_startup(self, startup_path):
def _execute_startup(self, startup_paths):
"""
Load and execute startup file.
"""
if startup_path:
with open(startup_path, 'r') as f:
code = compile(f.read(), startup_path, 'exec')
exec_(code, self.globals, self.locals)
if startup_paths:
for path in startup_paths:
with open(path, 'r') as f:
code = compile(f.read(), path, 'exec')
exec_(code, self.globals, self.locals)

def _execute(self, line):
"""
Expand Down Expand Up @@ -120,7 +123,7 @@ def _handle_keyboard_interrupt(self, e):


def embed(globals=None, locals=None, vi_mode=False, history_filename=None, no_colors=False,
autocompletion_style=AutoCompletionStyle.POPUP_MENU, startup_path=None, always_multiline=False):
autocompletion_style=AutoCompletionStyle.POPUP_MENU, startup_paths=None, always_multiline=False):
"""
Call this to embed Python shell at the current point in your program.
It's similar to `IPython.embed` and `bpython.embed`. ::
Expand All @@ -133,4 +136,4 @@ def embed(globals=None, locals=None, vi_mode=False, history_filename=None, no_co
cli = PythonRepl(globals, locals, vi_mode=vi_mode, history_filename=history_filename,
style=(None if no_colors else PythonStyle),
autocompletion_style=autocompletion_style, always_multiline=always_multiline)
cli.start_repl(startup_path=startup_path)
cli.start_repl(startup_paths=startup_paths)

0 comments on commit 200dc03

Please sign in to comment.