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

Blank lines in .pth file cause a duplicate sys.path entry #77870

Closed
mhsmith mannequin opened this issue May 29, 2018 · 8 comments
Closed

Blank lines in .pth file cause a duplicate sys.path entry #77870

mhsmith mannequin opened this issue May 29, 2018 · 8 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@mhsmith
Copy link
Mannequin

mhsmith mannequin commented May 29, 2018

BPO 33689
Nosy @taleinat, @mhsmith, @ammaraskar, @idomic
PRs
  • bpo-33689: Blank lines in .pth file cause a duplicate sys.path entry #20679
  • 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 2020-09-19.19:14:49.996>
    created_at = <Date 2018-05-29.23:03:14.459>
    labels = ['type-bug', 'library', '3.10']
    title = 'Blank lines in .pth file cause a duplicate sys.path entry'
    updated_at = <Date 2020-09-19.19:14:49.993>
    user = 'https://github.com/mhsmith'

    bugs.python.org fields:

    activity = <Date 2020-09-19.19:14:49.993>
    actor = 'taleinat'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-09-19.19:14:49.996>
    closer = 'taleinat'
    components = ['Library (Lib)']
    creation = <Date 2018-05-29.23:03:14.459>
    creator = 'Malcolm Smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33689
    keywords = ['patch']
    message_count = 8.0
    messages = ['318137', '318201', '364185', '364235', '370824', '377181', '377183', '377184']
    nosy_count = 4.0
    nosy_names = ['taleinat', 'Malcolm Smith', 'ammar2', 'Ido Michael']
    pr_nums = ['20679']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33689'
    versions = ['Python 3.10']

    @mhsmith
    Copy link
    Mannequin Author

    mhsmith mannequin commented May 29, 2018

    The site module documentation says that in .pth files, "Blank lines and lines beginning with # are skipped.". However, the implementation does not actually skip blank lines. It then joins the empty string to the site-packages directory, resulting in the site-packages directory being added to sys.path a second time.

    Example:

    $ python -c 'import sys; print(sys.path)'
    ['', '/home/smith/.virtualenvs/foo/lib/python36.zip', '/home/smith/.virtualenvs/foo/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/site-packages']
    $ echo > /home/smith/.virtualenvs/foo/lib/python3.6/site-packages/test.pth
    $ python -c 'import sys; print(sys.path)'
    ['', '/home/smith/.virtualenvs/foo/lib/python36.zip', '/home/smith/.virtualenvs/foo/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/lib-dynload', '/usr/lib/python3.6', '/home/smith/.virtualenvs/foo/lib/python3.6/site-packages', '/home/smith/.virtualenvs/foo/lib/python3.6/site-packages']

    A patch fixing this is attached to bpo-29326, but was ignored when that issue turned out to be caused by something else.

    @mhsmith mhsmith mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 29, 2018
    @ammaraskar
    Copy link
    Member

    If this is actually an issue, and not just a documentation lapse I can create a pull request from my original patch.

    @mhsmith
    Copy link
    Mannequin Author

    mhsmith mannequin commented Mar 14, 2020

    It's definitely a bug and not a documentation lapse. There's no reason why blank lines should have that effect, and no indication in the code that this was intentional.

    @idomic
    Copy link
    Mannequin

    idomic mannequin commented Mar 15, 2020

    I can take this and have a PR

    @idomic
    Copy link
    Mannequin

    idomic mannequin commented Jun 6, 2020

    Created a PR: #64878

    I did see some of the changes are already in the code for example, test_underpth_nosite_file.test_sity.py already had pth_lines filter out: ''.

    I think it's because this issue relevant only for 3.6?
    Or maybe this issue was solved already and this bug report is redundant

    @taleinat
    Copy link
    Contributor

    This is certainly a bug fix, but since it may break backwards-compatibility in delicate ways, I'm not going to backport it to earlier versions. Expect this to land in 3.10.

    @taleinat
    Copy link
    Contributor

    New changeset 0c71a66 by idomic in branch 'master':
    bpo-33689: Blank lines in .pth file cause a duplicate sys.path entry (GH-20679)
    0c71a66

    @taleinat
    Copy link
    Contributor

    Thanks for bringing this up again Malcolm, for the original Patch Ammar, and for the work on the PR Ido!

    @taleinat taleinat added the 3.10 only security fixes label Sep 19, 2020
    @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
    3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants