Skip to content

Commit

Permalink
Install as pdbpp.py (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed authored Nov 8, 2019
1 parent 37ee002 commit f95703d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run(self):
use_scm_version=True,
author='Antonio Cuni',
author_email='anto.cuni@gmail.com',
py_modules=['pdb', '_pdbpp_path_hack.pdb'],
py_modules=['pdbpp', '_pdbpp_path_hack.pdb'],
package_dir={"": "src"},
url='http://github.com/antocuni/pdb',
license='BSD',
Expand Down
8 changes: 7 additions & 1 deletion src/_pdbpp_path_hack/pdb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# this file is needed to hijack pdb without eggs
import os
import sys

if int(os.environ.get('PDBPP_HIJACK_PDB', 1)):
pdb_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'pdb.py')
pdb_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'pdbpp.py')
else:
# Use original pdb.
import code # arbitrary module which stays in the same dir as pdb
Expand All @@ -15,3 +16,8 @@

with open(pdb_path) as f:
exec(compile(f.read(), pdb_path, 'exec'))

# Update/set __file__ attribute to actually sourced file, but not when not coming
# here via "-m pdb", where __name__ is "__main__".
if __name__ != "__main__":
sys.modules["pdb"].__file__ = pdb_path
File renamed without changes.
14 changes: 13 additions & 1 deletion testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3563,11 +3563,23 @@ def test_python_m_pdb_usage():
@pytest.mark.parametrize('PDBPP_HIJACK_PDB', (1, 0))
def test_python_m_pdb_uses_pdbpp_and_env(PDBPP_HIJACK_PDB, monkeypatch, tmphome):
import subprocess
import textwrap

monkeypatch.setenv("PDBPP_HIJACK_PDB", str(PDBPP_HIJACK_PDB))

f = tmphome.ensure("test.py")
f.write("import os\n__import__('pdb').set_trace()")
f.write(textwrap.dedent("""
import inspect
import os
import pdb
fname = os.path.basename(inspect.getfile(pdb.Pdb))
if {PDBPP_HIJACK_PDB}:
assert fname == 'pdbpp.py', (fname, pdb, pdb.Pdb)
else:
assert fname == 'pdb.py', (fname, pdb, pdb.Pdb)
pdb.set_trace()
""".format(PDBPP_HIJACK_PDB=PDBPP_HIJACK_PDB)))

p = subprocess.Popen(
[sys.executable, "-m", "pdb", str(f)],
Expand Down

0 comments on commit f95703d

Please sign in to comment.