Skip to content

Commit 5a7add8

Browse files
committed
Do a fine-grained incremental run when loading from cache
1 parent 6d24777 commit 5a7add8

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

mypy/build.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,11 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
11281128
if not stat.S_ISREG(st.st_mode):
11291129
manager.log('Metadata abandoned for {}: file {} does not exist'.format(id, path))
11301130
return None
1131+
1132+
if manager.options.use_fine_grained_cache:
1133+
manager.log('Using potentially stale metadata for {}'.format(id))
1134+
return meta
1135+
11311136
size = st.st_size
11321137
if size != meta.size:
11331138
manager.log('Metadata abandoned for {}: file {} has different size'.format(id, path))

mypy/dmypy_server.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from mypy.dmypy_util import STATUS_FILE, receive
2525
from mypy.gclogger import GcLogger
2626
from mypy.fscache import FileSystemCache
27-
from mypy.fswatcher import FileSystemWatcher
27+
from mypy.fswatcher import FileSystemWatcher, FileData
2828

2929

3030
def daemonize(func: Callable[[], None], log_file: Optional[str] = None) -> int:
@@ -266,11 +266,29 @@ def initialize_fine_grained(self, sources: List[mypy.build.BuildSource]) -> Dict
266266
manager = result.manager
267267
graph = result.graph
268268
self.fine_grained_manager = mypy.server.update.FineGrainedBuildManager(manager, graph)
269-
status = 1 if messages else 0
270-
self.previous_messages = messages[:]
271269
self.fine_grained_initialized = True
272270
self.previous_sources = sources
273271
self.fscache.flush()
272+
273+
# If we are using the fine-grained cache, build hasn't actually done
274+
# the typechecking on the updated files yet.
275+
# Run a fine-grained update starting from the cached data
276+
if self.options.use_fine_grained_cache:
277+
# Pull times and hashes out of the saved_cache and stick them into
278+
# the fswatcher, so we pick up the changes.
279+
for meta, mypyfile, type_map in manager.saved_cache.values():
280+
if meta.mtime is None: continue
281+
self.fswatcher.set_file_data(
282+
meta.path,
283+
FileData(st_mtime=float(meta.mtime), st_size=meta.size, md5=meta.hash))
284+
285+
# Run an update
286+
changed = self.find_changed(sources)
287+
if changed:
288+
messages += self.fine_grained_manager.update(changed)
289+
290+
status = 1 if messages else 0
291+
self.previous_messages = messages[:]
274292
return {'out': ''.join(s + '\n' for s in messages), 'err': '', 'status': status}
275293

276294
def fine_grained_increment(self, sources: List[mypy.build.BuildSource]) -> Dict[str, Any]:

mypy/fswatcher.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def __init__(self, fs: FileSystemCache) -> None:
3636
def paths(self) -> AbstractSet[str]:
3737
return self._paths
3838

39+
def set_file_data(self, path: str, data: FileData) -> None:
40+
self._file_data[path] = data
41+
3942
def add_watched_paths(self, paths: Iterable[str]) -> None:
4043
for path in paths:
4144
if path not in self._paths:

0 commit comments

Comments
 (0)