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

independence between children of a package #207

Closed
florianabel opened this issue Nov 13, 2023 · 2 comments
Closed

independence between children of a package #207

florianabel opened this issue Nov 13, 2023 · 2 comments

Comments

@florianabel
Copy link

First of all, thanks for the great work with this package, it's really useful.
Secondly, I am hoping, that my question is not out of scope, though I think it's a valid use case.

Use case

I am having a package with several sub-packages of integrations, i.e.

my_package.integrations
|
|---->integation_a
|---->integration_b
...

I am packaging them together for shipping reasons but would like to ensure, that they do not depend on each other and was trying to use an independence contract for it, but I could not get it to run like this.

Implementation intent

[[tool.importlinter.contracts]]
name = "My independence contract"
type = "independence"
modules = [
"my_package.integrations"
]

Also tried:
[[tool.importlinter.contracts]]
name = "My independence contract"
type = "independence"
modules = [
"my_package.integrations",
"my_package.integrations"
]

Working but sub-optimal solution

I could define all integrations specifically, but that would require future developers to continue adding them to the list when new integrations are being added and kind of defeats the purpose for me.
[[tool.importlinter.contracts]]
name = "My independence contract"
type = "independence"
modules = [
"my_package.integrations.integration_a",
"my_package.integrations.integration_b"
]

@seddonym
Copy link
Owner

Hi, thanks for suggestion!

I think this is a duplicate of #56, so I'm going to close this one - feel free to comment further on that PR.

Another option which you could use right now is to use a layers contract instead, and define the packages as sibling layers:

[importlinter:contract:my-layers-contract]
name = Contract with sibling layers
type = layers
containers = my_package.integrations
layers=
    integration_a | integration_b
exhaustive  = true

The advantage of this is that layers contracts support the exhaustive flag, which means that if a developer adds an integration without listing it here, the contract will fail. You could add a comment to the contract to ensure that the integration gets added as a sibling layer - or you could even add an additional test that verifies that your contract is the shape you're expecting by reading the contract using the Python API.

Hope helps!

@florianabel
Copy link
Author

Thanks a lot @seddonym! I think this will work for now, very helpful.

Will have a closer look and then maybe get back on it if further need be.

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

No branches or pull requests

2 participants