-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Always write the cache (unless cache_dir is /dev/null) #3133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b3578a5
Always write the cache (unless cache_dir is /dev/null)
3f4706c
Respond to review; move get_stat(path) up and be more robust
1338bca
Fix format string
49a6665
Merge branch 'master' into always-write-cache
114be68
Handle a rare race condition with makedirs().
c836125
Better fix for makedirs() race
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -860,8 +860,7 @@ def write_cache(id: str, path: str, tree: MypyFile, | |
|
||
# Make sure directory for cache files exists | ||
parent = os.path.dirname(data_json) | ||
if not os.path.isdir(parent): | ||
os.makedirs(parent) | ||
os.makedirs(parent, exist_ok=True) | ||
assert os.path.dirname(meta_json) == parent | ||
|
||
# Construct temp file names | ||
|
@@ -877,6 +876,20 @@ def write_cache(id: str, path: str, tree: MypyFile, | |
data_str = json.dumps(data, sort_keys=True) | ||
interface_hash = compute_hash(data_str) | ||
|
||
# Obtain and set up metadata | ||
try: | ||
st = manager.get_stat(path) | ||
except OSError as err: | ||
manager.log("Cannot get stat for {}: {}".format(path, err)) | ||
# Remove apparently-invalid cache files. | ||
for filename in [data_json, meta_json]: | ||
try: | ||
os.remove(filename) | ||
except OSError: | ||
pass | ||
# Still return the interface hash we computed. | ||
return interface_hash | ||
|
||
# Write data cache file, if applicable | ||
if old_interface_hash == interface_hash: | ||
# If the interface is unchanged, the cached data is guaranteed | ||
|
@@ -891,8 +904,6 @@ def write_cache(id: str, path: str, tree: MypyFile, | |
os.replace(data_json_tmp, data_json) | ||
manager.trace("Interface for {} has changed".format(id)) | ||
|
||
# Obtain and set up metadata | ||
st = manager.get_stat(path) # TODO: Handle errors | ||
mtime = st.st_mtime | ||
size = st.st_size | ||
options = manager.options.clone_for_module(id) | ||
|
@@ -1524,26 +1535,26 @@ def valid_references(self) -> Set[str]: | |
return valid_refs | ||
|
||
def write_cache(self) -> None: | ||
ok = self.path and self.options.incremental | ||
if ok: | ||
if self.manager.options.quick_and_dirty: | ||
is_errors = self.manager.errors.is_errors_for_file(self.path) | ||
else: | ||
is_errors = self.manager.errors.is_errors() | ||
ok = not is_errors | ||
if ok: | ||
dep_prios = [self.priorities.get(dep, PRI_HIGH) for dep in self.dependencies] | ||
new_interface_hash = write_cache( | ||
self.id, self.path, self.tree, | ||
list(self.dependencies), list(self.suppressed), list(self.child_modules), | ||
dep_prios, self.interface_hash, | ||
self.manager) | ||
if new_interface_hash == self.interface_hash: | ||
self.manager.log("Cached module {} has same interface".format(self.id)) | ||
else: | ||
self.manager.log("Cached module {} has changed interface".format(self.id)) | ||
self.mark_interface_stale() | ||
self.interface_hash = new_interface_hash | ||
if not self.path or self.options.cache_dir == os.devnull: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, we can still override writing the cache by setting /dev/null. 👍 |
||
return | ||
if self.manager.options.quick_and_dirty: | ||
is_errors = self.manager.errors.is_errors_for_file(self.path) | ||
else: | ||
is_errors = self.manager.errors.is_errors() | ||
if is_errors: | ||
return | ||
dep_prios = [self.priorities.get(dep, PRI_HIGH) for dep in self.dependencies] | ||
new_interface_hash = write_cache( | ||
self.id, self.path, self.tree, | ||
list(self.dependencies), list(self.suppressed), list(self.child_modules), | ||
dep_prios, self.interface_hash, | ||
self.manager) | ||
if new_interface_hash == self.interface_hash: | ||
self.manager.log("Cached module {} has same interface".format(self.id)) | ||
else: | ||
self.manager.log("Cached module {} has changed interface".format(self.id)) | ||
self.mark_interface_stale() | ||
self.interface_hash = new_interface_hash | ||
|
||
|
||
def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph: | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the
replace
in :890 be only done if there's no OSError in :895?