MCPcopy Create free account
hub / github.com/twisted/twisted / _findEntryPathString

Method _findEntryPathString

src/twisted/python/modules.py:625–657  ·  view source on GitHub ↗

Determine where a given Python module object came from by looking at path entries.

(self, modobj)

Source from the content-addressed store, hash-verified

623 return self._sysPathFactory()
624
625 def _findEntryPathString(self, modobj):
626 """
627 Determine where a given Python module object came from by looking at path
628 entries.
629 """
630 topPackageObj = modobj
631 while "." in topPackageObj.__name__:
632 topPackageObj = self.moduleDict[
633 ".".join(topPackageObj.__name__.split(".")[:-1])
634 ]
635 if _isPackagePath(FilePath(topPackageObj.__file__)):
636 # if package 'foo' is on sys.path at /a/b/foo, package 'foo's
637 # __file__ will be /a/b/foo/__init__.py, and we are looking for
638 # /a/b here, the path-entry; so go up two steps.
639 rval = dirname(dirname(topPackageObj.__file__))
640 else:
641 # the module is completely top-level, not within any packages. The
642 # path entry it's on is just its dirname.
643 rval = dirname(topPackageObj.__file__)
644
645 # There are probably some awful tricks that an importer could pull
646 # which would break this, so let's just make sure... it's a loaded
647 # module after all, which means that its path MUST be in
648 # path_importer_cache according to PEP 302 -glyph
649 if rval not in self.importerCache:
650 warnings.warn(
651 "%s (for module %s) not in path importer cache "
652 "(PEP 302 violation - check your local configuration)."
653 % (rval, modobj.__name__),
654 stacklevel=3,
655 )
656
657 return rval
658
659 def _smartPath(self, pathName):
660 """

Callers 1

__getitem__Method · 0.95

Calls 4

FilePathClass · 0.90
_isPackagePathFunction · 0.85
joinMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected