Issue 33689: Blank lines in .pth file cause a duplicate sys.path entry (original) (raw)

Created on 2018-05-29 23:03 by Malcolm Smith, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (8)

msg318137 - (view)

Author: Malcolm Smith (Malcolm Smith)

Date: 2018-05-29 23:03

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 issue 29326, but was ignored when that issue turned out to be caused by something else.

msg318201 - (view)

Author: Ammar Askar (ammar2) * (Python committer)

Date: 2018-05-30 17:08

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

msg364185 - (view)

Author: Malcolm Smith (Malcolm Smith)

Date: 2020-03-14 15:42

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.

msg364235 - (view)

Author: Ido Michael (Ido Michael) *

Date: 2020-03-15 14:49

I can take this and have a PR

msg370824 - (view)

Author: Ido Michael (Ido Michael) *

Date: 2020-06-06 14:17

Created a PR: GH-20679

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

msg377181 - (view)

Author: Tal Einat (taleinat) * (Python committer)

Date: 2020-09-19 18:52

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.

msg377183 - (view)

Author: Tal Einat (taleinat) * (Python committer)

Date: 2020-09-19 19:13

New changeset 0c71a66b53f6ea262aa5a60784c8c625ae0bb98c by idomic in branch 'master': bpo-33689: Blank lines in .pth file cause a duplicate sys.path entry (GH-20679) https://github.com/python/cpython/commit/0c71a66b53f6ea262aa5a60784c8c625ae0bb98c

msg377184 - (view)

Author: Tal Einat (taleinat) * (Python committer)

Date: 2020-09-19 19:14

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

History

Date

User

Action

Args

2022-04-11 14:59:01

admin

set

github: 77870

2020-09-19 19:14:49

taleinat

set

status: open -> closed
versions: + Python 3.10, - Python 3.6
messages: +

resolution: fixed
stage: patch review -> resolved

2020-09-19 19:13:36

taleinat

set

messages: +

2020-09-19 18:52:43

taleinat

set

messages: +

2020-06-06 14:17:11

Ido Michael

set

messages: +

2020-06-06 14:05:06

Ido Michael

set

keywords: + patch
stage: patch review
pull_requests: + <pull%5Frequest19893>

2020-06-06 13:49:38

Ido Michael

set

nosy: + taleinat

2020-03-15 14:49:37

Ido Michael

set

nosy: + Ido Michael
messages: +

2020-03-14 15:42:22

Malcolm Smith

set

messages: +

2018-05-30 17:08:38

ammar2

set

nosy: + ammar2
messages: +

2018-05-29 23:03:14

Malcolm Smith

create