(module, loader=None, origin=None)
| 673 | |
| 674 | |
| 675 | def _spec_from_module(module, loader=None, origin=None): |
| 676 | # This function is meant for use in _setup(). |
| 677 | try: |
| 678 | spec = module.__spec__ |
| 679 | except AttributeError: |
| 680 | pass |
| 681 | else: |
| 682 | if spec is not None: |
| 683 | return spec |
| 684 | |
| 685 | name = module.__name__ |
| 686 | if loader is None: |
| 687 | try: |
| 688 | loader = module.__loader__ |
| 689 | except AttributeError: |
| 690 | # loader will stay None. |
| 691 | pass |
| 692 | try: |
| 693 | location = module.__file__ |
| 694 | except AttributeError: |
| 695 | location = None |
| 696 | if origin is None: |
| 697 | if loader is not None: |
| 698 | origin = getattr(loader, '_ORIGIN', None) |
| 699 | if not origin and location is not None: |
| 700 | origin = location |
| 701 | try: |
| 702 | submodule_search_locations = list(module.__path__) |
| 703 | except AttributeError: |
| 704 | submodule_search_locations = None |
| 705 | |
| 706 | spec = ModuleSpec(name, loader, origin=origin) |
| 707 | spec._set_fileattr = False if location is None else (origin == location) |
| 708 | spec.cached = None |
| 709 | spec.submodule_search_locations = submodule_search_locations |
| 710 | return spec |
| 711 | |
| 712 | |
| 713 | def _init_module_attrs(spec, module, *, override=False): |
no test coverage detected
searching dependent graphs…