Skip to content

Commit

Permalink
drgn.internal.repl: honor PYTHON_BASIC_REPL instead of our own enviro…
Browse files Browse the repository at this point in the history
…nment variable

Apparently the official Python interpreter has its own environment
variable for disabling the new REPL, so let's just reuse that instead of
defining our own.

Signed-off-by: Omar Sandoval <[email protected]>
  • Loading branch information
osandov committed Dec 16, 2024
1 parent 4006581 commit ecebeca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 8 additions & 7 deletions docs/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,20 @@ Some of drgn's behavior can be modified through environment variables:
Whether drgn should use libkdumpfile for ELF vmcores (0 or 1). The default
is 0. This functionality will be removed in the future.

``DRGN_USE_PYREPL``
Whether drgn should attempt to use the improved REPL (pyrepl) from Python
3.13. This provides colored output and multiline editing, among other
features. The default is 1. Unfortunately, Python has no public API to use
these features, so drgn must rely on internal implementation details. Set
this to 0 to disable this feature.

``DRGN_USE_SYS_MODULE``
Whether drgn should use ``/sys/module`` to find information about loaded
kernel modules for the running kernel instead of getting them from the core
dump (0 or 1). The default is 1. This environment variable is mainly
intended for testing and may be ignored in the future.

``PYTHON_BASIC_REPL``
If non-empty, don't try to use the `new interactive REPL
<https://docs.python.org/3/whatsnew/3.13.html#a-better-interactive-interpreter>`_
added in Python 3.13. drgn makes use of the new REPL through internal
implementation details since there is `not yet
<https://github.com/python/cpython/issues/119512>`_ a public API for it. If
it breaks, this may be used as an escape hatch.

.. _kernel-special-objects:

Linux Kernel Special Objects
Expand Down
7 changes: 4 additions & 3 deletions drgn/internal/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# in the "code" module. We'd like to give the best experience possible, so we'll
# detect _pyrepl and try to use it where possible.
try:
# Since this mucks with internals, add a knob that can be used to disable it
# and use the traditional REPL.
if os.environ.get("DRGN_USE_PYREPL") in ("0", "n", "N", "false", "False"):
# The official Python interpreter honors this environment variable to
# disable the new REPL. We do the same, which also gives users an escape
# hatch if any of the internals we're messing with change.
if os.environ.get("PYTHON_BASIC_REPL"):
raise ModuleNotFoundError()

# Unfortunately, the typeshed library behind mypy explicitly removed type
Expand Down

0 comments on commit ecebeca

Please sign in to comment.