classification
Title: Move sys variable initialization from import.c to sysmodule.c
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: eric.snow Nosy List: benjamin.peterson, eric.snow, ncoghlan, pitrou, vstinner
Priority: normal Keywords: patch

Created on 2011-07-20 23:24 by eric.snow, last changed 2019-10-22 22:42 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
sys_import_state.diff eric.snow, 2011-07-20 23:24 review
Messages (6)
msg140769 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2011-07-20 23:24
Several import-related sys variables are set in _PyImportHooks_Init (in Python/import.c), which is called in Python/pythonrun.c.  I have included a patch that moves that initialization from _PyImportHooks_Init to a new _SysImportState_Init function in Python/sysmodule.c, which is then called from _PyImportHooks_Init.

This may seem like an unnecessary change, but sysmodule.c is the obvious place to find the initialization of sys variables.  Other than in pythonrun.c, import.c is the only place that sys variables are set outside of sysmodule.c.

Finally, several import related projects[1] are coming up that will impact import.c and _PyImportHooks_Init specifically.  This change helps clean up import.c a little in preparation for those projects, and isolates out of import.c at least one thing that should be kept safe during any import.c refactoring.

[1] see issue #2377, PEP 402, and the GSOC import engine project.
msg158637 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2012-04-18 16:32
The patch is out of date, but the question is still somewhat applicable.
msg158650 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-04-18 19:17
This looks sensible.
msg158653 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-04-18 19:33
I don't see the point.
msg158670 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-04-18 22:06
It's about navigability/discovery of the source - to find out how the sys module gets initialised, you currently have to look in multiple places. The idea of the patch is to simplify that to the one logical place: sysmodule.c

However, I'm not sure it's right to actually *move* the full import state initialisation. A simple *indirection* (pythonrun.c -> sysmodule.c -> import.c) would solve the navigability problem while also retaining some level of encapsulation for the import state initialisation.
msg355164 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-22 22:42
No activity for 7 years, I close the issue.
History
Date User Action Args
2019-10-22 22:42:39vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg355164

resolution: out of date
stage: resolved
2013-06-25 05:29:25eric.snowsetassignee: eric.snow
2013-02-01 22:28:58brett.cannonsetnosy: - brett.cannon
2012-04-18 22:06:27ncoghlansetmessages: + msg158670
2012-04-18 19:33:54benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg158653
2012-04-18 19:17:08pitrousetnosy: + pitrou
messages: + msg158650
components: + Interpreter Core
2012-04-18 16:32:28eric.snowsetmessages: + msg158637
versions: + Python 3.3
2011-07-20 23:29:47ncoghlansetnosy: + brett.cannon, ncoghlan
2011-07-20 23:24:44eric.snowcreate