cleanup, TODO: use _node_cache

This commit is contained in:
Daniel Hahler 2018-11-07 20:14:07 +01:00
parent 6fce1f0ac7
commit 827573c049
1 changed files with 6 additions and 15 deletions

View File

@ -490,7 +490,6 @@ class Session(nodes.FSCollector):
names = self._parsearg(arg) names = self._parsearg(arg)
argpath = names.pop(0).realpath() argpath = names.pop(0).realpath()
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)
# and stack all Packages found on the way. # and stack all Packages found on the way.
# No point in finding packages when collecting doctests # No point in finding packages when collecting doctests
@ -503,10 +502,8 @@ class Session(nodes.FSCollector):
if parent.isdir(): if parent.isdir():
pkginit = parent.join("__init__.py") pkginit = parent.join("__init__.py")
if pkginit.isfile(): if pkginit.isfile():
if pkginit in self._node_cache: if pkginit not in self._node_cache:
root = self._node_cache[pkginit][0] col = self._collectfile(pkginit, handle_dupes=False)
else:
col = root._collectfile(pkginit, handle_dupes=False)
if col: if col:
if isinstance(col[0], Package): if isinstance(col[0], Package):
self._pkg_roots[parent] = col[0] self._pkg_roots[parent] = col[0]
@ -533,27 +530,21 @@ 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 = self._pkg_roots.get(dirpath, root)
if dirpath not in seen_dirs: if dirpath not in seen_dirs:
# Collect packages first. # Collect packages first.
seen_dirs.add(dirpath) seen_dirs.add(dirpath)
pkginit = dirpath.join("__init__.py") pkginit = dirpath.join("__init__.py")
if pkginit.exists(): if pkginit.exists():
got_pkg = False collect_root = self._pkg_roots.get(dirpath, self)
for x in collect_root._collectfile(pkginit): for x in collect_root._collectfile(pkginit):
yield x yield x
if isinstance(x, Package): if isinstance(x, Package):
self._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: if dirpath in self._pkg_roots:
# Do not collect packages here.
continue continue
for x in collect_root._collectfile(path): for x in self._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]
@ -566,7 +557,7 @@ 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:
collect_root = self._pkg_roots.get(argpath.dirname, root) collect_root = self._pkg_roots.get(argpath.dirname, self)
col = collect_root._collectfile(argpath) col = collect_root._collectfile(argpath)
if col: if col:
self._node_cache[argpath] = col self._node_cache[argpath] = col