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

[DOP-3921]: Implement concrete Facet type #500

Merged
merged 21 commits into from
Aug 11, 2023
Merged

[DOP-3921]: Implement concrete Facet type #500

merged 21 commits into from
Aug 11, 2023

Conversation

branberry
Copy link
Collaborator

@branberry branberry commented Aug 9, 2023

Ticket

DOP-3921

Notes

This PR implements a new data class to represent the Facet data type. It also incorporates facet validation for the facets.toml file.

Updates were made in the postprocessor as well to handle the new Facet type.

value: str
sub_facets: Optional[List["Facet"]] = None

def __lt__(self, other: "Facet") -> bool:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added for testing purposes so that we can sort the Facet array

Copy link
Collaborator Author

@branberry branberry Aug 10, 2023

Choose a reason for hiding this comment

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

I moved these back into a separate project directory since they required me to update the test_project.py test() function every time a change was made here that are irrelevant to the test() function.

For example, there was a test to verify that there were no diagnostics, but with these facets, diagnostics are returned for missing facets. Moving this to a separate directory should go through the same code path, but it shouldn't interfere with other tests.

@branberry branberry changed the title Dop 3921 [DOP-3921]: Implement concrete Facet type Aug 10, 2023
@branberry branberry marked this pull request as ready for review August 10, 2023 18:28
@@ -44,9 +44,10 @@ def get_taxonomy(cls) -> "TaxonomySpec":
@classmethod
def validate_key_value_pairs(cls, facet_str_pairs: List[Tuple[str, str]]) -> None:
taxonomy_ref = asdict(cls.get_taxonomy())
facet_pairs = copy.deepcopy(facet_str_pairs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because tuples and strings are both immutable, you don't actually have to do a deepcopy! Just do facet_pairs = facet_str_pairs[:]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, perhaps it would be better for this method to take a Sequence[] than a List[] if we're not mutating it?

try:
while len(facet_str_pairs) > 0:
key, value = facet_str_pairs.pop()
while len(facet_pairs) > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can just be while facet_pairs:


if self.parent_stack:
parent = self.parent_stack[-1][0]
if isinstance(parent.sub_facets, list):
Copy link
Collaborator

@i80and i80and Aug 11, 2023

Choose a reason for hiding this comment

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

sub_facets is an Optional[list] right? Much better if that's the case to just have

if parent.sub_facets is not None:
    parent.sub_facets.append(facet_node)

snooty/parser.py Outdated
curr_facet, diagnostics = self.config.load_facets_from_file(facet_path)

if curr_facet is None:
logger.warning(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this actually sounds like a logger.error()

But would it be a diagnostic instead of just a logging message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's correct! It would be a diagnostic, and it should already be included in the result. I'll remove this log.

@branberry branberry requested a review from i80and August 11, 2023 13:28
Copy link
Collaborator

@i80and i80and left a comment

Choose a reason for hiding this comment

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

:shipit:

taxonomy_ref = asdict(cls.get_taxonomy())
facet_pairs = list(facet_str_pairs[:])
Copy link
Collaborator

@i80and i80and Aug 11, 2023

Choose a reason for hiding this comment

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

Oh, I didn't notice that it's a Sequence. list() already does a copy, so this should just be list(facet_str_pairs)

@branberry branberry merged commit a9811f2 into master Aug 11, 2023
4 of 6 checks passed
@branberry branberry deleted the DOP-3921 branch August 11, 2023 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants