Skip to content

Commit

Permalink
pw_system: Remove IPython from pw_system console
Browse files Browse the repository at this point in the history
- Remove the --ipython option from the pw_system console, since IPython
  is not well optimized for Pigweed.
- Describe how to embed IPython in the pw_console docs.

Change-Id: I80bfbbae395b022948117eb162ad0c7c6fa8ed09
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/218882
Pigweed-Auto-Submit: Wyatt Hepler <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Anthony DiGirolamo <[email protected]>
  • Loading branch information
255 authored and CQ Bot Account committed Jun 28, 2024
1 parent d6d285a commit d36dcb9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
23 changes: 23 additions & 0 deletions pw_console/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ logger. This logger can then be included as a log window pane in the


.. _Python's logging documentation: https://docs.python.org/3/library/logging.html#logging.Logger.debug

------------------------------
Embeddeding other interpreters
------------------------------
The Pigweed console is optimized for use with Pigweed, but other embedded Python
interpreters may be used to interact with Pigweed devices. Popular options
include `IPython <https://ipython.org/>`_ and `bpython
<https://bpython-interpreter.org/>`_.

Embedding IPython is similar to embedding ``pw_console``. After ``import
IPython``, call ``IPython.start_ipython()`` with the set of variables to expose
in the console. See `Embedding IPython
<https://ipython.readthedocs.io/en/stable/interactive/reference.html#embedding>`_
for details.

.. code-block:: python
IPython.start_ipython(
argv=[],
display_banner=False,
user_ns=local_variables,
)
return
1 change: 0 additions & 1 deletion pw_system/py/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ py_library(
"//pw_transfer/py:pw_transfer",
"//pw_unit_test:unit_test_py_pb2",
"//pw_unit_test/py:pw_unit_test",
"@python_packages_ipython//:pkg",
"@python_packages_pyserial//:pkg",
],
)
Expand Down
23 changes: 2 additions & 21 deletions pw_system/py/pw_system/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
python -m pw_system.console --device /dev/ttyUSB0 --proto-globs pw_rpc/echo.proto
This starts an IPython console for communicating with the connected device. A
few variables are predefined in the interactive console. These include:
This starts an interactive console for communicating with the connected device.
A few variables are predefined in the console. These include:
rpcs - used to invoke RPCs
device - the serial device used for communication
Expand Down Expand Up @@ -50,7 +50,6 @@
)

import serial
import IPython # type: ignore

from pw_cli import log as pw_cli_log
from pw_console import embed
Expand Down Expand Up @@ -205,12 +204,6 @@ def get_parser() -> argparse.ArgumentParser:
action='store_true',
help='Enables debug logging when set.',
)
parser.add_argument(
'--ipython',
action='store_true',
dest='use_ipython',
help='Use IPython instead of pw_console.',
)

parser.add_argument(
'--rpc-logging',
Expand Down Expand Up @@ -266,7 +259,6 @@ def _start_python_terminal( # pylint: disable=too-many-arguments
json_logfile: str,
serial_debug: bool = False,
config_file_path: Path | None = None,
use_ipython: bool = False,
) -> None:
"""Starts an interactive Python terminal with preset variables."""
local_variables = dict(
Expand Down Expand Up @@ -306,15 +298,6 @@ def _start_python_terminal( # pylint: disable=too-many-arguments
'\nJSON device logs are being saved to:\n ' + json_logfile
)

if use_ipython:
print(welcome_message)
IPython.start_ipython(
argv=[],
display_banner=False,
user_ns=local_variables,
)
return

client_info = device.info()
completions = flattened_rpc_completions([client_info])

Expand Down Expand Up @@ -369,7 +352,6 @@ def console(
compiled_protos: list[ModuleType] | None = None,
merge_device_and_host_logs: bool = False,
rpc_logging: bool = True,
use_ipython: bool = False,
channel_id: int = rpc.DEFAULT_CHANNEL_ID,
hdlc_encoding: bool = True,
device_tracing: bool = True,
Expand Down Expand Up @@ -576,7 +558,6 @@ def disconnect_handler(
json_logfile=json_logfile,
serial_debug=serial_debug,
config_file_path=config_file,
use_ipython=use_ipython,
)
return 0

Expand Down

0 comments on commit d36dcb9

Please sign in to comment.