MCPcopy Index your code
hub / github.com/python/cpython / _setup

Function _setup

Lib/importlib/_bootstrap.py:1428–1465  ·  view source on GitHub ↗

Setup importlib by importing needed built-in modules and injecting them into the global namespace. As sys is needed for sys.modules access and _imp is needed to load built-in modules, those two modules must be explicitly passed in.

(sys_module, _imp_module)

Source from the content-addressed store, hash-verified

1426
1427
1428def _setup(sys_module, _imp_module):
1429 """Setup importlib by importing needed built-in modules and injecting them
1430 into the global namespace.
1431
1432 As sys is needed for sys.modules access and _imp is needed to load built-in
1433 modules, those two modules must be explicitly passed in.
1434
1435 """
1436 global _imp, sys, _blocking_on
1437 _imp = _imp_module
1438 sys = sys_module
1439
1440 # Set up the spec for existing builtin/frozen modules.
1441 module_type = type(sys)
1442 for name, module in sys.modules.items():
1443 if isinstance(module, module_type):
1444 if name in sys.builtin_module_names:
1445 loader = BuiltinImporter
1446 elif _imp.is_frozen(name):
1447 loader = FrozenImporter
1448 else:
1449 continue
1450 spec = _spec_from_module(module, loader)
1451 _init_module_attrs(spec, module)
1452 if loader is FrozenImporter:
1453 loader._fix_up_module(module)
1454
1455 # Directly load built-in modules needed during bootstrap.
1456 self_module = sys.modules[__name__]
1457 for builtin_name in ('_thread', '_warnings', '_weakref'):
1458 if builtin_name not in sys.modules:
1459 builtin_module = _builtin_from_name(builtin_name)
1460 else:
1461 builtin_module = sys.modules[builtin_name]
1462 setattr(self_module, builtin_name, builtin_module)
1463
1464 # Instantiation requires _weakref to have been set.
1465 _blocking_on = _WeakValueDictionary()
1466
1467
1468def _install(sys_module, _imp_module):

Callers 1

_installFunction · 0.70

Calls 6

_spec_from_moduleFunction · 0.85
_init_module_attrsFunction · 0.85
_builtin_from_nameFunction · 0.85
_fix_up_moduleMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…