Lines Matching refs:spec
259 spec = spec_from_loader(fullname, self)
262 _exec(spec, module)
265 return _load(spec)
281 spec = module.__spec__
285 if spec is not None:
286 return _module_repr_from_spec(spec)
320 spec = self._spec
323 del sys.modules[spec.name]
327 _verbose_message('import {!r} # {!r}', spec.name, spec.loader)
462 spec = module.__spec__
466 if spec is not None:
467 return spec
497 spec = ModuleSpec(name, loader, origin=origin)
498 spec._set_fileattr = False if location is None else True
499 spec.cached = cached
500 spec.submodule_search_locations = submodule_search_locations
501 return spec
504 def _init_module_attrs(spec, module, *, override=False): argument
510 module.__name__ = spec.name
515 loader = spec.loader
518 if spec.submodule_search_locations is not None:
524 loader._path = spec.submodule_search_locations
525 spec.loader = loader
544 module.__package__ = spec.parent
549 module.__spec__ = spec
554 if spec.submodule_search_locations is not None:
556 module.__path__ = spec.submodule_search_locations
560 if spec.has_location:
563 module.__file__ = spec.origin
568 if spec.cached is not None:
570 module.__cached__ = spec.cached
576 def module_from_spec(spec): argument
580 if hasattr(spec.loader, 'create_module'):
583 module = spec.loader.create_module(spec)
584 elif hasattr(spec.loader, 'exec_module'):
588 module = _new_module(spec.name)
589 _init_module_attrs(spec, module)
593 def _module_repr_from_spec(spec): argument
596 name = '?' if spec.name is None else spec.name
597 if spec.origin is None:
598 if spec.loader is None:
601 return '<module {!r} ({!r})>'.format(name, spec.loader)
603 if spec.has_location:
604 return '<module {!r} from {!r}>'.format(name, spec.origin)
606 return '<module {!r} ({})>'.format(spec.name, spec.origin)
610 def _exec(spec, module): argument
612 name = spec.name
617 if spec.loader is None:
618 if spec.submodule_search_locations is None:
619 raise ImportError('missing loader', name=spec.name)
621 _init_module_attrs(spec, module, override=True)
623 _init_module_attrs(spec, module, override=True)
624 if not hasattr(spec.loader, 'exec_module'):
628 spec.loader.load_module(name)
630 spec.loader.exec_module(module)
634 def _load_backward_compatible(spec): argument
638 spec.loader.load_module(spec.name)
640 module = sys.modules[spec.name]
643 module.__loader__ = spec.loader
653 module.__package__ = spec.name.rpartition('.')[0]
658 module.__spec__ = spec
663 def _load_unlocked(spec): argument
665 if spec.loader is not None:
667 if not hasattr(spec.loader, 'exec_module'):
668 return _load_backward_compatible(spec)
670 module = module_from_spec(spec)
672 if spec.loader is None:
673 if spec.submodule_search_locations is None:
674 raise ImportError('missing loader', name=spec.name)
677 spec.loader.exec_module(module)
682 return sys.modules[spec.name]
686 def _load(spec): argument
695 with _ModuleLockManager(spec.name):
696 return _load_unlocked(spec)
737 spec = cls.find_spec(fullname, path)
738 return spec.loader if spec is not None else None
741 def create_module(self, spec): argument
743 if spec.name not in sys.builtin_module_names:
744 raise ImportError('{!r} is not a built-in module'.format(spec.name),
745 name=spec.name)
746 return _call_with_frames_removed(_imp.create_builtin, spec)
809 def create_module(cls, spec): argument
902 spec = _find_spec_legacy(finder, name, path)
903 if spec is None:
906 spec = find_spec(name, path, target)
907 if spec is not None:
917 return spec
920 return spec
924 return spec
963 spec = _find_spec(name, path)
964 if spec is None:
967 module = _load_unlocked(spec)
1055 spec = globals.get('__spec__')
1057 if spec is not None and package != spec.parent:
1062 elif spec is not None:
1063 return spec.parent
1110 spec = BuiltinImporter.find_spec(name)
1111 if spec is None:
1113 return _load_unlocked(spec)
1138 spec = _spec_from_module(module, loader)
1139 _init_module_attrs(spec, module)