Issue 33689: Blank lines in .pth file cause a duplicate sys.path entry
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
Date: 2018-05-30 17:08
Date: 2020-09-19 18:52
Date: 2020-09-19 19:13
Date: 2020-09-19 19:14
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) *
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 PRmsg370824 - (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 redundantmsg377181 - (view) Author: Tal Einat (taleinat) *
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) *
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/0c71a66b53f6ea262aa5a60784c8c625ae0bb98cmsg377184 - (view) Author: Tal Einat (taleinat) *
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:01adminsetgithub: 77870
2020-09-19 19:14:49taleinatsetstatus: open -> closed
versions: + Python 3.10, - Python 3.6
messages: + msg377184
stage: patch review
pull_requests: + pull_request19893 2020-06-06 13:49:38Ido Michaelsetnosy: + taleinat
2020-03-15 14:49:37Ido Michaelsetnosy: + Ido Michael
messages: + msg364235
2020-03-14 15:42:22Malcolm Smithsetmessages: + msg364185 2018-05-30 17:08:38ammar2setnosy: + ammar2
messages: + msg318201
2018-05-29 23:03:14Malcolm Smithcreate
versions: + Python 3.10, - Python 3.6
messages: + msg377184
resolution: fixed
stage: patch review -> resolved
stage: patch review
pull_requests: + pull_request19893 2020-06-06 13:49:38Ido Michaelsetnosy: + taleinat
2020-03-15 14:49:37Ido Michaelsetnosy: + Ido Michael
messages: + msg364235
2020-03-14 15:42:22Malcolm Smithsetmessages: + msg364185 2018-05-30 17:08:38ammar2setnosy: + ammar2
messages: + msg318201
2018-05-29 23:03:14Malcolm Smithcreate