pkg_roots
This commit is contained in:
parent
f840521854
commit
f8b944dee0
|
@ -490,6 +490,7 @@ class Session(nodes.FSCollector):
|
||||||
names = self._parsearg(arg)
|
names = self._parsearg(arg)
|
||||||
argpath = names.pop(0).realpath()
|
argpath = names.pop(0).realpath()
|
||||||
paths = set()
|
paths = set()
|
||||||
|
pkg_roots = {}
|
||||||
|
|
||||||
root = self
|
root = self
|
||||||
# Start with a Session root, and delve to argpath item (dir or file)
|
# Start with a Session root, and delve to argpath item (dir or file)
|
||||||
|
@ -510,9 +511,9 @@ class Session(nodes.FSCollector):
|
||||||
col = root._collectfile(pkginit, handle_dupes=False)
|
col = root._collectfile(pkginit, handle_dupes=False)
|
||||||
if col:
|
if col:
|
||||||
if isinstance(col[0], Package):
|
if isinstance(col[0], Package):
|
||||||
root = col[0]
|
pkg_roots[parent] = col[0]
|
||||||
# always store a list in the cache, matchnodes expects it
|
# always store a list in the cache, matchnodes expects it
|
||||||
self._node_cache[root.fspath] = [root]
|
self._node_cache[col[0].fspath] = [col[0]]
|
||||||
|
|
||||||
# If it's a directory argument, recurse and look for any Subpackages.
|
# If it's a directory argument, recurse and look for any Subpackages.
|
||||||
# Let the Package collector deal with subnodes, don't collect here.
|
# Let the Package collector deal with subnodes, don't collect here.
|
||||||
|
@ -534,16 +535,19 @@ class Session(nodes.FSCollector):
|
||||||
fil=filter_, rec=self._recurse, bf=True, sort=True
|
fil=filter_, rec=self._recurse, bf=True, sort=True
|
||||||
):
|
):
|
||||||
dirpath = path.dirpath()
|
dirpath = path.dirpath()
|
||||||
|
collect_root = pkg_roots.get(dirpath, root)
|
||||||
if dirpath not in seen_dirs:
|
if dirpath not in seen_dirs:
|
||||||
seen_dirs.add(dirpath)
|
seen_dirs.add(dirpath)
|
||||||
pkginit = dirpath.join("__init__.py")
|
pkginit = dirpath.join("__init__.py")
|
||||||
if pkginit.exists() and parts(pkginit.strpath).isdisjoint(paths):
|
if pkginit.exists() and parts(pkginit.strpath).isdisjoint(paths):
|
||||||
for x in root._collectfile(pkginit):
|
for x in collect_root._collectfile(pkginit):
|
||||||
yield x
|
yield x
|
||||||
|
if isinstance(x, Package):
|
||||||
|
pkg_roots[dirpath] = x
|
||||||
paths.add(x.fspath.dirpath())
|
paths.add(x.fspath.dirpath())
|
||||||
|
|
||||||
if parts(path.strpath).isdisjoint(paths):
|
if True or parts(path.strpath).isdisjoint(paths):
|
||||||
for x in root._collectfile(path):
|
for x in collect_root._collectfile(path):
|
||||||
key = (type(x), x.fspath)
|
key = (type(x), x.fspath)
|
||||||
if key in self._node_cache:
|
if key in self._node_cache:
|
||||||
yield self._node_cache[key]
|
yield self._node_cache[key]
|
||||||
|
@ -556,7 +560,8 @@ class Session(nodes.FSCollector):
|
||||||
if argpath in self._node_cache:
|
if argpath in self._node_cache:
|
||||||
col = self._node_cache[argpath]
|
col = self._node_cache[argpath]
|
||||||
else:
|
else:
|
||||||
col = root._collectfile(argpath)
|
collect_root = pkg_roots.get(argpath.dirname, root)
|
||||||
|
col = collect_root._collectfile(argpath)
|
||||||
if col:
|
if col:
|
||||||
self._node_cache[argpath] = col
|
self._node_cache[argpath] = col
|
||||||
m = self.matchnodes(col, names)
|
m = self.matchnodes(col, names)
|
||||||
|
|
Loading…
Reference in New Issue