Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,22 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
# Read ~/.pdbrc and ./.pdbrc
self.rcLines = []
if readrc:
home_rcfile = os.path.expanduser("~/.pdbrc")
local_rcfile = os.path.abspath(".pdbrc")

try:
with open(os.path.expanduser('~/.pdbrc'), encoding='utf-8') as rcFile:
self.rcLines.extend(rcFile)
except OSError:
pass
try:
with open(".pdbrc", encoding='utf-8') as rcFile:
self.rcLines.extend(rcFile)
with open(home_rcfile, encoding='utf-8') as rcfile:
self.rcLines.extend(rcfile)
except OSError:
pass

if local_rcfile != home_rcfile:
try:
with open(local_rcfile, encoding='utf-8') as rcfile:
self.rcLines.extend(rcfile)
except OSError:
pass

self.commands = {} # associates a command list to breakpoint numbers
self.commands_defining = False # True while in the process of defining
# a command list
Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4050,6 +4050,23 @@ def test_readrc_homedir(self):
f.write("invalid")
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")

def test_readrc_current_dir(self):
with os_helper.temp_cwd() as cwd:
rc_path = os.path.join(cwd, ".pdbrc")
with open(rc_path, "w") as f:
f.write("invalid")
self.assertEqual(pdb.Pdb().rcLines[-1], "invalid")

def test_readrc_cwd_is_home(self):
with os_helper.EnvironmentVarGuard() as env:
env.unset("HOME")
with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"):
rc_path = os.path.join(cwd, ".pdbrc")
os.path.expanduser.return_value = rc_path
with open(rc_path, "w") as f:
f.write("invalid")
self.assertEqual(pdb.Pdb().rcLines, ["invalid"])

def test_header(self):
stdout = StringIO()
header = 'Nobody expects... blah, blah, blah'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue where ``pdb`` would read a ``.pdbrc`` twice if launched from the home directory
Loading