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>
(cherry picked from commit 7ea9a85f132b32347fcbd2cbe1b553a2e9890b56)
Co-authored-by: Timothy Hopper <tdhopper@users.noreply.github.com>
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index d03f1b2..16d245a 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1377,6 +1377,19 @@
if save_home is not None:
os.environ['HOME'] = save_home
+ def test_readrc_homedir(self):
+ save_home = os.environ.pop("HOME", None)
+ with support.temp_dir() as temp_dir, patch("os.path.expanduser"):
+ rc_path = os.path.join(temp_dir, ".pdbrc")
+ os.path.expanduser.return_value = rc_path
+ try:
+ with open(rc_path, "w") as f:
+ f.write("invalid")
+ self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
+ finally:
+ if save_home is not None:
+ os.environ["HOME"] = save_home
+
def test_header(self):
stdout = StringIO()
header = 'Nobody expects... blah, blah, blah'