This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Blank lines in .pth file cause a duplicate sys.path entry
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Ido Michael, Malcolm Smith, ammar2, taleinat
Priority: normal Keywords: patch

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

Pull Requests
URL Status Linked Edit
PR 20679 merged Ido Michael, 2020-06-06 14:05
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.


$ python -c 'import sys; print(sys.path)'
['', '/home/smith/.virtualenvs/foo/lib/', '/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/', '/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, 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)
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!
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

resolution: fixed
stage: patch review -> resolved
2020-09-19 19:13:36taleinatsetmessages: + msg377183
2020-09-19 18:52:43taleinatsetmessages: + msg377181
2020-06-06 14:17:11Ido Michaelsetmessages: + msg370824
2020-06-06 14:05:06Ido Michaelsetkeywords: + patch
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