Skip to content

Commit

Permalink
Don't delete fine-grained deps cache when a module has an error (#6333)
Browse files Browse the repository at this point in the history
The dependencies are created by other modules, so it is wrong to throw
away the dependency information, since it won't be recreated when the
module is fixed and rechecked.

Previously the behavior was to *crash*, which is bad.
  • Loading branch information
msullivan committed Feb 4, 2019
1 parent 3a12dab commit 34ea2af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,13 +1315,16 @@ def delete_cache(id: str, path: str, manager: BuildManager) -> None:
see #4043 for an example.
"""
path = manager.normpath(path)
cache_paths = get_cache_names(id, path, manager)
# We don't delete .deps files on errors, since the dependencies
# are mostly generated from other files and the metadata is
# tracked separately.
meta_path, data_path, _ = get_cache_names(id, path, manager)
cache_paths = [meta_path, data_path]
manager.log('Deleting {} {} {}'.format(id, path, " ".join(x for x in cache_paths if x)))

for filename in cache_paths:
try:
if filename:
manager.metastore.remove(filename)
manager.metastore.remove(filename)
except OSError as e:
if e.errno != errno.ENOENT:
manager.log("Error deleting cache file {}: {}".format(filename, e.strerror))
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -3630,6 +3630,19 @@ def foo() -> None:
[out2]
tmp/main.py:2: error: "int" has no attribute "foo"

[case testIncrementalFineGrainedCacheError1]
# flags: --cache-fine-grained --no-sqlite-cache
import a
[file a.py]
[file b.py]
x = 0
[file a.py.2]
from b import x
1 + 'lol'
[out]
[out2]
tmp/a.py:2: error: Unsupported operand types for + ("int" and "str")

[case testIncrementalBustedFineGrainedCache1]
# flags: --cache-fine-grained --no-sqlite-cache
import a
Expand Down

0 comments on commit 34ea2af

Please sign in to comment.