Skip to content

Inconsistent sys.path between python and pdb #86550

Closed

Description

@hexagonrecursion
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 = []

    Activity

    1. hexagonrecursion commented on Nov 17, 2020

      hexagonrecursionmannequin
      MannequinAuthor

      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']
    2. hexagonrecursion commented on Nov 17, 2020

      hexagonrecursionmannequin
      MannequinAuthor

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

    3. hexagonrecursion commented on Nov 17, 2020

      hexagonrecursionmannequin
      MannequinAuthor

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

    4. miss-islington commented on Jan 22, 2021

      @miss-islington
      Contributor

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

    5. gvanrossum commented on Jan 22, 2021

      @gvanrossum
      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?

    6. hexagonrecursion commented on Jan 22, 2021

      hexagonrecursionmannequin
      MannequinAuthor

      I'll give it a try

    7. gvanrossum commented on Jan 25, 2021

      @gvanrossum
      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

    8. gvanrossum commented on Jan 25, 2021

      @gvanrossum
      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

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions