Feature or enhancement
Currently sys.path[0] is set by pymain_run_python() (in Modules/main.c). This happens after pymain_init(), which initializes the runtime, including the rest of sys.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 own PyConfig field via getpath.py, when the rest of the base sys.path is calculated. We may need a later check to verify that there is a matching importer, as pymain_run_python() does. (FWIW, it isn't clear that there's any value to storing the sys.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 in pymain_run_python(). We'd need to factor that in.
CC @zooba, @vstinner, @ncoghlan
Linked PRs
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 ownPyConfigfield via getpath.py, when the rest of the basesys.pathis 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