8000 bpo-20523: pdb searches for .pdbrc in ~ instead of $HOME (GH-11847) · python/cpython@7ea9a85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ea9a85

Browse files
tdhopperaperiodic
authored andcommitted
bpo-20523: pdb searches for .pdbrc in ~ instead of $HOME (GH-11847)
Previously pdb checked the $HOME environmental variable to find the user .pdbrc. If $HOME is not set, the user .pdbrc would not be found. Change pdb to use `os.path.expanduser('~')` to determine the user's home directory. Thus, if $HOME is not set (as in tox or on Windows), os.path.expanduser('~') falls back on other techniques for locating the user's home directory. This follows pip's implementation for loading .piprc. Co-authored-by: Dan Lidral-Porter <dlp@aperiodic.org>
1 parent 8fbece1 commit 7ea9a85

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Lib/pdb.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,14 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
160160
self.allow_kbdint = False
161161
self.nosigint = nosigint
162162

163-
# Read $HOME/.pdbrc and ./.pdbrc
163+
# Read ~/.pdbrc and ./.pdbrc
164164
self.rcLines = []
165165
if readrc:
166-
if 'HOME' in os.environ:
167-
envHome = os.environ['HOME']
168-
try:
169-
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
170-
self.rcLines.extend(rcFile)
171-
except OSError:
172-
pass
166+
try:
167+
with open(os.path.expanduser('~/.pdbrc')) as rcFile:
168+
self.rcLines.extend(rcFile)
169+
except OSError:
170+
pass
173171
try:
174172
with open(".pdbrc") as rcFile:
175173
self.rcLines.extend(rcFile)

Lib/test/test_pdb.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,19 @@ def test_readrc_kwarg(self):
13771377
if save_home is not None:
13781378
os.environ['HOME'] = save_home
13791379

1380+
def test_readrc_homedir(self):
1381+
save_home = os.environ.pop("HOME", None)
1382+
with support.temp_dir() as temp_dir, patch("os.path.expanduser"):
1383+
rc_path = os.path.join(temp_dir, ".pdbrc")
1384+
os.path.expanduser.return_value = rc_path
1385+
try:
1386+
with open(rc_path, "w") as f:
1387+
f.write("invalid")
1388+
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
1389+
finally:
1390+
if save_home is not None:
1391+
os.environ["HOME"] = save_home
1392+
13801393
def test_header(self):
13811394
stdout = StringIO()
13821395
header = 'Nobody expects... blah, blah, blah'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``pdb.Pdb`` supports ~/.pdbrc in Windows 7. Patch by Tim Hopper and Dan
2+
Lidral-Porter.

0 commit comments

Comments
 (0)
0