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

Issue 382 tag value parser #502

Merged
merged 43 commits into from
Mar 9, 2023

Conversation

meretp
Copy link
Collaborator

@meretp meretp commented Mar 3, 2023

fixes #382

Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Nice job on yet another monumental undertaking! :)
The overall structure looks very good, but I've got a few suggestions that might enhance the code even further.
Due to the non-standard nature of the library, I even suggest including some inline comments here and there to improve readability.

tests/spdx/parser/tagvalue/test_annotation_parser.py Outdated Show resolved Hide resolved
tests/spdx/parser/tagvalue/test_creation_info_parser.py Outdated Show resolved Hide resolved
tests/spdx/parser/tagvalue/test_creation_info_parser.py Outdated Show resolved Hide resolved
tests/spdx/parser/tagvalue/test_creation_info_parser.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/lexer/tagvalue.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/parser/tagvalue.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/parser/tagvalue.py Outdated Show resolved Hide resolved
@grammar_rule("pkg_comment : PKG_COMMENT text_or_line")
def p_pkg_comment(self, p):
self.check_that_current_element_matches_class_for_value(Package, p.lineno(1))
set_value(p, self.current_element, argument_name="comment")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Most of these rules are only separate from each other because the argument_name has to be set differently.
So here is a major refactoring suggestion: Put all those into p_generic_package_value and do the determination of argument_name there. Then, these last two lines above need only appear once.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

src/spdx/parser/tagvalue/parser/tagvalue.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/parser/tagvalue.py Outdated Show resolved Hide resolved
@meretp meretp force-pushed the issue-382-tag-value-parser branch 6 times, most recently from 5bdde3d to dcae948 Compare March 8, 2023 15:02
src/spdx/parser/tagvalue/lexer.py Outdated Show resolved Hide resolved
t.value = t.value[1:].strip()
return t

@TOKEN(r"\s*((ht|f)tps?:\/\/\S*)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would probably go with the latter: Just read in whatever "URI" is provided, and let validation handle the rest.

src/spdx/parser/tagvalue/parser.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/lexer.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/lexer/tagvalue.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Thanks, this starts to look really good now, probably I spent too much time with it already :D

src/spdx/parser/tagvalue/helper_methods.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/parser.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/parser.py Outdated Show resolved Hide resolved
src/spdx/parser/tagvalue/parser.py Show resolved Hide resolved
src/spdx/parser/tagvalue/parser.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@armintaenzertng armintaenzertng left a comment

Choose a reason for hiding this comment

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

Thank you very much!
I think this calls for a celebration! :D

meretp added 19 commits March 9, 2023 11:58
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
The code is taken from the current implementation, I added a decorator function to use instead of docstrings and adapted the code according to the new data model.

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
…d for construction

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
meretp added 24 commits March 9, 2023 11:58
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
[review] assert that only one relationship exists
[review] improve tests for package parser
[review] don't use assertCountEqual if list contains only one element
[review] add newline to <text> field
[review] delete default values in datetime
[fix] soften comparison of error messages to also support older python versions

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
[review] add comments to parser to improve code readability
[review] merge parsing methods for byte_range and line_range
[review] delete superfluous except block
[review] delete superfluous call to setdefault
[review] delete superfluous case distinction
[review] rename parameter
[review] get rid of docstrings
[review] rename

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
[review] use strings instead of p.slice
[review] merge generic parsing methods
[review] parse value only if the current_element matches
[review] merge parsing methods
[review] merge error methods for current elements
[review] delete tokens for enum values and let the parser take care of correct values

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
[review] use double quotes
[review] change file structure of tag value parser
[review] rename

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
[review] fix parsing of external document ref
[review] use only one dictionary
[review] return if multiple values for snippet range found

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
@meretp meretp force-pushed the issue-382-tag-value-parser branch from aa1ded4 to 97a8de4 Compare March 9, 2023 11:05
@meretp meretp merged commit e5af2eb into spdx:refactor-python-tools Mar 9, 2023
@meretp meretp deleted the issue-382-tag-value-parser branch March 9, 2023 11:13
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.

2 participants