From 3326c0757c5a3229ec1576f19387871cd82f1556 Mon Sep 17 00:00:00 2001 From: Wouter Vanden Hove Date: Sun, 12 Mar 2023 02:56:41 +0100 Subject: [PATCH] blacken codebase --- HISTORY.txt | 14 ++++++------- ipdb/__init__.py | 6 +++--- ipdb/__main__.py | 50 +++++++++++++++++++++++++++----------------- pyproject.toml | 4 ++++ tests/test_config.py | 27 ++++++++++++------------ tests/test_import.py | 4 ++-- tests/test_opts.py | 34 +++++++++++++++--------------- 7 files changed, 78 insertions(+), 61 deletions(-) diff --git a/HISTORY.txt b/HISTORY.txt index 74d2830..62b0a1f 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -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) @@ -145,7 +145,7 @@ Changelog 0.12.1 (2019-07-26) ------------------- -- Fix --help +- Fix --help [native-api] @@ -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. @@ -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 @@ -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. diff --git a/ipdb/__init__.py b/ipdb/__init__.py index 75e8fed..65cc3b4 100644 --- a/ipdb/__init__.py +++ b/ipdb/__init__.py @@ -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 diff --git a/ipdb/__main__.py b/ipdb/__main__.py index fb1cd1c..c4b649a 100644 --- a/ipdb/__main__.py +++ b/ipdb/__main__.py @@ -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: @@ -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() @@ -110,7 +111,7 @@ def readline(self): try: return self.__next__() except StopIteration: - return '' + return "" # Python 2.7 (Newer dot versions) def next(self): @@ -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) @@ -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. @@ -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(): @@ -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: @@ -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: @@ -329,7 +338,7 @@ 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() @@ -337,9 +346,12 @@ class Restart(Exception): 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() diff --git a/pyproject.toml b/pyproject.toml index b1e1a46..b9a8d87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,6 @@ [build-system] requires = ["setuptools"] + + +[tool.black] +line-length = 88 diff --git a/tests/test_config.py b/tests/test_config.py index 4a44f85..e4fc7e7 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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): """ @@ -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")) @@ -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")) @@ -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): """ @@ -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")) @@ -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): """ diff --git a/tests/test_import.py b/tests/test_import.py index 7178d63..72bc193 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -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 diff --git a/tests/test_opts.py b/tests/test_opts.py index 6365d57..160fabd 100644 --- a/tests/test_opts.py +++ b/tests/test_opts.py @@ -17,10 +17,10 @@ from ipdb.__main__ import main -@patch('ipdb.__main__._get_debugger_cls') +@patch("ipdb.__main__._get_debugger_cls") class OptsTest(unittest.TestCase): def set_argv(self, *argv): - argv_patch = patch('ipdb.__main__.sys.argv', argv) + argv_patch = patch("ipdb.__main__.sys.argv", argv) argv_patch.start() self.addCleanup(argv_patch.stop) @@ -28,10 +28,10 @@ def set_argv(self, *argv): sys.version_info[0] == 3 and sys.version_info[1] >= 11, ">3.11 requires different test", ) - @patch('ipdb.__main__.sys.version_info', (3, 7)) + @patch("ipdb.__main__.sys.version_info", (3, 7)) def test_debug_module_script(self, get_debugger_cls): - module_name = 'my_buggy_module' - self.set_argv('ipdb', '-m', module_name) + module_name = "my_buggy_module" + self.set_argv("ipdb", "-m", module_name) main() @@ -42,10 +42,10 @@ def test_debug_module_script(self, get_debugger_cls): sys.version_info[0] == 3 and sys.version_info[1] >= 11, ">3.11 requires different test", ) - @patch('ipdb.__main__.os.path.exists') + @patch("ipdb.__main__.os.path.exists") def test_debug_script(self, exists, get_debugger_cls): - script_name = 'my_buggy_script' - self.set_argv('ipdb', script_name) + script_name = "my_buggy_script" + self.set_argv("ipdb", script_name) main() @@ -57,8 +57,8 @@ def test_debug_script(self, exists, get_debugger_cls): "<3.11 requires different test", ) def test_debug_module_script_3_11(self, get_debugger_cls): - module_name = 'my_buggy_module_3_11' - self.set_argv('ipdb', '-m', module_name) + module_name = "my_buggy_module_3_11" + self.set_argv("ipdb", "-m", module_name) main() @@ -69,10 +69,10 @@ def test_debug_module_script_3_11(self, get_debugger_cls): sys.version_info[0] != 3 or sys.version_info[1] < 11, "<3.11 requires different test", ) - @patch('ipdb.__main__.os.path.exists') + @patch("ipdb.__main__.os.path.exists") def test_debug_script_3_11(self, exists, get_debugger_cls): - script_name = 'my_buggy_script_3_11' - self.set_argv('ipdb', script_name) + script_name = "my_buggy_script_3_11" + self.set_argv("ipdb", script_name) main() @@ -80,13 +80,13 @@ def test_debug_script_3_11(self, exists, get_debugger_cls): debugger._run.assert_called_once_with(os.path.join(os.getcwd(), script_name)) def test_option_m_fallback_on_py36(self, get_debugger_cls): - self.set_argv('ipdb', '-m', 'my.module') - with patch('ipdb.__main__.sys.version_info', (3, 6)): + self.set_argv("ipdb", "-m", "my.module") + with patch("ipdb.__main__.sys.version_info", (3, 6)): with self.assertRaises(GetoptError): main() - with patch('ipdb.__main__.sys.version_info', (3, 7)): - self.set_argv('ipdb', '-m', 'my.module') + with patch("ipdb.__main__.sys.version_info", (3, 7)): + self.set_argv("ipdb", "-m", "my.module") try: main() except GetoptError: