Skip to content

Commit

Permalink
Fail on invalid PUDB_TERM_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
max-arnold committed Jan 15, 2024
1 parent aaed267 commit 7ebe62b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 1 addition & 2 deletions doc/starting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ the terminal size:
#. ``PUDB_TERM_SIZE`` environment variable
#. Size of the terminal in which the debugged program is running
(as returned by ``os.get_terminal_size()``)
#. Default fallback value of ``(80, 20)`` if one of the previous steps
fails with an exception
#. Default fallback value of ``(80, 20)``

At this point, the debugger will look for a free port and wait for a telnet
connection::
Expand Down
11 changes: 7 additions & 4 deletions pudb/forked.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ def set_trace(paused=True, frame=None, term_size=None):
if frame is None:
frame = sys._getframe().f_back
if term_size is None:
try:
term_size = os.environ.get("PUDB_TERM_SIZE", "")
term_size = os.environ.get("PUDB_TERM_SIZE")
if term_size is not None:
term_size = tuple(map(int, term_size.split("x")))
if len(term_size) != 2:
raise ValueError("PUDB_TERM_SIZE should have two dimensions")
else:
try:
# Getting terminal size
s = os.get_terminal_size()
term_size = (s.columns, s.lines)
except Exception:
term_size = (80, 24)
except Exception:
term_size = (80, 24)

Debugger(
stdin=open("/dev/stdin"),
Expand Down
16 changes: 9 additions & 7 deletions pudb/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@

from pudb.debugger import Debugger

__all__ = ["PUDB_RDB_HOST", "PUDB_RDB_PORT", "PUDB_TERM_SIZE",
"default_port", "debugger", "set_trace",
__all__ = ["PUDB_RDB_HOST", "PUDB_RDB_PORT", "default_port", "debugger", "set_trace",
"debug_remote_on_single_rank"]

default_port = 6899

PUDB_RDB_HOST = os.environ.get("PUDB_RDB_HOST") or "127.0.0.1"
PUDB_RDB_PORT = int(os.environ.get("PUDB_RDB_PORT") or default_port)
PUDB_TERM_SIZE = os.environ.get("PUDB_TERM_SIZE", "")

#: Holds the currently active debugger.
_current = [None]
Expand Down Expand Up @@ -140,13 +138,17 @@ def __init__(
self.out = out

if term_size is None:
try:
term_size = tuple(map(int, PUDB_TERM_SIZE.split("x")))
term_size = os.environ.get("PUDB_TERM_SIZE")
if term_size is not None:
term_size = tuple(map(int, term_size.split("x")))
if len(term_size) != 2:
raise ValueError("PUDB_TERM_SIZE should have two dimensions")
else:
try:
s = os.get_terminal_size()
term_size = (s.columns, s.lines)
except Exception:
term_size = (80, 24)
except Exception:
term_size = (80, 24)

self._prev_handles = sys.stdin, sys.stdout
self._client, (address, port) = self.get_client(
Expand Down

0 comments on commit 7ebe62b

Please sign in to comment.