8000 squashed review commits with name fixes and comment improvement · HarshvMahawar/tools-python@af58dfa · GitHub
[go: up one dir, main page]

Skip to content

Commit af58dfa

Browse files
committed
squashed review commits with name fixes and comment improvement
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
1 parent 08ad4df commit af58dfa

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/spdx/parser/tagvalue/helper_methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def parse_checksum(checksum_str: str) -> Checksum:
5757
def set_value(parsed_value: YaccProduction, dict_to_fill: Dict[str, Any], argument_name: Optional[str] = None,
5858
method_to_apply: Callable = lambda x: x):
5959
if not argument_name:
60-
argument_name = get_property(parsed_value[1])
60+
argument_name = get_property_name(parsed_value[1])
6161
if argument_name in dict_to_fill:
6262
dict_to_fill["logger"].append(
6363
f"Multiple values for {parsed_value[1]} found. Line: {parsed_value.lineno(1)}")
@@ -72,7 +72,7 @@ def set_value(parsed_value: YaccProduction, dict_to_fill: Dict[str, Any], argume
7272
dict_to_fill["logger"].append(f"Invalid {parsed_value[1]}: {parsed_value[2]}. Line: {parsed_value.lineno(1)}")
7373

7474

75-
def get_property(tag: str):
75+
def get_property_name(tag: str):
7676
if tag not in TAG_DATA_MODEL_FIELD.keys():
7777
return camel_case_to_snake_case(tag)
7878
return TAG_DATA_MODEL_FIELD[tag][1]

src/spdx/parser/tagvalue/lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class SPDXLexer(object):
4141
# Package fields
4242
"PackageName": "PKG_NAME",
4343
"PackageVersion": "PKG_VERSION",
44-
"PackageDownloadLocation": "PKG_DOWWNLOAD_LOCATION",
44+
"PackageDownloadLocation": "PKG_DOWNLOAD_LOCATION",
4545
"FilesAnalyzed": "PKG_FILES_ANALYZED",
4646
"PackageSummary": "PKG_SUMMARY",
4747
"PackageSourceInfo": "PKG_SOURCE_INFO",

src/spdx/parser/tagvalue/parser.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def p_attrib(self, p):
119119
"pkg_license_concluded : PKG_LICENSE_CONCLUDED error\n source_info : PKG_SOURCE_INFO error\n "
120120
"homepage : PKG_HOMEPAGE error\n pkg_checksum : PKG_CHECKSUM error\n "
121121
"verification_code : PKG_VERIFICATION_CODE error\n originator : PKG_ORIGINATOR error\n "
122-
"download_location : PKG_DOWWNLOAD_LOCATION error\n files_analyzed : PKG_FILES_ANALYZED error\n "
122+
"download_location : PKG_DOWNLOAD_LOCATION error\n files_analyzed : PKG_FILES_ANALYZED error\n "
123123
"supplier : PKG_SUPPLIER error\n pkg_file_name : PKG_FILE_NAME error\n "
124124
"package_version : PKG_VERSION error\n primary_package_purpose : PRIMARY_PACKAGE_PURPOSE error\n "
125125
"built_date : BUILT_DATE error\n release_date : RELEASE_DATE error\n "
@@ -150,7 +150,7 @@ def p_current_element_error(self, p):
150150
"package_name : PKG_NAME LINE\n description : PKG_DESCRIPTION text_or_line\n "
151151
"summary : PKG_SUMMARY text_or_line\n source_info : PKG_SOURCE_INFO text_or_line\n "
152152
"homepage : PKG_HOMEPAGE line_or_no_assertion_or_none\n "
153-
"download_location : PKG_DOWWNLOAD_LOCATION line_or_no_assertion_or_none\n "
153+
"download_location : PKG_DOWNLOAD_LOCATION line_or_no_assertion_or_none\n "
154154
"originator : PKG_ORIGINATOR actor_or_no_assertion\n supplier : PKG_SUPPLIER actor_or_no_assertion\n "
155155
"pkg_comment : PKG_COMMENT text_or_line\n "
156156
"pkg_copyright_text : PKG_COPYRIGHT_TEXT line_or_no_assertion_or_none\n "
@@ -165,9 +165,7 @@ def p_current_element_error(self, p):
165165
"file_spdx_id : SNIPPET_FILE_SPDXID LINE\n "
166166
"snippet_license_concluded : SNIPPET_LICENSE_CONCLUDED license_or_no_assertion_or_none\n "
167167
"annotation_spdx_id : ANNOTATION_SPDX_ID LINE\n "
168-
"annotation_comment : ANNOTATION_COMMENT text_or_line\n "
169-
170-
)
168+
"annotation_comment : ANNOTATION_COMMENT text_or_line")
171169
def p_generic_value(self, p):
172170
if p[1] in EXPECTED_START_TAG_ELEMENT.keys():
173171
self.initialize_new_current_element(EXPECTED_START_TAG_ELEMENT[p[1]])
@@ -206,8 +204,9 @@ def p_actor_values(self, p):
206204

207205
@grammar_rule("spdx_id : SPDX_ID LINE")
208206
def p_spdx_id(self, p):
209-
# We assume that the documents spdx_id is defined first in the SPDXDocument, before any package or file
210-
# information. If this is not the case the parser will behave unexpectedly as the spdx_ids are assigned falsy.
207+
# As all SPDX Ids share the same tag, there is no knowing which spdx_id belongs to the document.
208+
# We assume that to be the first spdx_id we encounter. As the specification does not explicitly require this,
209+
# our approach might lead to unwanted behavior when the document's SPDX Id is defined later in the document.
211210
if "spdx_id" in self.creation_info:
212211
self.current_element["spdx_id"] = p[2]
213212
else:
@@ -302,7 +301,8 @@ def p_pkg_attribution_text(self, p):
302301
self.check_that_current_element_matches_class_for_value(Package, p.lineno(1))
303302
self.current_element.setdefault("attribution_texts", []).append(p[2])
304303

305-
@grammar_rule("pkg_external_ref : PKG_EXTERNAL_REF LINE PKG_EXTERNAL_REF_COMMENT text_or_line\n | PKG_EXTERNAL_REF LINE")
304+
@grammar_rule(
305+
"pkg_external_ref : PKG_EXTERNAL_REF LINE PKG_EXTERNAL_REF_COMMENT text_or_line\n | PKG_EXTERNAL_REF LINE")
306306
def p_pkg_external_refs(self, p):
307307
if not self.check_that_current_element_matches_class_for_value(Package, p.lineno(1)):
308308
return
@@ -516,9 +516,8 @@ def check_that_current_element_matches_class_for_value(self, expected_class, lin
516516

517517
def construct_current_element(self):
518518
if "class" not in self.current_element:
519-
# When the first element of the document is instantiated we don't have a current element in scope
520-
# and the key "class" doesn't exist. Additionally, if the first element doesn't have the expected start
521-
# value the key "class" wouldn't exist. To prevent a KeyError we use early return.
519+
# This happens when the first element is initialized via initialize_new_current_element() or if the first
520+
# element is missing its expected starting tag. In both cases we are unable to construct an element.
522521
return
523522

524523
clazz = self.current_element.pop("class")

tests/spdx/parser/tagvalue/test_tag_value_lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def test_tokenization_of_package(lexer):
159159
token_assert_helper(lexer.token(), "LINE", "SPDXRef-Package", 2)
160160
token_assert_helper(lexer.token(), "PKG_VERSION", "PackageVersion", 3)
161161
token_assert_helper(lexer.token(), "LINE", "Version 0.9.2", 3)
162-
token_assert_helper(lexer.token(), "PKG_DOWWNLOAD_LOCATION", "PackageDownloadLocation", 4)
162+
token_assert_helper(lexer.token(), "PKG_DOWNLOAD_LOCATION", "PackageDownloadLocation", 4)
163163
token_assert_helper(lexer.token(), "LINE", "http://example.com/test", 4)
164164
token_assert_helper(lexer.token(), "PKG_FILES_ANALYZED", "FilesAnalyzed", 5)
165165
token_assert_helper(lexer.token(), "LINE", "True", 5)

0 commit comments

Comments
 (0)
0