classification
Title: Control what module is imported first
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, carljm, eric.araujo, eric.snow, ncoghlan, pitrou, rhettinger, twouters, vstinner
Priority: low Keywords: patch

Created on 2011-09-06 17:53 by brett.cannon, last changed 2019-10-22 23:08 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
stdlib_landmark.diff twouters, 2011-09-07 11:25 review
Messages (7)
msg143636 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2011-09-06 17:53
Issue11561 had a use case for controlling what module is imported first (along with a patch to use a module other than 'os' to control finding the stdlib). There have been others who could use this feature as well.
msg143668 - (view) Author: Thomas Wouters (twouters) * (Python committer) Date: 2011-09-07 11:25
Here's the patch implementing this, which I'd attached to Issue11561 (although I noticed 'hg diff' omitted the empty stdlib_landmark.py file.)
msg143770 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-09-09 17:10
Thomas: I assume you have “hg add”-ed the file; you may need to use git-style diffs to have new files included in diffs: http://hgtip.com/tips/beginner/2009-10-22-always-use-git-diffs/
msg148553 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-11-29 11:21
I don't think conflating two orthogonal needs in a single "feature" like that is a good idea. This will become one of these obscure implementation details which complicate the code for no real benefit. If there's a need to "customize the first import" then a proper proposal should be made rather than a quick hack.
msg148609 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-11-29 20:56
I concur with Antoine.
msg181121 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-02-01 22:07
This would tie into PEP 432 at this point.
msg355173 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-22 23:08
I close the issue since I see disagreement on the feature request.

Modules/getpath.c and PC/getpathp.c use Lib/os.py to detect the stdlib directory.

_PyUnicode_InitEncodings() is the first function importing modules: to import the Python codec of the filesystem encoding. If this import fails, Python now dumps the "path configuration" to help users to debug their setup. See bpo-38236.

Example:

$ PYTHONHOME=/xxx ./python -c pass
Python path configuration:
  PYTHONHOME = '/xxx'
  PYTHONPATH = (not set)
  program name = './python'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/home/vstinner/python/master/python'
  sys.base_prefix = '/xxx'
  sys.base_exec_prefix = '/xxx'
  sys.executable = '/home/vstinner/python/master/python'
  sys.prefix = '/xxx'
  sys.exec_prefix = '/xxx'
  sys.path = [
    '/xxx/lib/python39.zip',
    '/xxx/lib/python3.9',
    '/xxx/lib/python3.9/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007f845ca19740 (most recent call first):
<no Python frame>
History
Date User Action Args
2019-10-22 23:08:35vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg355173

resolution: rejected
stage: patch review -> resolved
2013-02-01 22:07:59brett.cannonsetnosy: + ncoghlan
messages: + msg181121
2012-03-12 17:51:02eric.araujosetnosy: + carljm
2011-11-29 20:56:10rhettingersetnosy: + rhettinger
messages: + msg148609
2011-11-29 11:21:46pitrousetnosy: + pitrou
messages: + msg148553
2011-11-29 06:25:47ezio.melottisetstage: needs patch -> patch review
2011-09-09 17:10:50eric.araujosetnosy: + eric.araujo
messages: + msg143770
2011-09-07 11:25:27twouterssetfiles: + stdlib_landmark.diff

nosy: + twouters
messages: + msg143668

keywords: + patch
2011-09-06 19:36:14eric.snowsetnosy: + eric.snow
2011-09-06 17:53:35brett.cannoncreate