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

Inconsistent sys.path between python and pdb #86550

Closed
hexagonrecursion mannequin opened this issue Nov 17, 2020 · 8 comments
Closed

Inconsistent sys.path between python and pdb #86550

hexagonrecursion mannequin opened this issue Nov 17, 2020 · 8 comments

Comments

@hexagonrecursion
Copy link
Mannequin

hexagonrecursion mannequin commented Nov 17, 2020

BPO 42384
Nosy @gvanrossum, @miss-islington, @hexagonrecursion
PRs
  • bpo-42384: pdb: correctly populate sys.path[0] #23338
  • [3.9] bpo-42384: pdb: correctly populate sys.path[0] (GH-23338) #24290
  • [3.8] bpo-42384: pdb: correctly populate sys.path[0] (GH-23338) #24291
  • [3.8] bpo-42384: pdb: correctly populate sys.path[0] (GH-23338) #24320
  • [3.9] bpo-42384: pdb: correctly populate sys.path[0] (GH-23338) #24321
  • bpo-42383: pdb: do not fail to restart the target if the current directory changed #23412
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-01-26.15:59:07.336>
    created_at = <Date 2020-11-17.07:46:41.774>
    labels = []
    title = 'Inconsistent sys.path between python and pdb'
    updated_at = <Date 2021-01-26.15:59:07.335>
    user = 'https://github.com/hexagonrecursion'

    bugs.python.org fields:

    activity = <Date 2021-01-26.15:59:07.335>
    actor = 'gvanrossum'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-26.15:59:07.336>
    closer = 'gvanrossum'
    components = []
    creation = <Date 2020-11-17.07:46:41.774>
    creator = 'hexagonrecursion'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42384
    keywords = ['patch']
    message_count = 8.0
    messages = ['381215', '381218', '381219', '385464', '385470', '385482', '385666', '385667']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'miss-islington', 'hexagonrecursion']
    pr_nums = ['23338', '24290', '24291', '24320', '24321', '23412']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42384'
    versions = []

    @hexagonrecursion
    Copy link
    Mannequin Author

    hexagonrecursion mannequin commented Nov 17, 2020

    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']

    @hexagonrecursion
    Copy link
    Mannequin Author

    hexagonrecursion mannequin commented Nov 17, 2020

    I'll look into fixing this after I fix bpo-42383

    @hexagonrecursion
    Copy link
    Mannequin Author

    hexagonrecursion mannequin commented Nov 17, 2020

    After reading Lib/pdb.py:main I believe I can fix both by changing a single line.

    @miss-islington
    Copy link
    Contributor

    New changeset 8603dfb by Andrey Bienkowski in branch 'master':
    bpo-42384: pdb: correctly populate sys.path[0] (GH-23338)
    8603dfb

    @gvanrossum
    Copy link
    Member

    Hey Andrey, this has been merged into 3.10, but the backports didn't work because the structure of the tests has changed (os_helper doesn't exist). Do you want to fix these?

    @hexagonrecursion
    Copy link
    Mannequin Author

    hexagonrecursion mannequin commented Jan 22, 2021

    I'll give it a try

    @gvanrossum
    Copy link
    Member

    New changeset f2df795 by Andrey Bienkowski in branch '3.9':
    [3.9] bpo-42384: pdb: correctly populate sys.path[0] (GH-23338) (bpo-24321)
    f2df795

    @gvanrossum
    Copy link
    Member

    New changeset c10180e by Andrey Bienkowski in branch '3.8':
    [3.8] bpo-42384: pdb: correctly populate sys.path[0] (GH-23338) (bpo-24320)
    c10180e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    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

    No branches or pull requests

    2 participants