Title: Blank lines in .pth file cause a duplicate sys.path entry
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Malcolm Smith, ammar2
Priority: normal Keywords:

Created on 2018-05-29 23:03 by Malcolm Smith, last changed 2018-05-30 17:08 by ammar2.

Messages (2)
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 triager) 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.
Date User Action Args
2018-05-30 17:08:38ammar2setnosy: + ammar2
messages: + msg318201
2018-05-29 23:03:14Malcolm Smithcreate