Skip to content
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

Support wildcards in module ignores #103

Merged
merged 27 commits into from
Sep 2, 2021
Merged

Support wildcards in module ignores #103

merged 27 commits into from
Sep 2, 2021

Conversation

kasium
Copy link
Contributor

@kasium kasium commented Aug 9, 2021

Resolves #44

@kasium kasium marked this pull request as draft August 9, 2021 14:11
@kasium
Copy link
Contributor Author

kasium commented Aug 9, 2021

@seddonym here is the first implementation draft. Please take a look if you see any issues before I move to the tests

Copy link
Owner

@seddonym seddonym left a comment

Choose a reason for hiding this comment

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

I really like the direction this is going, thanks!

docs/contract_types.rst Outdated Show resolved Hide resolved
src/importlinter/domain/fields.py Show resolved Hide resolved
src/importlinter/domain/helpers.py Outdated Show resolved Hide resolved
src/importlinter/domain/imports.py Outdated Show resolved Hide resolved
src/importlinter/domain/imports.py Outdated Show resolved Hide resolved
src/importlinter/domain/imports.py Outdated Show resolved Hide resolved
src/importlinter/domain/imports.py Outdated Show resolved Hide resolved
src/importlinter/domain/fields.py Outdated Show resolved Hide resolved
src/importlinter/domain/helpers.py Outdated Show resolved Hide resolved
src/importlinter/domain/helpers.py Show resolved Hide resolved
src/importlinter/domain/helpers.py Show resolved Hide resolved
src/importlinter/domain/imports.py Show resolved Hide resolved
docs/contract_types.rst Outdated Show resolved Hide resolved
@kasium
Copy link
Contributor Author

kasium commented Aug 20, 2021

So, any further comments?

@seddonym
Copy link
Owner

So, any further comments?

Sorry @kasium I thought I was waiting on you! I will try to look as soon as I can but it might be a week or so, sorry about that 😄

Copy link
Owner

@seddonym seddonym left a comment

Choose a reason for hiding this comment

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

This is shaping up really nicely.

Apart from a few tweaks, the main thing we're missing is tests. I suggest we stop marking this PR as a draft and move into the final stages!

PS I think you might need to rebase off the latest master - I tried to build the docs and there were some errors which aren't happening on master.

docs/contract_types.rst Outdated Show resolved Hide resolved
docs/contract_types.rst Outdated Show resolved Hide resolved
src/importlinter/domain/fields.py Outdated Show resolved Hide resolved
graph: ImportGraph, expressions: Iterable[ImportExpression]
) -> List[Dict[str, Union[str, int]]]:
imports: List[DirectImport] = []
for expression in expressions:
Copy link
Owner

Choose a reason for hiding this comment

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

Nice. I think it would be worth extracting lines 41 - 53 into a separate import_expressions_to_imports function, which would be a side-effect free function so easier to test.

It would be great to have unit test coverage too. If I were you I would focus the unit testing on the pure function import_expressions_to_imports - possibly don't need one for pop_import_expressions if we have coverage on the contract types instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some basic tests

src/importlinter/domain/fields.py Show resolved Hide resolved
tests/unit/domain/test_fields.py Show resolved Hide resolved
tests/unit/domain/test_imports.py Show resolved Hide resolved

def __init__(self, importer: str, imported: str) -> None:
self.importer = importer
self.imported = imported
Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps we should raise a ValueError if we get a malformed import expression, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess, then it make sense to extract the import expression validationto a util function or NOT to validate in ImportExpressionField


The following options can be used in all contracts.

- ``ignore_imports``: Optional list of imports, each in the form ``mypackage.foo.importer -> mypackage.bar.imported``.
Copy link
Owner

Choose a reason for hiding this comment

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

(Not related to documentation, but had to write this somewhere!) It would be great to have the following test coverage:

  • Unit tests for wildcarded ignore_imports for each contract type (see tests/unit/contracts).
  • Functional test coverage in tests/functional/test_lint_imports.py. I suggest just adding an illegal import, together with a wildcarded ignore_imports that covers it, to the contract in setup.cfg in that folder (which is used for checking contract adherence).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seddonym I can work further on the pure functions but I guess I don't have the time for extended tests. I really see the point of them, but it consumes a lot of time. Would you maybe just add them?

@kasium
Copy link
Contributor Author

kasium commented Aug 31, 2021

This is shaping up really nicely.

Apart from a few tweaks, the main thing we're missing is tests. I suggest we stop marking this PR as a draft and move into the final stages!

PS I think you might need to rebase off the latest master - I tried to build the docs and there were some errors which aren't happening on master.

Already on latest master, no clue

@kasium kasium requested a review from seddonym August 31, 2021 13:34
@seddonym
Copy link
Owner

seddonym commented Sep 1, 2021

Thanks for the latest changes, they look great. I've now fixed the issue on master, so rebasing off that should hopefully get the tests passing. Let's get this out of draft and with the existing tests passing.

I do want a bit more test coverage before merging to master but I'm happy to merge this into a branch on the main repo and then make the final changes there.

Thanks again for the excellent work!

@kasium kasium marked this pull request as ready for review September 1, 2021 12:08
@kasium kasium requested a review from seddonym September 1, 2021 12:38
@seddonym seddonym changed the base branch from master to wildcards September 2, 2021 08:06
Copy link
Owner

@seddonym seddonym left a comment

Choose a reason for hiding this comment

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

Thanks for all your hard work on this and bearing with all the rounds of feedback! I think we've got to a great place with it. I am not merging to master yet so I can add a few extra tests.

@seddonym seddonym merged commit f5b5a1d into seddonym:wildcards Sep 2, 2021
@kasium kasium deleted the issue-44 branch September 2, 2021 08:11
@kasium
Copy link
Contributor Author

kasium commented Sep 2, 2021

Great. Your feedback is always appreciated. I learned a lot during the iterations.

seddonym pushed a commit that referenced this pull request Sep 3, 2021
Support wildcards in module ignores
seddonym pushed a commit that referenced this pull request Sep 21, 2021
Support wildcards in module ignores
seddonym pushed a commit that referenced this pull request Sep 21, 2021
Support wildcards in module ignores
seddonym added a commit that referenced this pull request Sep 21, 2021
Support wildcards in module ignores

Co-authored-by: kasium <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude modules from the graph, according to wildcard expressions
2 participants