@@ -490,7 +490,6 @@ def _collect(self, arg):
490
490
names = self ._parsearg (arg )
491
491
argpath = names .pop (0 ).realpath ()
492
492
493
- root = self
494
493
# Start with a Session root, and delve to argpath item (dir or file)
495
494
# and stack all Packages found on the way.
496
495
# No point in finding packages when collecting doctests
@@ -503,10 +502,8 @@ def _collect(self, arg):
503
502
if parent .isdir ():
504
503
pkginit = parent .join ("__init__.py" )
505
504
if pkginit .isfile ():
506
- if pkginit in self ._node_cache :
507
- root = self ._node_cache [pkginit ][0 ]
508
- else :
509
- col = root ._collectfile (pkginit , handle_dupes = False )
505
+ if pkginit not in self ._node_cache :
506
+ col = self ._collectfile (pkginit , handle_dupes = False )
510
507
if col :
511
508
if isinstance (col [0 ], Package ):
512
509
self ._pkg_roots [parent ] = col [0 ]
@@ -533,27 +530,21 @@ def filter_(f):
533
530
fil = filter_ , rec = self ._recurse , bf = True , sort = True
534
531
):
535
532
dirpath = path .dirpath ()
536
- collect_root = self ._pkg_roots .get (dirpath , root )
537
533
if dirpath not in seen_dirs :
538
534
# Collect packages first.
539
535
seen_dirs .add (dirpath )
540
536
pkginit = dirpath .join ("__init__.py" )
541
537
if pkginit .exists ():
542
- got_pkg = False
538
+ collect_root = self . _pkg_roots . get ( dirpath , self )
543
539
for x in collect_root ._collectfile (pkginit ):
544
540
yield x
545
541
if isinstance (x , Package ):
546
542
self ._pkg_roots [dirpath ] = x
547
- got_pkg = True
548
- if got_pkg :
549
- continue
550
- if path .basename == "__init__.py" :
551
- continue
552
-
553
543
if dirpath in self ._pkg_roots :
544
+ # Do not collect packages here.
554
545
continue
555
546
556
- for x in collect_root ._collectfile (path ):
547
+ for x in self ._collectfile (path ):
557
548
key = (type (x ), x .fspath )
558
549
if key in self ._node_cache :
559
550
yield self ._node_cache [key ]
@@ -566,7 +557,7 @@ def filter_(f):
566
557
if argpath in self ._node_cache :
567
558
col = self ._node_cache [argpath ]
568
559
else :
569
- collect_root = self ._pkg_roots .get (argpath .dirname , root )
560
+ collect_root = self ._pkg_roots .get (argpath .dirname , self )
570
561
col = collect_root ._collectfile (argpath )
571
562
if col :
572
563
self ._node_cache [argpath ] = col
0 commit comments