summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Slenders <jonathan@slenders.be>2014-09-29 12:22:31 +0200
committerJonathan Slenders <jonathan@slenders.be>2014-09-29 12:22:31 +0200
commit200dc03a90378c61c07f8b52a43e56c3751597ef (patch)
tree4ce0e8fcab8f1f22f596c5e948bff8226674b4e5
parentefca3eac494d7ffc66e1438a011380f4c8a22043 (diff)
AUTHORS.rst file added.
-rw-r--r--AUTHORS.rst11
-rwxr-xr-xbin/ptpython22
-rw-r--r--prompt_toolkit/contrib/repl.py21
3 files changed, 38 insertions, 16 deletions
diff --git a/AUTHORS.rst b/AUTHORS.rst
new file mode 100644
index 00000000..f7c8f60f
--- /dev/null
+++ b/AUTHORS.rst
@@ -0,0 +1,11 @@
+Authors
+=======
+
+Creator
+-------
+Jonathan Slenders <jonathan AT slenders.be>
+
+Contributors
+------------
+
+- Amjith Ramanujam <amjith.r AT gmail.com>
diff --git a/bin/ptpython b/bin/ptpython
index 83aa12df..2bc741a8 100755
--- a/bin/ptpython
+++ b/bin/ptpython
@@ -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)
@@ -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()
diff --git a/prompt_toolkit/contrib/repl.py b/prompt_toolkit/contrib/repl.py
index 85bcbaa7..1ea1af97 100644
--- a/prompt_toolkit/contrib/repl.py
+++ b/prompt_toolkit/contrib/repl.py
@@ -30,11 +30,13 @@ __all__ = ('PythonRepl', 'embed')
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:
@@ -59,14 +61,15 @@ class PythonRepl(PythonCommandLineInterface):
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):
"""
@@ -120,7 +123,7 @@ class PythonRepl(PythonCommandLineInterface):
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`. ::
@@ -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)