Skip to content

Conversation

ilevkivskyi
Copy link
Member

Fixes #3592

This invalidates all cache files if at least one plugin changes its __version__ or hash of its content (this will not catch situations when there are changes in modules imported by a plugin, and version is also imported, but such situations are probably very rare).

I was not sure where to place the check to invalidate all caches at the same time, so I invalidate them one by one.

@ilevkivskyi ilevkivskyi requested a review from JukkaL November 8, 2018 22:11
Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this will make plugins behave more reliably.

mypy/build.py Outdated
'(in {})'.format(plugin_path))
try:
custom_plugins.append(plugin_type(options))
# We record _both_ hash and the version to detect more
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is quite long. It would be better if this would be moved to a helper method to avoid making it even longer.

[out]
[out2]

[case testChangedPluginsInvalidateCache]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add another test where only the version changes (e.g. import version from another module so that the text of the plugin doesn't change).

# a mapping from each file being typechecked to its possible shadow file
self.shadow_equivalence_map = {} # type: Dict[str, Optional[str]]
self.plugin = plugin
self.plugins_snapshot = plugins_snapshot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document the new attributes in the class docstring.


[case testChangedPluginsInvalidateCache]
# flags: --config-file tmp/mypy.ini
import a
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add a fine-grained incremental test case where a plugin changes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, this will have no effect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I have found there is another daemon command dmypy run, which unlike dmypy check restarts if options change. I think we can also restart in dmypy run if plugins change. There is however no way to test this currently.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 9, 2018

There is a test failure.

@ilevkivskyi
Copy link
Member Author

Hm, this is weird, all tests pass locally. Also the error appears on the first run, which is even more weird.

@ilevkivskyi
Copy link
Member Author

OK, I also added restart for daemon if plugins change (in addition to cache invalidation) and tested manually that it works. @msullivan does this make sense to you?

@ilevkivskyi
Copy link
Member Author

@msullivan @JukkaL I assume this looks good now. Are there any other comments?

manager.trace(' {}: {} != {}'
.format(key, cached_options.get(key), current_options.get(key)))
return None
if manager.old_plugins_snapshot and manager.plugins_snapshot:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a test for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't yet add tests for daemon. I opened #5891 for this.

@ilevkivskyi ilevkivskyi merged commit 74c5070 into python:master Nov 14, 2018
@ilevkivskyi ilevkivskyi deleted the invalidate-plugin-change branch November 14, 2018 00:34
ilevkivskyi added a commit that referenced this pull request Nov 14, 2018
#5878 added cache invalidation for situations where a plugin version/hash changes but there is even simpler scenario -- if `plugins` option itself change, the cache should be invalidated as well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants