@@ -534,25 +534,23 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
534
534
535
535
orig_modules = list (graph .keys ())
536
536
537
- # TODO: Are the differences from fine_grained_increment(), necessary?
538
537
self .update_sources (sources )
539
538
changed_paths = self .fswatcher .find_changed ()
540
539
manager .search_paths = compute_search_paths (sources , manager .options , manager .data_dir )
541
540
542
541
t1 = time .time ()
543
542
manager .log ("fine-grained increment: find_changed: {:.3f}s" .format (t1 - t0 ))
544
543
545
- sources_set = {source .module for source in sources }
544
+ seen = {source .module for source in sources }
546
545
547
546
# Find changed modules reachable from roots (or in roots) already in graph.
548
- seen = set () # type: Set[str]
549
- changed , removed , new_files = self .follow_imports (
550
- sources , graph , seen , changed_paths , sources_set
547
+ changed , new_files = self .find_reachable_changed_modules (
548
+ sources , graph , seen , changed_paths
551
549
)
552
550
sources .extend (new_files )
553
551
554
552
# Process changes directly reachable from roots.
555
- messages = fine_grained_manager .update (changed , removed )
553
+ messages = fine_grained_manager .update (changed , [] )
556
554
557
555
# Follow deps from changed modules (still within graph).
558
556
worklist = changed [:]
@@ -561,31 +559,31 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
561
559
if module [0 ] not in graph :
562
560
continue
563
561
sources2 = self .direct_imports (module , graph )
564
- changed , removed , new_files = self .follow_imports (
565
- sources2 , graph , seen , changed_paths , sources_set
562
+ changed , new_files = self .find_reachable_changed_modules (
563
+ sources2 , graph , seen , changed_paths
566
564
)
567
- sources .extend (new_files )
568
565
self .update_sources (new_files )
569
- messages = fine_grained_manager .update (changed , removed )
570
- # TODO: Removed?
566
+ messages = fine_grained_manager .update (changed , [])
571
567
worklist .extend (changed )
572
568
573
569
t2 = time .time ()
574
570
575
- for module_id , state in graph .items ():
576
- refresh_suppressed_submodules (module_id , state .path , fine_grained_manager .deps , graph ,
577
- self .fscache )
571
+ def refresh_file (module : str , path : str ) -> List [str ]:
572
+ return fine_grained_manager .update ([(module , path )], [])
573
+
574
+ for module_id , state in list (graph .items ()):
575
+ new_messages = refresh_suppressed_submodules (
576
+ module_id , state .path , fine_grained_manager .deps , graph , self .fscache , refresh_file
577
+ )
578
+ if new_messages is not None :
579
+ messages = new_messages
578
580
579
581
t3 = time .time ()
580
582
581
583
# There may be new files that became available, currently treated as
582
584
# suppressed imports. Process them.
583
- seen_suppressed = set () # type: Set[str]
584
585
while True :
585
- # TODO: Merge seen and seen_suppressed?
586
- new_unsuppressed , seen_suppressed = self .find_added_suppressed (
587
- graph , seen_suppressed , manager .search_paths
588
- )
586
+ new_unsuppressed = self .find_added_suppressed (graph , seen , manager .search_paths )
589
587
if not new_unsuppressed :
590
588
break
591
589
new_files = [BuildSource (mod [1 ], mod [0 ]) for mod in new_unsuppressed ]
@@ -594,8 +592,15 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
594
592
messages = fine_grained_manager .update (new_unsuppressed , [])
595
593
596
594
for module_id , path in new_unsuppressed :
597
- refresh_suppressed_submodules (module_id , path , fine_grained_manager .deps , graph ,
598
- self .fscache )
595
+ new_messages = refresh_suppressed_submodules (
596
+ module_id , path ,
597
+ fine_grained_manager .deps ,
598
+ graph ,
599
+ self .fscache ,
600
+ refresh_file
601
+ )
602
+ if new_messages is not None :
603
+ messages = new_messages
599
604
600
605
t4 = time .time ()
601
606
@@ -604,7 +609,7 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
604
609
for module_id in orig_modules :
605
610
if module_id not in graph :
606
611
continue
607
- if module_id not in seen and module_id not in seen_suppressed :
612
+ if module_id not in seen :
608
613
module_path = graph [module_id ].path
609
614
assert module_path is not None
610
615
to_delete .append ((module_id , module_path ))
@@ -631,33 +636,35 @@ def fine_grained_increment_follow_imports(self, sources: List[BuildSource]) -> L
631
636
632
637
return messages
633
638
634
- def follow_imports (self ,
635
- sources : List [BuildSource ],
636
- graph : mypy .build .Graph ,
637
- seen : Set [str ],
638
- changed_paths : AbstractSet [str ],
639
- sources_set : Set [str ]) -> Tuple [List [Tuple [str , str ]],
640
- List [Tuple [str , str ]],
641
- List [BuildSource ]]:
642
- """Follow imports within graph from given sources.
639
+ def find_reachable_changed_modules (
640
+ self ,
641
+ roots : List [BuildSource ],
642
+ graph : mypy .build .Graph ,
643
+ seen : Set [str ],
644
+ changed_paths : AbstractSet [str ]) -> Tuple [List [Tuple [str , str ]],
645
+ List [BuildSource ]]:
646
+ """Follow imports within graph from given sources until hitting changed modules.
647
+
648
+ If we find a changed module, we can't continue following imports as the imports
649
+ may have changed.
643
650
644
651
Args:
645
- sources: roots of modules to search
652
+ roots: modules where to start search from
646
653
graph: module graph to use for the search
647
- seen: modules we've seen before that won't be visited (mutated here!)
654
+ seen: modules we've seen before that won't be visited (mutated here!! )
648
655
changed_paths: which paths have changed (stop search here and return any found)
649
- sources_set: set of sources (TODO: relationship with seen)
650
656
651
- Return (reachable changed modules, removed modules, updated file list).
657
+ Return (encountered reachable changed modules,
658
+ unchanged files not in sources_set traversed).
652
659
"""
653
660
changed = []
654
661
new_files = []
655
- worklist = sources [:]
662
+ worklist = roots [:]
656
663
seen .update (source .module for source in worklist )
657
664
while worklist :
658
665
nxt = worklist .pop ()
659
- if nxt .module not in sources_set :
660
- sources_set .add (nxt .module )
666
+ if nxt .module not in seen :
667
+ seen .add (nxt .module )
661
668
new_files .append (nxt )
662
669
if nxt .path in changed_paths :
663
670
assert nxt .path is not None # TODO
@@ -669,7 +676,7 @@ def follow_imports(self,
669
676
seen .add (dep )
670
677
worklist .append (BuildSource (graph [dep ].path ,
671
678
graph [dep ].id ))
672
- return changed , [], new_files
679
+ return changed , new_files
673
680
674
681
def direct_imports (self ,
675
682
module : Tuple [str , str ],
@@ -682,8 +689,14 @@ def direct_imports(self,
682
689
def find_added_suppressed (self ,
683
690
graph : mypy .build .Graph ,
684
691
seen : Set [str ],
685
- search_paths : SearchPaths ) -> Tuple [List [Tuple [str , str ]], Set [str ]]:
686
- """Find suppressed modules that have been added (and not included in seen)."""
692
+ search_paths : SearchPaths ) -> List [Tuple [str , str ]]:
693
+ """Find suppressed modules that have been added (and not included in seen).
694
+
695
+ Args:
696
+ seen: reachable modules we've seen before (mutated here!!)
697
+
698
+ Return suppressed, added modules.
699
+ """
687
700
all_suppressed = set ()
688
701
for module , state in graph .items ():
689
702
all_suppressed |= state .suppressed_set
@@ -693,7 +706,6 @@ def find_added_suppressed(self,
693
706
all_suppressed = {module for module in all_suppressed if module not in graph }
694
707
695
708
# TODO: Namespace packages
696
- # TODO: Handle seen?
697
709
698
710
finder = FindModuleCache (search_paths , self .fscache , self .options )
699
711
@@ -705,7 +717,7 @@ def find_added_suppressed(self,
705
717
found .append ((module , result ))
706
718
seen .add (module )
707
719
708
- return found , seen
720
+ return found
709
721
710
722
def increment_output (self ,
711
723
messages : List [str ],
0 commit comments