The specification for a module, used for loading. A module's spec is the source for information about the module. For data associated with the module, including source, use the spec's loader. `name` is the absolute name of the module. `loader` is the loader to use when loadin
| 563 | |
| 564 | |
| 565 | class ModuleSpec: |
| 566 | """The specification for a module, used for loading. |
| 567 | |
| 568 | A module's spec is the source for information about the module. For |
| 569 | data associated with the module, including source, use the spec's |
| 570 | loader. |
| 571 | |
| 572 | `name` is the absolute name of the module. `loader` is the loader |
| 573 | to use when loading the module. `parent` is the name of the |
| 574 | package the module is in. The parent is derived from the name. |
| 575 | |
| 576 | `is_package` determines if the module is considered a package or |
| 577 | not. On modules this is reflected by the `__path__` attribute. |
| 578 | |
| 579 | `origin` is the specific location used by the loader from which to |
| 580 | load the module, if that information is available. When filename is |
| 581 | set, origin will match. |
| 582 | |
| 583 | `has_location` indicates that a spec's "origin" reflects a location. |
| 584 | When this is True, `__file__` attribute of the module is set. |
| 585 | |
| 586 | `cached` is the location of the cached bytecode file, if any. It |
| 587 | corresponds to the `__cached__` attribute. |
| 588 | |
| 589 | `submodule_search_locations` is the sequence of path entries to |
| 590 | search when importing submodules. If set, is_package should be |
| 591 | True--and False otherwise. |
| 592 | |
| 593 | Packages are simply modules that (may) have submodules. If a spec |
| 594 | has a non-None value in `submodule_search_locations`, the import |
| 595 | system will consider modules loaded from the spec as packages. |
| 596 | |
| 597 | Only finders (see importlib.abc.MetaPathFinder and |
| 598 | importlib.abc.PathEntryFinder) should modify ModuleSpec instances. |
| 599 | |
| 600 | """ |
| 601 | |
| 602 | def __init__(self, name, loader, *, origin=None, loader_state=None, |
| 603 | is_package=None): |
| 604 | self.name = name |
| 605 | self.loader = loader |
| 606 | self.origin = origin |
| 607 | self.loader_state = loader_state |
| 608 | self.submodule_search_locations = [] if is_package else None |
| 609 | self._uninitialized_submodules = [] |
| 610 | |
| 611 | # file-location attributes |
| 612 | self._set_fileattr = False |
| 613 | self._cached = None |
| 614 | |
| 615 | def __repr__(self): |
| 616 | args = [f'name={self.name!r}', f'loader={self.loader!r}'] |
| 617 | if self.origin is not None: |
| 618 | args.append(f'origin={self.origin!r}') |
| 619 | if self.submodule_search_locations is not None: |
| 620 | args.append(f'submodule_search_locations={self.submodule_search_locations}') |
| 621 | return f'{self.__class__.__name__}({", ".join(args)})' |
| 622 |
no outgoing calls