From a3e9e4c5f17e337f4046106f34957750399acb84 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 8 Apr 2019 18:34:01 +0200 Subject: [PATCH 1/3] pdb: do not read .pdbrc twice when in $HOME --- Lib/pdb.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index f5d33c27fc1d91..1008b1c181a63e 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -162,18 +162,18 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, # Read $HOME/.pdbrc and ./.pdbrc self.rcLines = [] if readrc: + readrcFiles = [] if 'HOME' in os.environ: envHome = os.environ['HOME'] + readrcFiles.append(os.path.join(envHome, ".pdbrc")) + if not readrcFiles or envHome != os.getcwd(): + readrcFiles.append(".pdbrc") + for rcPath in readrcFiles: try: - with open(os.path.join(envHome, ".pdbrc")) as rcFile: + with open(rcPath) as rcFile: self.rcLines.extend(rcFile) except OSError: pass - try: - with open(".pdbrc") as rcFile: - self.rcLines.extend(rcFile) - except OSError: - pass self.commands = {} # associates a command list to breakpoint numbers self.commands_doprompt = {} # for each bp num, tells if the prompt From d867852982386faf55737e2da7fe860845b0d0c8 Mon Sep 17 00:00:00 2001 From: Xtreak Date: Mon, 15 Apr 2019 04:05:12 +0200 Subject: [PATCH 2/3] Add test_readrc_home_twice --- Lib/test/test_pdb.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 56d823249544ae..bc10ff3b91918f 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1337,6 +1337,33 @@ def test_readrc_kwarg(self): if save_home is not None: os.environ['HOME'] = save_home + def test_readrc_home_twice(self): + script = textwrap.dedent(""" + import pdb; pdb.Pdb(readrc=True).set_trace() + + print('hello') + """) + + with support.temp_cwd() as cur_dir: + with patch.dict(os.environ, {'HOME': cur_dir}): + with open('.pdbrc', 'w') as f: + f.write("invalid\n") + + with open('main.py', 'w') as f: + f.write(script) + + cmd = [sys.executable, 'main.py'] + proc = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + with proc: + stdout, stderr = proc.communicate(b'q\n') + output = stdout.decode() + self.assertEqual(output.count('NameError'), 1) + def test_header(self): stdout = StringIO() header = 'Nobody expects... blah, blah, blah' From 74f4a4fae1daa552fd1201be005c73b18176b3d5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 15 Apr 2019 04:09:11 +0200 Subject: [PATCH 3/3] news --- .../NEWS.d/next/Library/2019-04-15-04-09-04.bpo-36563.4x71uX.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-04-15-04-09-04.bpo-36563.4x71uX.rst diff --git a/Misc/NEWS.d/next/Library/2019-04-15-04-09-04.bpo-36563.4x71uX.rst b/Misc/NEWS.d/next/Library/2019-04-15-04-09-04.bpo-36563.4x71uX.rst new file mode 100644 index 00000000000000..eebc6f42dfcb4e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-04-15-04-09-04.bpo-36563.4x71uX.rst @@ -0,0 +1 @@ +.pdbrc is not read twice anymore when the current directory is $HOME.