Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyproject.toml reading upon initialization raises KeyError exception #227

Closed
anjos opened this issue Apr 23, 2021 · 0 comments · Fixed by #228
Closed

pyproject.toml reading upon initialization raises KeyError exception #227

anjos opened this issue Apr 23, 2021 · 0 comments · Fixed by #228

Comments

@anjos
Copy link
Contributor

anjos commented Apr 23, 2021

Just started ipdb on a directory that happened to contain a pyproject.toml file inside to get a KeyError exception on tool.

To reproduce this problem, pip install the latest ipdb, create an empty pyproject.toml (n.b: it does not have to empty, it should just not contain any tool section) in the directory you are launching it, and then you will observe the crash (tested with ipdb 0.13.7):

$ pip install ipdb
$ mkdir tmp
$ cd tmp
$ touch pyproject.toml
$ touch test.py
$ python -m ipdb test.py
/Users/andre/conda/envs/bdt/lib/python3.8/runpy.py:127: RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))
Traceback (most recent call last):
  File "/Users/andre/conda/envs/bdt/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/andre/conda/envs/bdt/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/andre/conda/envs/bdt/lib/python3.8/site-packages/ipdb/__main__.py", line 323, in <module>
    main()
  File "/Users/andre/conda/envs/bdt/lib/python3.8/site-packages/ipdb/__main__.py", line 295, in main
    pdb = _init_pdb(commands=commands)
  File "/Users/andre/conda/envs/bdt/lib/python3.8/site-packages/ipdb/__main__.py", line 53, in _init_pdb
    context = os.getenv("IPDB_CONTEXT_SIZE", get_context_from_config())
  File "/Users/andre/conda/envs/bdt/lib/python3.8/site-packages/ipdb/__main__.py", line 84, in get_context_from_config
    parser = get_config()
  File "/Users/andre/conda/envs/bdt/lib/python3.8/site-packages/ipdb/__main__.py", line 181, in get_config
    if "ipdb" in toml_file["tool"]:
KeyError: 'tool'

Upon inspection, the code on line 181 could be better implemented and avoid this with something like:

if "ipdb" in toml_file.get("tool"):
    ....

I'll submit a PR in a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant