Add module expressions#188
Conversation
CodSpeed Performance ReportMerging #188 will not alter performanceComparing Summary
Benchmarks breakdown
|
c8456dd to
4ac6d87
Compare
| def test_finds_matching_modules(self): | ||
| graph = ImportGraph() | ||
| graph.add_module("foo") | ||
| graph.add_module("foo.bar") | ||
| graph.add_module("foo.bar.baz") | ||
|
|
||
| assert graph.find_matching_modules("foo") == {"foo"} | ||
| assert graph.find_matching_modules("foo.*") == {"foo.bar"} | ||
| assert graph.find_matching_modules("foo.**") == {"foo.bar", "foo.bar.baz"} |
There was a problem hiding this comment.
🍷 This test basically duplicates the rust test. For me it's okay to keep both.
There was a problem hiding this comment.
I think a good rule of thumb is that the Python tests should be comprehensive, and if we want to add some Rust tests to help too (even if they duplicate) then that's fine. Do you agree?
There was a problem hiding this comment.
Do you agree?
I think I could be persuaded either way. In the sense of a testing pyramid, one might argue that the rust tests should be the most comprehensive, since this is the closest we have to a unit test. All the python tests integrate the rust code, so by definition are higher up the pyramid, so we'd expect less comprehensive tests there.
That said, this isn't a normal testing pyramid, and the preexisting code puts most of the tests in python so there is definitely precedent to follow your suggestion.
In summary I think it's good to have both, certainly with comprehensive python tests. I'll flesh out the python tests a bit more.
There was a problem hiding this comment.
Thinking back to when we swapped in your Rust implementation, it was a really useful property of the test suite that there was thorough test coverage of the Python API - we just deleted all the Rust tests and still felt confident. If coverage had been split across the two languages then we wouldn't have been able to do that.
So I think focusing on the Python tests is worthwhile - we can treat the Rust tests more lightly as tests to help us as we go along, but more disposable.
Arguably the Python unit tests are still at the base of the testing pyramid - they're fast and give us lots of signal about granular behaviour.
There was a problem hiding this comment.
Yes okay I think you're right 👍
290c001 to
f202f7a
Compare
seddonym
left a comment
There was a problem hiding this comment.
Just leaving some early feedback - I haven't yet gone over everything in detail.
| graph.add_module("foo.bar") | ||
| graph.add_module("foo.bar.baz") | ||
|
|
||
| assert graph.find_matching_modules("foo") == {"foo"} |
There was a problem hiding this comment.
I'm reasonably confident that we have similar coverage - the rust test cases within module_expressions.rs cover all of that I think. There aren't many tests at the level of find_matching_modules and find_matching_direct_imports. Most of the testing is done as unit tests on the ModuleExpression i.e. test_parse and test_is_match.
There was a problem hiding this comment.
As per the other discussion, would you mind making sure the behaviour is covered by the Python tests, too? Or I can do it once everything else is ready on the PR.
| def test_finds_matching_modules(self): | ||
| graph = ImportGraph() | ||
| graph.add_module("foo") | ||
| graph.add_module("foo.bar") | ||
| graph.add_module("foo.bar.baz") | ||
|
|
||
| assert graph.find_matching_modules("foo") == {"foo"} | ||
| assert graph.find_matching_modules("foo.*") == {"foo.bar"} | ||
| assert graph.find_matching_modules("foo.**") == {"foo.bar", "foo.bar.baz"} |
There was a problem hiding this comment.
I think a good rule of thumb is that the Python tests should be comprehensive, and if we want to add some Rust tests to help too (even if they duplicate) then that's fine. Do you agree?
seddonym
left a comment
There was a problem hiding this comment.
Another round of comments.
The commits are on the large side for reviewing, by the way...
41ccd51 to
2e526a3
Compare
33f42f4 to
41aa83e
Compare
|
@seddonym I've spent some time working through your comments. I'm not sure if I quite got them all, there's quite a few - perhaps you can take a look and close off the ones you are happy with? |
41aa83e to
38c8b4d
Compare
38c8b4d to
a70d2a1
Compare
Remove the "bidirectional" from the function name, since this is the only path finding function we have. The "bidirectional" part is just an implementation detail.
a70d2a1 to
eb43939
Compare
seddonym
left a comment
There was a problem hiding this comment.
Ok I've finished the full review. It's looking great in general, thanks for your efforts!
I don't think there's much more to do on this, mainly it's just a few tweaks to comments.
Before merging to master, there are two blockers:
- Making sure the Python test coverage is comprehensive.
- Figuring out whether to represent import expressions as two-tuples or arrow-strings (let's discuss).
I'd be happy to merge this into a branch in my repo if it would help - then we could both work on the remainder. Let me know what you prefer.
| def test_finds_matching_modules(self): | ||
| graph = ImportGraph() | ||
| graph.add_module("foo") | ||
| graph.add_module("foo.bar") | ||
| graph.add_module("foo.bar.baz") | ||
|
|
||
| assert graph.find_matching_modules("foo") == {"foo"} | ||
| assert graph.find_matching_modules("foo.*") == {"foo.bar"} | ||
| assert graph.find_matching_modules("foo.**") == {"foo.bar", "foo.bar.baz"} |
There was a problem hiding this comment.
Thinking back to when we swapped in your Rust implementation, it was a really useful property of the test suite that there was thorough test coverage of the Python API - we just deleted all the Rust tests and still felt confident. If coverage had been split across the two languages then we wouldn't have been able to do that.
So I think focusing on the Python tests is worthwhile - we can treat the Rust tests more lightly as tests to help us as we go along, but more disposable.
Arguably the Python unit tests are still at the base of the testing pyramid - they're fast and give us lots of signal about granular behaviour.
| graph.add_module("foo.bar") | ||
| graph.add_module("foo.bar.baz") | ||
|
|
||
| assert graph.find_matching_modules("foo") == {"foo"} |
There was a problem hiding this comment.
As per the other discussion, would you mind making sure the behaviour is covered by the Python tests, too? Or I can do it once everything else is ready on the PR.
seddonym
left a comment
There was a problem hiding this comment.
Merging to the add-module-expressions working branch in the origin repo.
90ad8cf
into
python-grimp:add-module-expressions
Context: seddonym/import-linter#252
This PR adds module expressions to grimp. By moving module expressions into grimp, in particular into the rust code, we will be able to speed up lots of the import linter code that works with module expressions (import linter now supports module expressions in quite a few places).