MCPcopy
hub / github.com/pytest-dev/pytest / pypkgpath

Method pypkgpath

src/_pytest/_py/path.py:1045–1058  ·  view source on GitHub ↗

Return the Python package path by looking for the last directory upwards which still contains an __init__.py. Return None if a pkgpath cannot be determined.

(self)

Source from the content-addressed store, hash-verified

1043 error.checked_call(os.chmod, self.strpath, mode)
1044
1045 def pypkgpath(self):
1046 """Return the Python package path by looking for the last
1047 directory upwards which still contains an __init__.py.
1048 Return None if a pkgpath cannot be determined.
1049 """
1050 pkgpath = None
1051 for parent in self.parts(reverse=True):
1052 if parent.isdir():
1053 if not parent.join("__init__.py").exists():
1054 break
1055 if not isimportable(parent.basename):
1056 break
1057 pkgpath = parent
1058 return pkgpath
1059
1060 def _ensuresyspath(self, ensuremode, path):
1061 if ensuremode:

Callers 3

pyimportMethod · 0.95
test_pypkgdirFunction · 0.80

Calls 5

partsMethod · 0.95
isimportableFunction · 0.85
joinMethod · 0.80
isdirMethod · 0.45
existsMethod · 0.45

Tested by 2

test_pypkgdirFunction · 0.64