-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys.path[0] Is Set Differently From the Rest of sys.path #109853
Comments
There are two cases:
For the case (A), do you want to execute PyImport_GetImporter() twice? Once in Py_InitializeFromConfig(), then again in pymain_run_python()? It's to decide if pymain_run_module() or pymain_run_file() should be used. For case (B), this code path can be easily moved to Py_InitializeFromConfig(). When I designed and implemented PyConfig, I tried to minimize changes. But apparently, now the dust has settled, and we can go further :-) |
I think we should move most of the default If we're able to fully initialise the search path using only our public APIs, we'll have a much better interface for embedders to use. |
I would love that sys.path would be fully initialized before the site module is loaded. Currently, sys.path is still modified by the site module in many ways, and so site changes:
|
I expect most of the site module can move into getpath. Venv and pth sure can (though we'd have to defer code execution in pth files until after initialization finishes). Some of the interactive mode features probably can't, but I'd also like to treat those as something specific to python.c and separate from libpython (i.e. part of the Python program not the Python interpreter). |
…-109994) This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all. This change does not address the broader concerns from pythongh-109853. (cherry-picked from commit a040a32)
…-109994) This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all. This change does not address the broader concerns from pythongh-109853. (cherry-picked from commit a040a32)
This adds |
Need @ericsnowcurrently to confirm, but I suspect marking it internal is better. When the calculation gets refactored into |
We should mark it as internal at least for now. We'd need to sort out the complexity I described above before this would become meaningful config. |
The There's an intrinsic problem here in that |
I wonder if we can make |
This change makes sure sys.path[0] is set properly for subinterpreters. Before, it wasn't getting set at all. This PR does not address the broader concerns from pythongh-109853.
Feature or enhancement
Currently
sys.path[0]
is set bypymain_run_python()
(in Modules/main.c). This happens afterpymain_init()
, which initializes the runtime, including the rest ofsys.path
(via getpath.py and site.py). This makes it harder to reason about and introduces extra complexity for subinterpreters. (See gh-109793 and gh-109794.)We should consider calculating
sys.path[0]
and setting it to its ownPyConfig
field via getpath.py, when the rest of the basesys.path
is calculated. We may need a later check to verify that there is a matching importer, aspymain_run_python()
does. (FWIW, it isn't clear that there's any value to storing thesys.path[0]
value on the global_PyPathConfig
.)Also, we currently wait to actually set
sys.path[0]
(for the main interpreter) until after the readline/rlcompleter modules are imported inpymain_run_python()
. We'd need to factor that in.CC @zooba, @vstinner, @ncoghlan
Linked PRs
The text was updated successfully, but these errors were encountered: