diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-20 16:19:04 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-20 16:19:04 -0400 |
commit | 89523d4fa0de91d5959497496dd4bc0a430da333 (patch) | |
tree | a6e45284d133bd839765ca26e937aec5308d887e | |
parent | 3254626f8d7c5a353b3f615fc80fa716006137fd (diff) | |
download | cmd2-git-89523d4fa0de91d5959497496dd4bc0a430da333.tar.gz |
Renamed PyscriptBridge to PyBridge
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | cmd2/__init__.py | 2 | ||||
-rw-r--r-- | cmd2/cmd2.py | 26 | ||||
-rw-r--r-- | cmd2/py_bridge.py (renamed from cmd2/pyscript_bridge.py) | 8 | ||||
-rw-r--r-- | tests/pyscript/stop.py | 2 |
5 files changed, 21 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ab396952..bdd0a10c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ shortcuts dictionary into a tuple before creating `StatementParser`. * Renamed `Cmd.pyscript_name` to `Cmd.py_bridge_name` * Renamed `Cmd.pystate` to `Cmd.py_locals` + * Renamed `PyscriptBridge` to `PyBridge` ## 0.9.14 (June 29, 2019) * Enhancements @@ -124,7 +125,7 @@ of a `cmd2` based app, you will need to update your code to use `.history.get(1).statement.raw` instead. * Removed internally used `eos` command that was used to keep track of when a text script's commands ended * Removed `cmd2` member called `_STOP_AND_EXIT` since it was just a boolean value that should always be True - * Removed `cmd2` member called `_should_quit` since `PyscriptBridge` now handles this logic + * Removed `cmd2` member called `_should_quit` since `PyBridge` now handles this logic * Removed support for `cmd.cmdqueue` * `allow_cli_args` is now an argument to __init__ instead of a `cmd2` class member * **Python 3.4 EOL notice** diff --git a/cmd2/__init__.py b/cmd2/__init__.py index 2b3bec5d..2653051a 100644 --- a/cmd2/__init__.py +++ b/cmd2/__init__.py @@ -15,4 +15,4 @@ from .argparse_custom import Cmd2ArgumentParser, CompletionItem from .cmd2 import Cmd, Statement, EmptyStatement, categorize from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category from .constants import DEFAULT_SHORTCUTS -from .pyscript_bridge import CommandResult +from .py_bridge import CommandResult diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index ae79339f..e810f809 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -415,7 +415,7 @@ class Cmd(cmd.Cmd): # Keeps track of typed command history in the Python shell self._py_history = [] - # The name by which Python and IPython environments refer to the PyscriptBridge to call app commands + # The name by which Python environments refer to the PyBridge to call app commands self.py_bridge_name = 'app' # Defines app-specific variables/functions available in Python shells and pyscripts @@ -1704,13 +1704,13 @@ class Cmd(cmd.Cmd): statement = self.statement_parser.parse_command_only(line) return statement.command, statement.args, statement.command_and_args - def onecmd_plus_hooks(self, line: str, pyscript_bridge_call: bool = False) -> bool: + def onecmd_plus_hooks(self, line: str, py_bridge_call: bool = False) -> bool: """Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks. :param line: line of text read from input - :param pyscript_bridge_call: This should only ever be set to True by PyscriptBridge to signify the beginning - of an app() call in a pyscript. It is used to enable/disable the storage of the - command's stdout. + :param py_bridge_call: This should only ever be set to True by PyBridge to signify the beginning + of an app() call from Python. It is used to enable/disable the storage of the + command's stdout. :return: True if running of commands should stop """ import datetime @@ -1750,7 +1750,7 @@ class Cmd(cmd.Cmd): try: # Get sigint protection while we set up redirection with self.sigint_protection: - if pyscript_bridge_call: + if py_bridge_call: # Start saving command's stdout at this point self.stdout.pause_storage = False @@ -1799,7 +1799,7 @@ class Cmd(cmd.Cmd): if not already_redirecting: self._redirecting = False - if pyscript_bridge_call: + if py_bridge_call: # Stop saving command's stdout before command finalization hooks run self.stdout.pause_storage = True @@ -3204,13 +3204,13 @@ class Cmd(cmd.Cmd): @with_argparser(py_parser, preserve_quotes=True) def do_py(self, args: argparse.Namespace) -> bool: """Invoke Python command or shell""" - from .pyscript_bridge import PyscriptBridge + from .py_bridge import PyBridge if self._in_py: err = "Recursively entering interactive Python consoles is not allowed." self.perror(err) return False - bridge = PyscriptBridge(self) + bridge = PyBridge(self) try: self._in_py = True @@ -3256,7 +3256,7 @@ class Cmd(cmd.Cmd): if args.remainder: full_command += ' ' + ' '.join(args.remainder) - # Set cmd_echo to True so PyscriptBridge statements like: py app('help') + # Set cmd_echo to True so PyBridge statements like: py app('help') # run at the command line will print their output. bridge.cmd_echo = True @@ -3339,7 +3339,7 @@ class Cmd(cmd.Cmd): @with_argparser(Cmd2ArgumentParser()) def do_ipy(self, _: argparse.Namespace) -> None: """Enter an interactive IPython shell""" - from .pyscript_bridge import PyscriptBridge + from .py_bridge import PyBridge banner = ('Entering an embedded IPython shell. Type quit or <Ctrl>-d to exit.\n' 'Run Python code from external files with: run filename.py\n') exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0]) @@ -3349,8 +3349,8 @@ class Cmd(cmd.Cmd): Embed an IPython shell in an environment that is restricted to only the variables in this function :param cmd2_app: the instance of the cmd2 app """ - # Create a variable pointing to the PyscriptBridge and name it using the value of py_bridge_name - bridge = PyscriptBridge(cmd2_app) + # Create a variable pointing to a PyBridge and name it using the value of py_bridge_name + bridge = PyBridge(cmd2_app) exec("{} = bridge".format(cmd2_app.py_bridge_name)) # Add self variable pointing to cmd2_app, if allowed diff --git a/cmd2/pyscript_bridge.py b/cmd2/py_bridge.py index ac3dfd40..9864b0ac 100644 --- a/cmd2/pyscript_bridge.py +++ b/cmd2/py_bridge.py @@ -1,6 +1,6 @@ # coding=utf-8 """ -Bridges calls made inside of a pyscript with the Cmd2 host app while maintaining a reasonable +Bridges calls made inside of a Python environments to the Cmd2 host app while maintaining a reasonable degree of isolation between the two """ @@ -53,7 +53,7 @@ class CommandResult(namedtuple_with_defaults('CommandResult', ['stdout', 'stderr return not self.stderr -class PyscriptBridge(object): +class PyBridge(object): """Provides a Python API wrapper for application commands.""" def __init__(self, cmd2_app): self._cmd2_app = cmd2_app @@ -70,7 +70,7 @@ class PyscriptBridge(object): def __call__(self, command: str, echo: Optional[bool] = None) -> CommandResult: """ - Provide functionality to call application commands by calling PyscriptBridge + Provide functionality to call application commands by calling PyBridge ex: app('help') :param command: command line being run :param echo: if True, output will be echoed to stdout/stderr while the command runs @@ -95,7 +95,7 @@ class PyscriptBridge(object): self._cmd2_app.stdout = copy_cmd_stdout with redirect_stdout(copy_cmd_stdout): with redirect_stderr(copy_stderr): - stop = self._cmd2_app.onecmd_plus_hooks(command, pyscript_bridge_call=True) + stop = self._cmd2_app.onecmd_plus_hooks(command, py_bridge_call=True) finally: with self._cmd2_app.sigint_protection: self._cmd2_app.stdout = copy_cmd_stdout.inner_stream diff --git a/tests/pyscript/stop.py b/tests/pyscript/stop.py index e731218e..1578b057 100644 --- a/tests/pyscript/stop.py +++ b/tests/pyscript/stop.py @@ -2,7 +2,7 @@ app.cmd_echo = True app('help') -# This will set stop to True in the PyscriptBridge +# This will set stop to True in the PyBridge app('quit') # Exercise py_quit() in unit test |