Issue 33698: ._pth does not allow to populate sys.path with empty entry (original) (raw)

Created on 2018-05-30 17:12 by excitoon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7243 closed excitoon,2018-05-30 17:12
Messages (4)
msg318202 - (view) Author: Vladimir Chebotarev (excitoon) * Date: 2018-05-30 17:12
Moving from bpo-29326 ==== Hi Steve. I'll try to explain what is my motivation. I need a reliable way to run Python (not matter embedded or not) in isolated mode, but still having current directory in `sys.path` (empty entry). Ironically I could misuse normal mode to simulate isolated mode with specified %PYTHONPATH% (which is not much handy, by the way), but hiding Windows Registry keys would look pretty hard (it is impossible to make a bat/cmd wrapper). Possibility to search %PYTHONPATH% in HKLM entries makes it even worse. Empty entry in `sys.path` is a extremely popular thing, and many software depend on it. It looks like a bug that isolated mode cannot support such entry. # How would I fix it. Possibly we should allow another keyword for adding an empty entry (like we have an exclusion for `import site`). Ideas are appreciated.
msg318211 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-05-30 21:45
If your ._pth includes `import site`, then including a blank line in a `anything.pth` file should add the entry. Alternatively, if you can add "import sys; sys.path.insert(0, '')" to the start of your code that depends on it you should be fine.
msg318267 - (view) Author: Vladimir Chebotarev (excitoon) * Date: 2018-05-31 08:45
Unfortunately this is not true: "Blank lines and lines beginning with # are skipped." (https://docs.python.org/3/library/site.html#index-1) I'm not sure we should change this behavior as it would make huge impact on usage of `pth` files by users (`._pth`, on the contrary, is the only one per distribution and managed by the distribution). I could easily add `''` to `sys.path` manually if I had one script or even dozen of them, but as the solution that alternative is not acceptable. :(
msg318272 - (view) Author: Paul Moore (paul.moore) * (Python committer) Date: 2018-05-31 09:02
You could add the line import sys; sys.path.insert(0, '') to a .pth file. The documentation you pointed out states that lines starting with "import" are executed...
History
Date User Action Args
2022-04-11 14:59:01 admin set github: 77879
2020-02-05 02:53:11 steve.dower set status: open -> closedresolution: rejectedstage: resolved
2018-09-29 07🔞58 ssapin set nosy: + ssapin
2018-05-31 09:02:46 paul.moore set messages: +
2018-05-31 08:45:08 excitoon set messages: +
2018-05-30 21:45:56 steve.dower set messages: +
2018-05-30 17:32:53 excitoon set title: `._pth` does not allow to populate `sys.path` empty entry -> `._pth` does not allow to populate `sys.path` with empty entry
2018-05-30 17:12:41 excitoon create