classification
Title: Windows _sys.path file should allow import site
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: steve.dower Nosy List: paul.moore, python-dev, steve.dower, tds333, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-09-13 21:11 by steve.dower, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (4)
msg276344 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-09-13 21:11
Windows's _sys.path file (being renamed from sys.path in b1) currently disable the initial "import site; site.main()" call. However, there are legitimate cases where you may want to opt-in to this while still controlling the search paths.

We should support "import site" as a line in this file that indicates that Py_NoSite should *not* be set. We deliberately do not want arbitrary code execution from this file - there's a reason it's '.path' and not '.pth'

(While I or someone else is here, we should also handle blank lines and lines starting with '#' specially, so that files can be formatted more nicely.)
msg276557 - (view) Author: Wolfgang Langner (tds333) * Date: 2016-09-15 14:09
But this is nearly the same as a *.pth file.
Using the same logic and extension then does not confuse more users.

Why not doing the same as with a .pth file?

Using something like a _sys.pth file if it is there it will be used for path handling. In all cases on all platforms for interpreter startup.
(if we will have the embedded interpreter on more platforms)
msg276564 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-09-15 15:21
On issue28137 I agreed with the proposal to rename to EXENAME.pth, but rather than supporting all of .pth file's syntax we would abort the process on anything we don't like.

Specifically, we'd allow relative paths, absolute paths, blank lines, comments, and "import site". (The parsing code is written in C and runs before initialization, so we can't exec stuff anyway, but if I had my way I'd ban that from .pth files everywhere.)

Supporting this on other platforms requires porting the code to Python/getpath.c. I took a quick survey of core devs at the sprints and nobody seemed desperate to have it, but it's something that we can add at any time since it is tied to build/install (rather than anything you'd write in Python code).
msg276824 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-17 19:57
New changeset 7b47c98f24da by Steve Dower in branch '3.6':
Issue #28137: Renames Windows path file to ._pth
https://hg.python.org/cpython/rev/7b47c98f24da
History
Date User Action Args
2017-03-31 16:36:13dstufftsetpull_requests: + pull_request893
2016-09-17 19:58:17steve.dowersetstatus: open -> closed
resolution: fixed
stage: needs patch -> resolved
2016-09-17 19:57:27python-devsetnosy: + python-dev
messages: + msg276824
2016-09-15 15:21:55steve.dowersetmessages: + msg276564
2016-09-15 14:09:54tds333setnosy: + tds333
messages: + msg276557
2016-09-13 21:11:22steve.dowercreate