[issue33698] `._pth` does not allow to populate `sys.path` empty entry
New submission from Vladimir Chebotarev <vladimir.chebotarev@gmail.com>: 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. ---------- assignee: docs@python components: Documentation, Windows messages: 318202 nosy: docs@python, excitoon, paul.moore, steve.dower, tim.golden, zach.ware priority: normal pull_requests: 6878 severity: normal status: open title: `._pth` does not allow to populate `sys.path` empty entry type: behavior versions: Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
Change by Vladimir Chebotarev <vladimir.chebotarev@gmail.com>: ---------- title: `._pth` does not allow to populate `sys.path` empty entry -> `._pth` does not allow to populate `sys.path` with empty entry _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
Steve Dower <steve.dower@python.org> added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
Vladimir Chebotarev <vladimir.chebotarev@gmail.com> added the comment: 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. :( ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
Paul Moore <p.f.moore@gmail.com> added the comment: 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... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
Change by Simon Sapin <simon.sapin@exyr.org>: ---------- nosy: +ssapin _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
Change by Steve Dower <steve.dower@python.org>: ---------- resolution: -> rejected stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue33698> _______________________________________
participants (4)
-
Paul Moore
-
Simon Sapin
-
Steve Dower
-
Vladimir Chebotarev