(module, loader=None, origin=None)
| 692 | |
| 693 | |
| 694 | def _spec_from_module(module, loader=None, origin=None): |
| 695 | # This function is meant for use in _setup(). |
| 696 | try: |
| 697 | spec = module.__spec__ |
| 698 | except AttributeError: |
| 699 | pass |
| 700 | else: |
| 701 | if spec is not None: |
| 702 | return spec |
| 703 | |
| 704 | name = module.__name__ |
| 705 | if loader is None: |
| 706 | try: |
| 707 | loader = module.__loader__ |
| 708 | except AttributeError: |
| 709 | # loader will stay None. |
| 710 | pass |
| 711 | try: |
| 712 | location = module.__file__ |
| 713 | except AttributeError: |
| 714 | location = None |
| 715 | if origin is None: |
| 716 | if loader is not None: |
| 717 | origin = getattr(loader, '_ORIGIN', None) |
| 718 | if not origin and location is not None: |
| 719 | origin = location |
| 720 | try: |
| 721 | cached = module.__cached__ |
| 722 | except AttributeError: |
| 723 | cached = None |
| 724 | try: |
| 725 | submodule_search_locations = list(module.__path__) |
| 726 | except AttributeError: |
| 727 | submodule_search_locations = None |
| 728 | |
| 729 | spec = ModuleSpec(name, loader, origin=origin) |
| 730 | spec._set_fileattr = False if location is None else (origin == location) |
| 731 | spec.cached = cached |
| 732 | spec.submodule_search_locations = submodule_search_locations |
| 733 | return spec |
| 734 | |
| 735 | |
| 736 | def _init_module_attrs(spec, module, *, override=False): |
no test coverage detected