pkg_roots per session
This commit is contained in:
parent
bbb9d72c13
commit
6fce1f0ac7
|
@ -386,6 +386,7 @@ class Session(nodes.FSCollector):
|
|||
self._initialpaths = frozenset()
|
||||
# Keep track of any collected nodes in here, so we don't duplicate fixtures
|
||||
self._node_cache = {}
|
||||
self._pkg_roots = {}
|
||||
|
||||
self.config.pluginmanager.register(self, name="session")
|
||||
|
||||
|
@ -488,7 +489,6 @@ class Session(nodes.FSCollector):
|
|||
|
||||
names = self._parsearg(arg)
|
||||
argpath = names.pop(0).realpath()
|
||||
pkg_roots = {}
|
||||
|
||||
root = self
|
||||
# Start with a Session root, and delve to argpath item (dir or file)
|
||||
|
@ -509,7 +509,7 @@ class Session(nodes.FSCollector):
|
|||
col = root._collectfile(pkginit, handle_dupes=False)
|
||||
if col:
|
||||
if isinstance(col[0], Package):
|
||||
pkg_roots[parent] = col[0]
|
||||
self._pkg_roots[parent] = col[0]
|
||||
# always store a list in the cache, matchnodes expects it
|
||||
self._node_cache[col[0].fspath] = [col[0]]
|
||||
|
||||
|
@ -533,15 +533,25 @@ class Session(nodes.FSCollector):
|
|||
fil=filter_, rec=self._recurse, bf=True, sort=True
|
||||
):
|
||||
dirpath = path.dirpath()
|
||||
collect_root = pkg_roots.get(dirpath, root)
|
||||
collect_root = self._pkg_roots.get(dirpath, root)
|
||||
if dirpath not in seen_dirs:
|
||||
# Collect packages first.
|
||||
seen_dirs.add(dirpath)
|
||||
pkginit = dirpath.join("__init__.py")
|
||||
if pkginit.exists():
|
||||
got_pkg = False
|
||||
for x in collect_root._collectfile(pkginit):
|
||||
yield x
|
||||
if isinstance(x, Package):
|
||||
pkg_roots[dirpath] = x
|
||||
self._pkg_roots[dirpath] = x
|
||||
got_pkg = True
|
||||
if got_pkg:
|
||||
continue
|
||||
if path.basename == "__init__.py":
|
||||
continue
|
||||
|
||||
if dirpath in self._pkg_roots:
|
||||
continue
|
||||
|
||||
for x in collect_root._collectfile(path):
|
||||
key = (type(x), x.fspath)
|
||||
|
@ -556,7 +566,7 @@ class Session(nodes.FSCollector):
|
|||
if argpath in self._node_cache:
|
||||
col = self._node_cache[argpath]
|
||||
else:
|
||||
collect_root = pkg_roots.get(argpath.dirname, root)
|
||||
collect_root = self._pkg_roots.get(argpath.dirname, root)
|
||||
col = collect_root._collectfile(argpath)
|
||||
if col:
|
||||
self._node_cache[argpath] = col
|
||||
|
|
Loading…
Reference in New Issue