-
Notifications
You must be signed in to change notification settings - Fork 134
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
[Issue 305] add new json parser #366
[Issue 305] add new json parser #366
Conversation
7aa8bb9
to
dbe17bb
Compare
45d6c65
to
c675847
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this monumental effort :)
I have some initial remarks mostly concerned with (hopefully) improving readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! :)
Most comments concern the naming of things but there are a few that go a little deeper.
I haven't looked at the tests yet, but I feel like there aren't enough yet
|
||
elif person_match: | ||
name: str = person_match.group(1).strip() | ||
email: Optional[str] = ActorParser.get_email_or_none(person_match) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email: Optional[str] = ActorParser.get_email_or_none(person_match) | |
email: Optional[str] = person_match.group(4).strip() or None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way, we can discard the get_email_or_none
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wouldn't work. If person_match.group(4)
is None
(e.g. if the brackets for email are completely missing) this would lead to an AttributeError
. I also thought that this could be handled in one line but didn't find a good way besides using the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably need more tests to catch invalid inputs (open an issue for this) but the current state will do for now, I think.
e024400
to
0eb0629
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice going, I like the breadth of the tests much better now :)
Just a few remarks left
def parse_relationships(self, relationship_dicts: List[Dict]) -> List[Relationship]: | ||
logger = Logger() | ||
relationship_list = [] | ||
for relationship_dict in relationship_dicts: | ||
relationship_list = append_parsed_field_or_log_error(logger=logger, list_to_append_to=relationship_list, | ||
field=relationship_dict, method_to_parse=self.parse_relationship) | ||
raise_parsing_error_if_logger_has_messages(logger) | ||
return relationship_list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new double-lambda expressions may not be the prettiest (we might even consider helper methods which return the required functions there) but we lose quite a lot of weight in return, so I think it is worth it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort! :)
Only two minor comments left from my side
|
||
|
||
def parse_field_or_no_assertion_or_none(field: Optional[str], method_for_field: Callable = lambda x: x) -> Union[ | ||
SpdxNoAssertion, SpdxNone, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writing Any
in a Union does not make sense (as it just overwrites the other entries)
SpdxNoAssertion, SpdxNone, Any]: | |
SpdxNoAssertion, SpdxNone, str, None]: |
see also the next method below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but depending on the method_for_field
the return value could also be a LicenseExpressions
or an Actor
or anything else..So probably I should just write Any
as return type?
src/parser/json/package_parser.py
Outdated
supplier: Optional[Union[Actor, SpdxNoAssertion]] = parse_field_or_log_error(logger, | ||
package_dict.get("supplier"), | ||
lambda | ||
x: parse_field_or_no_assertion( | ||
x, | ||
self.actor_parser.parse_actor)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one escaped your reformatting ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
Signed-off-by: Meret Behrens <[email protected]>
…XParsingError if construction fails Signed-off-by: Meret Behrens <[email protected]>
…eadability Signed-off-by: Meret Behrens <[email protected]>
…with exception handling Signed-off-by: Meret Behrens <[email protected]>
…ationships Signed-off-by: Meret Behrens <[email protected]>
…s and method to handle exceptions when appending a list Signed-off-by: Meret Behrens <[email protected]>
…all changes Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
…ueError due to wrong format Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
…_str_to_enum_name Signed-off-by: Meret Behrens <[email protected]>
…use assertCountEqual to compare lists Signed-off-by: Meret Behrens <[email protected]>
…r SpdxNoAssertion Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
Signed-off-by: Meret Behrens <[email protected]>
c1ee766
to
347051a
Compare
fixes #305
Signed-off-by: Meret Behrens [email protected]