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

Standalone contract #222

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

Conversation

sbrugman
Copy link
Contributor

@sbrugman sbrugman commented Feb 23, 2024

Closes #181

(Ending the PR streak here - hope we can merge them after some review and get another release out)

@seddonym
Copy link
Owner

Ending the PR streak here

Ha ha, thanks so much for all your work! It will take me a few days to go through everything, but excited to see what you've done.

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.

Nice work - this is nearly there.

Most of the comments are fairly minor / trivial, let me know if any questions.

Would you mind adding something to the CHANGELOG and your name to AUTHORS.rst?


**Configuration options**

- ``modules``: A list of modules/subpackages that should be independent of each other.
Copy link
Owner

Choose a reason for hiding this comment

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

This line needs to be updated as it's from the independence contract.

modules =
mypackage.bar
mypackage.baz
ignore_imports =
Copy link
Owner

Choose a reason for hiding this comment

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

I think it would be better to remove the ignore_imports section from the example, just so it's minimal.

**Configuration options**

- ``modules``: A list of modules/subpackages that should be independent of each other.
- ``ignore_imports``: See :ref:`Shared options`.
Copy link
Owner

Choose a reason for hiding this comment

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

We should also add unmatched_ignore_imports_alerting as an option.


type_name = "standalone"

modules = fields.ListField(subfield=fields.ModuleField())
Copy link
Owner

Choose a reason for hiding this comment

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

Any reason not to make this a SetField? Order isn't important...

output.print_error(f"- {downstream} is not allowed to import {upstream}")
output.new_line()

def _check_all_modules_exist_in_graph(self, graph: ImportGraph) -> None:
Copy link
Owner

Choose a reason for hiding this comment

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

Now that this is used by two contracts, would you mind moving this to contract_utils?


assert contract_check.kept, contract_check.metadata

def test_non_standalone_imported(self):
Copy link
Owner

Choose a reason for hiding this comment

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

Mind adding a test case for multiple importeds and importers to/from multiple modules, just to check the logic of handling multiple violations?

@@ -27,6 +27,9 @@ def __init__(self, name: str) -> None:
"""
self.name = name

def has_wildcard_expression(self) -> bool:
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this commit belongs in this PR, correct?

It would be interesting to support module expressions in standalone contracts, but perhaps that's left for another day!

@@ -0,0 +1,162 @@
from __future__ import annotations
Copy link
Owner

Choose a reason for hiding this comment

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

Nice tests, thanks!

session_options={"root_packages": ["mypackage"]},
contract_options={
"modules": ("mypackage.green", "mypackage.yellow"),
"ignore_imports": ["mypackage.yellow -> mypackage.other"],
Copy link
Owner

Choose a reason for hiding this comment

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

Very minor comment, but we could allow passing in the ignore_imports as an optional argument to the utility method.


- mypackage.green.b.a is not allowed to import mypackage.green.a.b

""" # noqa
Copy link
Owner

Choose a reason for hiding this comment

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

Why the noqa?

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.

Standalone contract
2 participants