classification
Title: Inconsistent sys.path between python and pdb
Type: Stage: patch review
Components: Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: hexagonrecursion
Priority: normal Keywords: patch

Created on 2020-11-17 07:46 by hexagonrecursion, last changed 2020-11-17 11:36 by hexagonrecursion.

Pull Requests
URL Status Linked Edit
PR 23338 open hexagonrecursion, 2020-11-17 11:36
Messages (3)
msg381215 - (view) Author: Andrey Bienkowski (hexagonrecursion) * Date: 2020-11-17 07:46
The first entry in sys.path is different between `python foo.py` and `python -m pdb foo.py`. In the former it is the absolute path to the parent directory of foo.py while in the later it is a relative path (unless the debug target was specified using an absolute path). The meaning of the absolute path does not change when the current directory changes (e.g. via os.chdir()) while the meaning of the relative path does. Like any environment inconsistency between regular program execution and the debugger this may lead to bugs that mysteriously vanish when you try to debug them.

$ cat > print-path.py
import sys
from pprint import pprint

pprint(sys.path)
$ python3 print-path.py 
['/home/user',
 '/usr/lib64/python38.zip',
 '/usr/lib64/python3.8',
 '/usr/lib64/python3.8/lib-dynload',
 '/usr/lib64/python3.8/site-packages',
 '/usr/lib/python3.8/site-packages']
$ python3 -m pdb print-path.py                                  
> /home/user/print-path.py(1)<module>()
-> import sys
(Pdb) c
['',
 '/usr/lib64/python38.zip',
 '/usr/lib64/python3.8',
 '/usr/lib64/python3.8/lib-dynload',
 '/usr/lib64/python3.8/site-packages',
 '/usr/lib/python3.8/site-packages']
msg381218 - (view) Author: Andrey Bienkowski (hexagonrecursion) * Date: 2020-11-17 07:51
I'll look into fixing this after I fix #42383
msg381219 - (view) Author: Andrey Bienkowski (hexagonrecursion) * Date: 2020-11-17 08:38
After reading Lib/pdb.py:main I believe I can fix both by changing a single line.
History
Date User Action Args
2020-11-17 11:36:57hexagonrecursionsetkeywords: + patch
stage: patch review
pull_requests: + pull_request22228
2020-11-17 08:38:57hexagonrecursionsetmessages: + msg381219
2020-11-17 07:51:14hexagonrecursionsetmessages: + msg381218
2020-11-17 07:46:41hexagonrecursioncreate