MCPcopy Index your code
hub / github.com/RustPython/RustPython / _setup

Function _setup

Lib/importlib/_bootstrap.py:1509–1546  ·  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

1507
1508
1509def _setup(sys_module, _imp_module):
1510 """Setup importlib by importing needed built-in modules and injecting them
1511 into the global namespace.
1512
1513 As sys is needed for sys.modules access and _imp is needed to load built-in
1514 modules, those two modules must be explicitly passed in.
1515
1516 """
1517 global _imp, sys, _blocking_on
1518 _imp = _imp_module
1519 sys = sys_module
1520
1521 # Set up the spec for existing builtin/frozen modules.
1522 module_type = type(sys)
1523 for name, module in sys.modules.items():
1524 if isinstance(module, module_type):
1525 if name in sys.builtin_module_names:
1526 loader = BuiltinImporter
1527 elif _imp.is_frozen(name):
1528 loader = FrozenImporter
1529 else:
1530 continue
1531 spec = _spec_from_module(module, loader)
1532 _init_module_attrs(spec, module)
1533 if loader is FrozenImporter:
1534 loader._fix_up_module(module)
1535
1536 # Directly load built-in modules needed during bootstrap.
1537 self_module = sys.modules[__name__]
1538 for builtin_name in ('_thread', '_warnings', '_weakref'):
1539 if builtin_name not in sys.modules:
1540 builtin_module = _builtin_from_name(builtin_name)
1541 else:
1542 builtin_module = sys.modules[builtin_name]
1543 setattr(self_module, builtin_name, builtin_module)
1544
1545 # Instantiation requires _weakref to have been set.
1546 _blocking_on = _WeakValueDictionary()
1547
1548
1549def _install(sys_module, _imp_module):

Callers 1

_installFunction · 0.70

Calls 8

isinstanceFunction · 0.85
setattrFunction · 0.85
_spec_from_moduleFunction · 0.70
_init_module_attrsFunction · 0.70
_builtin_from_nameFunction · 0.70
itemsMethod · 0.45
_fix_up_moduleMethod · 0.45

Tested by

no test coverage detected