Skip to content

Commit 89523d4

Browse files
committed
Renamed PyscriptBridge to PyBridge
1 parent 3254626 commit 89523d4

5 files changed

Lines changed: 21 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
shortcuts dictionary into a tuple before creating `StatementParser`.
3434
* Renamed `Cmd.pyscript_name` to `Cmd.py_bridge_name`
3535
* Renamed `Cmd.pystate` to `Cmd.py_locals`
36+
* Renamed `PyscriptBridge` to `PyBridge`
3637

3738
## 0.9.14 (June 29, 2019)
3839
* Enhancements
@@ -124,7 +125,7 @@
124125
of a `cmd2` based app, you will need to update your code to use `.history.get(1).statement.raw` instead.
125126
* Removed internally used `eos` command that was used to keep track of when a text script's commands ended
126127
* Removed `cmd2` member called `_STOP_AND_EXIT` since it was just a boolean value that should always be True
127-
* Removed `cmd2` member called `_should_quit` since `PyscriptBridge` now handles this logic
128+
* Removed `cmd2` member called `_should_quit` since `PyBridge` now handles this logic
128129
* Removed support for `cmd.cmdqueue`
129130
* `allow_cli_args` is now an argument to __init__ instead of a `cmd2` class member
130131
* **Python 3.4 EOL notice**

cmd2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
from .cmd2 import Cmd, Statement, EmptyStatement, categorize
1616
from .cmd2 import with_argument_list, with_argparser, with_argparser_and_unknown_args, with_category
1717
from .constants import DEFAULT_SHORTCUTS
18-
from .pyscript_bridge import CommandResult
18+
from .py_bridge import CommandResult

cmd2/cmd2.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
415415
# Keeps track of typed command history in the Python shell
416416
self._py_history = []
417417

418-
# The name by which Python and IPython environments refer to the PyscriptBridge to call app commands
418+
# The name by which Python environments refer to the PyBridge to call app commands
419419
self.py_bridge_name = 'app'
420420

421421
# Defines app-specific variables/functions available in Python shells and pyscripts
@@ -1704,13 +1704,13 @@ def parseline(self, line: str) -> Tuple[str, str, str]:
17041704
statement = self.statement_parser.parse_command_only(line)
17051705
return statement.command, statement.args, statement.command_and_args
17061706

1707-
def onecmd_plus_hooks(self, line: str, pyscript_bridge_call: bool = False) -> bool:
1707+
def onecmd_plus_hooks(self, line: str, py_bridge_call: bool = False) -> bool:
17081708
"""Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks.
17091709
17101710
:param line: line of text read from input
1711-
:param pyscript_bridge_call: This should only ever be set to True by PyscriptBridge to signify the beginning
1712-
of an app() call in a pyscript. It is used to enable/disable the storage of the
1713-
command's stdout.
1711+
:param py_bridge_call: This should only ever be set to True by PyBridge to signify the beginning
1712+
of an app() call from Python. It is used to enable/disable the storage of the
1713+
command's stdout.
17141714
:return: True if running of commands should stop
17151715
"""
17161716
import datetime
@@ -1750,7 +1750,7 @@ def onecmd_plus_hooks(self, line: str, pyscript_bridge_call: bool = False) -> bo
17501750
try:
17511751
# Get sigint protection while we set up redirection
17521752
with self.sigint_protection:
1753-
if pyscript_bridge_call:
1753+
if py_bridge_call:
17541754
# Start saving command's stdout at this point
17551755
self.stdout.pause_storage = False
17561756

@@ -1799,7 +1799,7 @@ def onecmd_plus_hooks(self, line: str, pyscript_bridge_call: bool = False) -> bo
17991799
if not already_redirecting:
18001800
self._redirecting = False
18011801

1802-
if pyscript_bridge_call:
1802+
if py_bridge_call:
18031803
# Stop saving command's stdout before command finalization hooks run
18041804
self.stdout.pause_storage = True
18051805

@@ -3204,13 +3204,13 @@ def _restore_cmd2_env(self, cmd2_env: _SavedCmd2Env) -> None:
32043204
@with_argparser(py_parser, preserve_quotes=True)
32053205
def do_py(self, args: argparse.Namespace) -> bool:
32063206
"""Invoke Python command or shell"""
3207-
from .pyscript_bridge import PyscriptBridge
3207+
from .py_bridge import PyBridge
32083208
if self._in_py:
32093209
err = "Recursively entering interactive Python consoles is not allowed."
32103210
self.perror(err)
32113211
return False
32123212

3213-
bridge = PyscriptBridge(self)
3213+
bridge = PyBridge(self)
32143214

32153215
try:
32163216
self._in_py = True
@@ -3256,7 +3256,7 @@ def py_quit():
32563256
if args.remainder:
32573257
full_command += ' ' + ' '.join(args.remainder)
32583258

3259-
# Set cmd_echo to True so PyscriptBridge statements like: py app('help')
3259+
# Set cmd_echo to True so PyBridge statements like: py app('help')
32603260
# run at the command line will print their output.
32613261
bridge.cmd_echo = True
32623262

@@ -3339,7 +3339,7 @@ def do_run_pyscript(self, args: argparse.Namespace) -> bool:
33393339
@with_argparser(Cmd2ArgumentParser())
33403340
def do_ipy(self, _: argparse.Namespace) -> None:
33413341
"""Enter an interactive IPython shell"""
3342-
from .pyscript_bridge import PyscriptBridge
3342+
from .py_bridge import PyBridge
33433343
banner = ('Entering an embedded IPython shell. Type quit or <Ctrl>-d to exit.\n'
33443344
'Run Python code from external files with: run filename.py\n')
33453345
exit_msg = 'Leaving IPython, back to {}'.format(sys.argv[0])
@@ -3349,8 +3349,8 @@ def load_ipy(cmd2_app: Cmd):
33493349
Embed an IPython shell in an environment that is restricted to only the variables in this function
33503350
:param cmd2_app: the instance of the cmd2 app
33513351
"""
3352-
# Create a variable pointing to the PyscriptBridge and name it using the value of py_bridge_name
3353-
bridge = PyscriptBridge(cmd2_app)
3352+
# Create a variable pointing to a PyBridge and name it using the value of py_bridge_name
3353+
bridge = PyBridge(cmd2_app)
33543354
exec("{} = bridge".format(cmd2_app.py_bridge_name))
33553355

33563356
# Add self variable pointing to cmd2_app, if allowed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding=utf-8
22
"""
3-
Bridges calls made inside of a pyscript with the Cmd2 host app while maintaining a reasonable
3+
Bridges calls made inside of a Python environments to the Cmd2 host app while maintaining a reasonable
44
degree of isolation between the two
55
"""
66

@@ -53,7 +53,7 @@ def __bool__(self) -> bool:
5353
return not self.stderr
5454

5555

56-
class PyscriptBridge(object):
56+
class PyBridge(object):
5757
"""Provides a Python API wrapper for application commands."""
5858
def __init__(self, cmd2_app):
5959
self._cmd2_app = cmd2_app
@@ -70,7 +70,7 @@ def __dir__(self):
7070

7171
def __call__(self, command: str, echo: Optional[bool] = None) -> CommandResult:
7272
"""
73-
Provide functionality to call application commands by calling PyscriptBridge
73+
Provide functionality to call application commands by calling PyBridge
7474
ex: app('help')
7575
:param command: command line being run
7676
:param echo: if True, output will be echoed to stdout/stderr while the command runs
@@ -95,7 +95,7 @@ def __call__(self, command: str, echo: Optional[bool] = None) -> CommandResult:
9595
self._cmd2_app.stdout = copy_cmd_stdout
9696
with redirect_stdout(copy_cmd_stdout):
9797
with redirect_stderr(copy_stderr):
98-
stop = self._cmd2_app.onecmd_plus_hooks(command, pyscript_bridge_call=True)
98+
stop = self._cmd2_app.onecmd_plus_hooks(command, py_bridge_call=True)
9999
finally:
100100
with self._cmd2_app.sigint_protection:
101101
self._cmd2_app.stdout = copy_cmd_stdout.inner_stream

tests/pyscript/stop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
app.cmd_echo = True
33
app('help')
44

5-
# This will set stop to True in the PyscriptBridge
5+
# This will set stop to True in the PyBridge
66
app('quit')
77

88
# Exercise py_quit() in unit test

0 commit comments

Comments
 (0)