Skip to content

Commit

Permalink
blacken codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Wouter Vanden Hove authored and gotcha committed Mar 13, 2023
1 parent ed766bf commit 3326c07
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 61 deletions.
14 changes: 7 additions & 7 deletions HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
0.13.14 (unreleased)
--------------------

- Nothing changed yet.
- Run ``black`` on ipdb-codebase with line-length 88. [WouterVH]


0.13.13 (2023-03-09)
Expand Down Expand Up @@ -145,7 +145,7 @@ Changelog
0.12.1 (2019-07-26)
-------------------

- Fix --help
- Fix --help
[native-api]


Expand Down Expand Up @@ -185,7 +185,7 @@ Changelog

- Ask IPython which debugger class to use.
Closes https://github.com/gotcha/ipdb/issues/105
[gnebehay, JBKahn]
[gnebehay, JBKahn]

- ipdb.set_trace() does not ignore context arg anymore.
Closes https://github.com/gotcha/ipdb/issues/93.
Expand Down Expand Up @@ -339,7 +339,7 @@ Changelog
----------------

- Add setuptools ``console_scripts`` entry point.
[akrito, gotcha]
[akrito, gotcha]

- Nose support.
Closes https://github.com/gotcha/ipdb/issues/8
Expand All @@ -360,12 +360,12 @@ Changelog
Closes https://github.com/gotcha/ipdb/issues/1
[gotcha]

- Fixed errors when exiting with "q".
- Fixed errors when exiting with "q".
[gotcha]

- Allow use of ``python -m ipdb mymodule.py``.
Python 2.7 only.
Closes https://github.com/gotcha/ipdb/issues/3
Python 2.7 only.
Closes https://github.com/gotcha/ipdb/issues/3
[gotcha]

- Fixed post_mortem when the traceback is None.
Expand Down
6 changes: 3 additions & 3 deletions ipdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Redistributable under the revised BSD license
# https://opensource.org/licenses/BSD-3-Clause

from ipdb.__main__ import set_trace, post_mortem, pm, run, iex # noqa
from ipdb.__main__ import set_trace, post_mortem, pm, run, iex # noqa
from ipdb.__main__ import runcall, runeval, launch_ipdb_on_exception # noqa

from ipdb.stdout import sset_trace, spost_mortem, spm # noqa
from ipdb.stdout import slaunch_ipdb_on_exception # noqa
from ipdb.stdout import sset_trace, spost_mortem, spm # noqa
from ipdb.stdout import slaunch_ipdb_on_exception # noqa
50 changes: 31 additions & 19 deletions ipdb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

from decorator import contextmanager

__version__ = '0.13.14.dev0'
__version__ = "0.13.14.dev0"

from IPython import get_ipython
from IPython.core.debugger import BdbQuit_excepthook
from IPython.terminal.ipapp import TerminalIPythonApp
from IPython.terminal.embed import InteractiveShellEmbed

try:
import configparser
except:
Expand Down Expand Up @@ -75,7 +76,7 @@ def set_trace(frame=None, context=None, cond=True):
if frame is None:
frame = sys._getframe().f_back
p = _init_pdb(context).set_trace(frame)
if p and hasattr(p, 'shell'):
if p and hasattr(p, "shell"):
p.shell.restore_sys_module_state()


Expand Down Expand Up @@ -110,7 +111,7 @@ def readline(self):
try:
return self.__next__()
except StopIteration:
return ''
return ""

# Python 2.7 (Newer dot versions)
def next(self):
Expand Down Expand Up @@ -170,21 +171,24 @@ def get_config():
parser.filepath = filepath
# Users are expected to put an [ipdb] section
# only if they use setup.cfg
if filepath.endswith('setup.cfg'):
if filepath.endswith("setup.cfg"):
with open(filepath) as f:
parser.remove_section("ipdb")
read_func(f)
# To use on pyproject.toml, put [tool.ipdb] section
elif filepath.endswith('pyproject.toml'):
elif filepath.endswith("pyproject.toml"):
try:
import tomllib

file_mode = "rb"
except ImportError:
try:
import tomli as tomllib

file_mode = "rb"
except ImportError:
import toml as tomllib

file_mode = "r"
with open(filepath, file_mode) as f:
toml_file = tomllib.load(f)
Expand Down Expand Up @@ -242,7 +246,8 @@ def launch_ipdb_on_exception():
iex = launch_ipdb_on_exception()


_usage = """\
_usage = (
"""\
usage: python -m ipdb [-m] [-c command] ... pyfile [arg] ...
Debug the Python program given by pyfile.
Expand All @@ -257,7 +262,9 @@ def launch_ipdb_on_exception():
Option -m is available only in Python 3.7 and later.
ipdb version %s.""" % __version__
ipdb version %s."""
% __version__
)


def main():
Expand All @@ -268,35 +275,36 @@ def main():
try:
from pdb import Restart
except ImportError:

class Restart(Exception):
pass

if sys.version_info >= (3, 7):
opts, args = getopt.getopt(sys.argv[1:], 'mhc:', ['help', 'command='])
opts, args = getopt.getopt(sys.argv[1:], "mhc:", ["help", "command="])
else:
opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['help', 'command='])
opts, args = getopt.getopt(sys.argv[1:], "hc:", ["help", "command="])

commands = []
run_as_module = False
for opt, optarg in opts:
if opt in ['-h', '--help']:
if opt in ["-h", "--help"]:
print(_usage)
sys.exit()
elif opt in ['-c', '--command']:
elif opt in ["-c", "--command"]:
commands.append(optarg)
elif opt in ['-m']:
elif opt in ["-m"]:
run_as_module = True

if not args:
print(_usage)
sys.exit(2)

mainpyfile = args[0] # Get script filename
mainpyfile = args[0] # Get script filename
if not run_as_module and not os.path.exists(mainpyfile):
print('Error:', mainpyfile, 'does not exist')
print("Error:", mainpyfile, "does not exist")
sys.exit(1)

sys.argv = args # Hide "pdb.py" from argument list
sys.argv = args # Hide "pdb.py" from argument list

# Replace pdb's dir with script's dir in front of module search path.
if not run_as_module:
Expand All @@ -310,6 +318,7 @@ class Restart(Exception):
while 1:
try:
import pdb as stdlib_pdb

if hasattr(stdlib_pdb.Pdb, "_run"):
# Looks like Pdb from Python 3.11+
if run_as_module:
Expand All @@ -329,17 +338,20 @@ class Restart(Exception):
print("\t" + " ".join(sys.argv[1:]))
except SystemExit:
# In most cases SystemExit does not warrant a post-mortem session.
print("The program exited via sys.exit(). Exit status: ", end='')
print("The program exited via sys.exit(). Exit status: ", end="")
print(sys.exc_info()[1])
except:
traceback.print_exc()
print("Uncaught exception. Entering post mortem debugging")
print("Running 'cont' or 'step' will restart the program")
t = sys.exc_info()[2]
pdb.interaction(None, t)
print("Post mortem debugger finished. The " + mainpyfile +
" will be restarted")
print(
"Post mortem debugger finished. The "
+ mainpyfile
+ " will be restarted"
)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[build-system]
requires = ["setuptools"]


[tool.black]
line-length = 88
27 changes: 14 additions & 13 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ def test_env_nodef_nosetup(self):
os.unlink(self.default_filename)
os.unlink(self.pyproject_filename)
os.remove(self.setup_filename)
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename,
HOME=self.tmpd):
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename, HOME=self.tmpd):
cfg = get_config()
self.assertEqual(["ipdb"], cfg.sections())
self.assertEqual(self.env_context, cfg.getint("ipdb", "context"))
self.assertRaises(configparser.NoOptionError, cfg.getboolean, "ipdb", "version")
self.assertRaises(
configparser.NoOptionError, cfg.getboolean, "ipdb", "version"
)

def test_noenv_def_nosetup(self):
"""
Expand Down Expand Up @@ -243,8 +244,7 @@ def test_env_cwd(self):
os.chdir(self.tmpd) # setUp is already set to restore us to our pre-testing cwd
os.unlink(self.pyproject_filename)
os.remove(self.setup_filename)
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename,
HOME=self.tmpd):
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename, HOME=self.tmpd):
cfg = get_config()
self.assertEqual(["ipdb"], cfg.sections())
self.assertEqual(self.env_context, cfg.getint("ipdb", "context"))
Expand All @@ -258,8 +258,7 @@ def test_env_def_nosetup(self):
"""
os.unlink(self.pyproject_filename)
os.remove(self.setup_filename)
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename,
HOME=self.tmpd):
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename, HOME=self.tmpd):
cfg = get_config()
self.assertEqual(["ipdb"], cfg.sections())
self.assertEqual(self.env_context, cfg.getint("ipdb", "context"))
Expand All @@ -277,7 +276,9 @@ def test_noenv_def_setup(self):
cfg = get_config()
self.assertEqual(["ipdb"], cfg.sections())
self.assertEqual(self.default_context, cfg.getint("ipdb", "context"))
self.assertRaises(configparser.NoOptionError, cfg.getboolean, "ipdb", "version")
self.assertRaises(
configparser.NoOptionError, cfg.getboolean, "ipdb", "version"
)

def test_noenv_nodef_setup(self):
"""
Expand All @@ -301,8 +302,7 @@ def test_env_def_setup(self):
Result: load $IPDB_CONFIG
"""
os.unlink(self.pyproject_filename)
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename,
HOME=self.tmpd):
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename, HOME=self.tmpd):
cfg = get_config()
self.assertEqual(["ipdb"], cfg.sections())
self.assertEqual(self.env_context, cfg.getint("ipdb", "context"))
Expand All @@ -316,12 +316,13 @@ def test_env_nodef_setup(self):
"""
os.unlink(self.default_filename)
os.unlink(self.pyproject_filename)
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename,
HOME=self.tmpd):
with ModifiedEnvironment(IPDB_CONFIG=self.env_filename, HOME=self.tmpd):
cfg = get_config()
self.assertEqual(["ipdb"], cfg.sections())
self.assertEqual(self.env_context, cfg.getint("ipdb", "context"))
self.assertRaises(configparser.NoOptionError, cfg.getboolean, "ipdb", "version")
self.assertRaises(
configparser.NoOptionError, cfg.getboolean, "ipdb", "version"
)

def test_noenv_def_setup(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@


class ImportTest(unittest.TestCase):

def test_import(self):
from ipdb import set_trace, post_mortem, pm, iex, run, runcall, runeval

set_trace # please pyflakes
post_mortem # please pyflakes
pm # please pyflakes
iex # please pyflakes
iex # please pyflakes
run # please pyflakes
runcall # please pyflakes
runeval # please pyflakes
Loading

0 comments on commit 3326c07

Please sign in to comment.