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

Add as_packages to Forbidden contracts #229

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

NicholasBunn
Copy link

@NicholasBunn NicholasBunn commented Aug 2, 2024

Following on from the work to add further as_packages support to Grimp here, this PR adds the as_packages options to Forbidden contracts so that we can forbid modules in addition to entire packages. The default behaviour remains, treating all imports as packages

This change would serve to fix this issue (or implement the feature, I guess?)

@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch 4 times, most recently from 937046f to 9227c71 Compare November 8, 2024 12:56
@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch 2 times, most recently from 70ff3b4 to 84c664e Compare November 8, 2024 13:59
@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch 2 times, most recently from 063c8be to c2a9d25 Compare November 8, 2024 15:33
Comment on lines +105 to +142
(
False,
(
"mypackage.blue",
"mypackage.green",
"mypackage.yellow",
"mypackage.purple",
),
[
{
"upstream_module": "mypackage.green",
"downstream_module": "mypackage.three",
"chains": [
[
{
"importer": "mypackage.three",
"imported": "mypackage.green",
"line_numbers": (4,),
}
]
],
},
{
"upstream_module": "mypackage.purple",
"downstream_module": "mypackage.two",
"chains": [
[
{
"importer": "mypackage.two",
"imported": "mypackage.utils",
"line_numbers": (9,),
},
{
"importer": "mypackage.utils",
"imported": "mypackage.purple",
"line_numbers": (1,),
},
]
],
},
],
),
],
)
Copy link
Author

Choose a reason for hiding this comment

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

🍷 This is a new test case

@pytest.mark.parametrize(
"as_packages",
(
("False"),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 New test case

def test_is_broken_when_forbidden_external_modules_imported(self):
@pytest.mark.parametrize(
"as_packages",
(False, True),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 False is a new test case

@pytest.mark.parametrize(
"as_packages",
(
("False"),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 New test case

@pytest.mark.parametrize(
"as_packages",
(
("False"),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 New test case

Comment on lines +455 to +466
False,
("mypackage.green",),
[
{
"upstream_module": "mypackage.green",
"downstream_module": "mypackage.three",
"chains": [
[
{
"importer": "mypackage.three",
"imported": "mypackage.green",
"line_numbers": (4,),
},
]
],
},
],
),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 New test case

def test_ignore_imports_with_recursive_wildcards(self):
@pytest.mark.parametrize(
"as_packages",
(False, True),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 False is a new test case

@pytest.mark.parametrize(
"as_packages",
(
("False"),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 New test case

@pytest.mark.parametrize(
"as_packages",
(
("False"),
Copy link
Author

Choose a reason for hiding this comment

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

🍷 New test case

* Fabian Binz - https://github.com/fbinz
Copy link
Author

Choose a reason for hiding this comment

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

Not sure why this has registered as a change 🤔

Copy link
Owner

Choose a reason for hiding this comment

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

It's just because there is a line ending added to the end of that line.

@NicholasBunn NicholasBunn marked this pull request as draft November 8, 2024 15:39
@NicholasBunn NicholasBunn marked this pull request as ready for review November 8, 2024 15:39
@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch from c2a9d25 to d202c51 Compare November 22, 2024 14:04
@seddonym seddonym self-requested a review November 25, 2024 12:50
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.

Looking great!

I would approve it, but the checks aren't passing. I suspect you'll need to put # type:ignore comments on those - contract fields don't play well with mypy.

Nothing else is blocking. If you felt like adding public facing docs then that would be appreciated, but I can also do it in a follow up if you prefer.

CHANGELOG.rst Outdated Show resolved Hide resolved
tests/unit/contracts/test_forbidden.py Outdated Show resolved Hide resolved
tests/unit/contracts/test_forbidden.py Outdated Show resolved Hide resolved
src/importlinter/contracts/forbidden.py Show resolved Hide resolved
* Fabian Binz - https://github.com/fbinz
Copy link
Owner

Choose a reason for hiding this comment

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

It's just because there is a line ending added to the end of that line.

@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch from d202c51 to 8165aaa Compare November 25, 2024 16:26
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.

The tests are still failing - are you able to run tox -echeck locally to see if you can reproduce?

docs/contract_types.rst Show resolved Hide resolved
@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch 2 times, most recently from 754e08d to a3b20e3 Compare December 4, 2024 12:54
@seddonym seddonym self-requested a review December 4, 2024 15:39
docs/contract_types.rst Outdated Show resolved Hide resolved
Implement the funcitonality for treating the forbidden modules as a module rather than a package. If this is specified, we set the source_moduels and forbidden_modules as the package name rather than finding all downstream modules of that package.
@NicholasBunn NicholasBunn force-pushed the feature/add_package_support_to_forbidden_contracts branch from a3b20e3 to 83f2e8d Compare December 6, 2024 10:04
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.

Support "forbidden" contracts within packages (again)
2 participants