Always write the cache (unless cache_dir is /dev/null)#3133
Always write the cache (unless cache_dir is /dev/null)#3133gvanrossum merged 6 commits intomasterfrom
Conversation
ambv
left a comment
There was a problem hiding this comment.
LGTM, I'd improve the error handling a bit.
| 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.
Alright, we can still override writing the cache by setting /dev/null.
👍
| @@ -891,7 +891,12 @@ def write_cache(id: str, path: str, tree: MypyFile, | |||
| manager.trace("Interface for {} has changed".format(id)) | |||
There was a problem hiding this comment.
Shouldn't the replace in :890 be only done if there's no OSError in :895?
mypy/build.py
Outdated
| try: | ||
| st = manager.get_stat(path) | ||
| except OSError: | ||
| manager.log("Cannot write {}".format(path)) |
There was a problem hiding this comment.
- We should try to delete the nonced file here (and the data file; it's invalidated by the mismatched
data_mtimeanyway). - Would also be good to at least stringify the OSError to get an idea why the stat failed.
- The error message is misleading. It's a source stat issue, not a cache write issue.
|
OK, I think I've made all the changes you suggested. I moved the get_stat() call up earlier so we don't even write anything if we can't stat() the source; and I also delete the cache files in that case (not sure if it's even needed now). |
|
A downside is that it slows down regular runs somewhat. (5-10%? I have to collect more serious data.) |
mypy/build.py
Outdated
| try: | ||
| st = manager.get_stat(path) | ||
| except OSError as err: | ||
| manager.log("Cannot get stat for {}: %s".format(path, err)) |
There was a problem hiding this comment.
Something is wrong with formatting here, this does not fail, but %s is never replaced (at least in Python 3.4 I just tried).
There was a problem hiding this comment.
Good eye, I am still not in the habit of using {} for format()...
There was a Travis-CI test failure, I presume it was due to runtests.py parallelizing jobs that share the cache?
mypy/build.py
Outdated
| try: | ||
| os.makedirs(parent) | ||
| except os.error: | ||
| pass # Assume it already exists. |
There was a problem hiding this comment.
You can just call os.makedirs(parent, exist_ok=True) instead (as of 3.2, https://docs.python.org/3/library/os.html#os.makedirs).
There was a problem hiding this comment.
Oh thanks! Why this isn't the default behavior I'll never understand (it's Eric Raymond's fault :-).
Fixes #3045
(How to test? I tested manually and it seems to work. It's also pretty straightforward.)