MCPcopy
hub / github.com/pex-tool/pex / imported_from_bootstrap

Method imported_from_bootstrap

pex/bootstrap.py:81–106  ·  view source on GitHub ↗

Return ``True`` if the given ``module`` object was imported from bootstrap code. :param module: The module to check the provenance of.

(self, module)

Source from the content-addressed store, hash-verified

79 return unimported_modules
80
81 def imported_from_bootstrap(self, module):
82 # type: (Any) -> bool
83 """Return ``True`` if the given ``module`` object was imported from bootstrap code.
84
85 :param module: The module to check the provenance of.
86 """
87
88 # Python 2.7 does some funky imports in the email stdlib package that cause havoc with
89 # un-importing. Since all our own importing just goes through the vanilla importers we can
90 # safely ignore all but the standard module type.
91 if not isinstance(module, types.ModuleType):
92 return False
93
94 # A vendored module.
95 path = getattr(module, "__file__", None)
96 if path and os.path.realpath(path).startswith(self._realpath):
97 return True
98
99 # A vendored package.
100 path = getattr(module, "__path__", None)
101 if path and any(
102 os.path.realpath(path_item).startswith(self._realpath) for path_item in path
103 ):
104 return True
105
106 return False
107
108 def __repr__(self):
109 # type: () -> str

Callers 1

demoteMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected