Repository navigation
Bug fixes #207
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
Bug fixes #207
Changes from all commits
277a517
bccf672
597978e
5986c91
0f615ee
cbae4c0
e6122e2
716905b
3395930
fe40893
5fc3694
a6cee6a
bd45d41
3fdd1a4
25abc73
6a48660
b316c0c
e7d4f51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| [metadata] | ||
| license_file = LICENSE | ||
|
|
||
| [bdist_wheel] | ||
| universal=1 | ||
|
|
||
| [aliases] | ||
| release = clean --all sdist --formats=gztar bdist_wheel |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -271,11 +271,17 @@ def validate_str_fields(self, fields, optional, messages): | |
| return messages | ||
|
|
||
| def validate_checksum(self, messages): | ||
| if self.check_sum is not None: | ||
| if not isinstance(self.check_sum, checksum.Algorithm): | ||
| messages.append( | ||
| "Package checksum must be instance of spdx.checksum.Algorithm" | ||
| ) | ||
| try: | ||
| if self.check_sum is not None: | ||
| if not isinstance(self.check_sum, checksum.Algorithm): | ||
| messages.append( | ||
| "Package checksum must be instance of spdx.checksum.Algorithm" | ||
| ) | ||
| # this check was added by the WhiteSouse PS Team ( for cases where SHA1 is not available at WhiteSource ) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't seen such attribution comments elsewhere in the project, and I don't think they are viable. If there are many contributors, it would lead to a lot of clutter. I would be grateful if you remove them here and in other locations where they were added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @nicoweidner - will do
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @rammatzkvosky ! Since we didn't hear back for a while, @meretp took over this PR and put up a new version here. Hope that is alright! |
||
| if not self.check_sum.value: | ||
| delattr(self, 'check_sum') | ||
|
Comment on lines
+281
to
+282
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what this accomplishes. If a checksum object without a value is present, it gets removed - does some downstream check depend on this? Sorry if I am being slow here, I just started working on this project 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nicoweidner -In our platform, there are cases where a package sha1 is missing ( empty value ). For that reason, we add this check. |
||
| except: | ||
| pass | ||
|
Comment on lines
+283
to
+284
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just swallowing all exceptions is bad. Why was this added? |
||
|
|
||
| return messages | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -82,6 +82,9 @@ def __init__(self, relationship=None, relationship_comment=None): | |||||||||||
| self.relationship = relationship | ||||||||||||
| self.relationship_comment = relationship_comment | ||||||||||||
|
|
||||||||||||
| def __eq__(self, other): | ||||||||||||
| return True if self.relationship == other.relationship else False | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should include an instance check on the other object:
Suggested change
|
||||||||||||
|
|
||||||||||||
| @property | ||||||||||||
| def has_comment(self): | ||||||||||||
| return self.relationship_comment is not None | ||||||||||||
|
|
@@ -103,7 +106,7 @@ def validate(self, messages): | |||||||||||
| Check that all the fields are valid. | ||||||||||||
| Appends any error messages to messages parameter shall be a ErrorMessages. | ||||||||||||
| """ | ||||||||||||
| self.validate_relationship(messages) | ||||||||||||
| return self.validate_relationship(messages) | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! From a quick look, I see the same thing happening for annotations. I will create a separate issue for this. |
||||||||||||
|
|
||||||||||||
| def validate_relationship(self, messages): | ||||||||||||
| r_type = self.relationship.split(" ")[1] | ||||||||||||
|
|
@@ -112,3 +115,5 @@ def validate_relationship(self, messages): | |||||||||||
| "Relationship type must be one of the constants defined in " | ||||||||||||
| "class spdx.relationship.Relationship" | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| return messages | ||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,20 @@ | |||||
| from spdx.writers.tagvalue import InvalidDocumentError | ||||||
| from spdx.writers.jsonyamlxml import Writer | ||||||
| from spdx.parsers.loggers import ErrorMessages | ||||||
| import numpy as np | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove the dependency on |
||||||
| import datetime | ||||||
|
|
||||||
|
|
||||||
| # this method has been added by the WhiteSouse PS Team. | ||||||
| def json_converter(obj): | ||||||
| if isinstance(obj, np.integer): | ||||||
| return int(obj) | ||||||
| elif isinstance(obj, np.floating): | ||||||
| return float(obj) | ||||||
| elif isinstance(obj, np.ndarray): | ||||||
| return obj.tolist() | ||||||
| elif isinstance(obj, datetime.datetime): | ||||||
|
Comment on lines
+22
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the documentation, I believe the I also verified this myself: If you don't raise |
||||||
| return obj.__str__() | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| def write_document(document, out, validate=True): | ||||||
|
|
@@ -26,4 +40,4 @@ def write_document(document, out, validate=True): | |||||
|
|
||||||
| writer = Writer(document) | ||||||
| document_object = writer.create_document() | ||||||
| json.dump(document_object, out, indent=4) | ||||||
| json.dump(document_object, out, indent=4, default=json_converter) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the use case for numpy type serialization. The internal representation of the SPDX document should always be created by the tool itself (using either "parse document" or "convert document"). So how would we ever end up in a situation where it contains numpy types that need to be serialized? |
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -47,7 +47,9 @@ def checksum(self, checksum_field): | |||||
| """ | ||||||
| checksum_object = dict() | ||||||
| checksum_object["algorithm"] = ( | ||||||
| "checksumAlgorithm_" + checksum_field.identifier.lower() | ||||||
| #"checksumAlgorithm_" + checksum_field.identifier.lower() | ||||||
| # Changed by the WhiteSouse PS Team. | ||||||
| checksum_field.identifier | ||||||
|
Comment on lines
-50
to
+52
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I agree that the |
||||||
| ) | ||||||
| checksum_object["checksumValue"] = checksum_field.value | ||||||
| return checksum_object | ||||||
|
|
@@ -112,16 +114,16 @@ def create_package_info(self, package): | |||||
| package_object["SPDXID"] = self.spdx_id(package.spdx_id) | ||||||
| package_object["name"] = package.name | ||||||
| package_object["downloadLocation"] = package.download_location.__str__() | ||||||
| package_object["packageVerificationCode"] = self.package_verification_code( | ||||||
| package | ||||||
| ) | ||||||
| package_object["licenseConcluded"] = self.license(package.conc_lics) | ||||||
| package_object["licenseInfoFromFiles"] = list( | ||||||
| map(self.license, package.licenses_from_files) | ||||||
| ) | ||||||
| package_object["licenseDeclared"] = self.license(package.license_declared) | ||||||
| package_object["copyrightText"] = package.cr_text.__str__() | ||||||
|
|
||||||
| if package.verif_code is not None: | ||||||
| package_object["packageVerificationCode"] = self.package_verification_code(package) | ||||||
|
Comment on lines
+124
to
+125
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||||||
|
|
||||||
| if package.has_optional_field("version"): | ||||||
| package_object["versionInfo"] = package.version | ||||||
|
|
||||||
|
|
@@ -145,7 +147,8 @@ def create_package_info(self, package): | |||||
|
|
||||||
| if package.has_optional_field("check_sum"): | ||||||
| package_object["checksums"] = [self.checksum(package.check_sum)] | ||||||
| package_object["sha1"] = package.check_sum.value | ||||||
| # package_object["sha1"] = package.check_sum.value | ||||||
| # commented by the WS PS Team, sha1 is already exist in check_sum | ||||||
|
Comment on lines
+150
to
+151
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, but can you please remove the comments? |
||||||
|
|
||||||
| if package.has_optional_field("description"): | ||||||
| package_object["description"] = package.description | ||||||
|
|
@@ -156,6 +159,9 @@ def create_package_info(self, package): | |||||
| if package.has_optional_field("homepage"): | ||||||
| package_object["homepage"] = package.homepage.__str__() | ||||||
|
|
||||||
| if package.has_optional_field("files_analyzed"): | ||||||
| package_object["filesAnalyzed"] = package.files_analyzed | ||||||
|
Comment on lines
+162
to
+163
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yet another good catch! I think this project really needs more extensive test cases to catch issues like this. |
||||||
|
|
||||||
| return package_object | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -371,9 +377,16 @@ def __init__(self, document): | |||||
|
|
||||||
| def create_extracted_license(self): | ||||||
| extracted_license_objects = [] | ||||||
| extracted_licenses = self.document.extracted_licenses | ||||||
| # commented by the WS PS Team | ||||||
| # extracted_licenses = self.document.extracted_licenses | ||||||
|
|
||||||
| # filter by unique identifier attribute in ExtractedLicense object, added by the WhiteSouse PS Team | ||||||
| unique_extracted_licenses = {} | ||||||
| for lic in self.document.extracted_licenses: | ||||||
| if lic.identifier not in unique_extracted_licenses.keys(): | ||||||
| unique_extracted_licenses[lic.identifier] = lic | ||||||
|
|
||||||
| for extracted_license in extracted_licenses: | ||||||
| for extracted_license in unique_extracted_licenses.values(): | ||||||
|
Comment on lines
+380
to
+389
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another good change - from my understanding at least, extracted license ids should be unique within one document. While this is fine in this PR, I think on a higher level it would be nicer to sure that the internal representation of the document is valid before passing it to the writer. Then the writer wouldn't need to include such checks. But that is a change for another time... However, please remove the comments :-) |
||||||
| extracted_license_object = dict() | ||||||
|
|
||||||
| if isinstance(extracted_license.identifier, Literal): | ||||||
|
|
@@ -471,13 +484,37 @@ def create_document(self): | |||||
| self.document_object["SPDXID"] = self.spdx_id(self.document.spdx_id) | ||||||
| self.document_object["name"] = self.document.name | ||||||
|
|
||||||
| # filter by unique spdx_id attribute in Package object, added by the WhiteSouse PS Team | ||||||
| unique_doc_packages = {} | ||||||
| for doc_package in self.document.packages: | ||||||
| if doc_package.spdx_id not in unique_doc_packages.keys(): | ||||||
| unique_doc_packages[doc_package.spdx_id] = doc_package | ||||||
|
Comment on lines
+488
to
+491
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the extracted licenses: Fine for now, but eventually I would move this to validations |
||||||
|
|
||||||
| # commented by the WS PS Team | ||||||
| # package_objects = [] | ||||||
| # for package in self.document.packages: | ||||||
| # package_info_object = self.create_package_info(package) | ||||||
| # package_info_object["files"] = self.create_file_info(package) | ||||||
| # package_objects.append({"Package": package_info_object}) | ||||||
| # | ||||||
| # self.document_object["documentDescribes"] = package_objects | ||||||
|
|
||||||
| # the previous code block has been adjusted by the WhiteSouse PS Team. | ||||||
| # adding documentDescribes and packages sections. | ||||||
|
Comment on lines
+493
to
+503
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the comments. It will be in the git history anyway, and the comments will just clutter the code |
||||||
| package_objects = [] | ||||||
| for package in self.document.packages: | ||||||
| document_describes_objects = [] | ||||||
| for package in unique_doc_packages.values(): | ||||||
| package_info_object = self.create_package_info(package) | ||||||
| package_info_object["files"] = self.create_file_info(package) | ||||||
| package_objects.append({"Package": package_info_object}) | ||||||
| if package.files: | ||||||
| package_info_object["files"] = self.create_file_info(package) | ||||||
| # create a list of the packages' names for the 'documentDescribes' field | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| package_spdxid = package_info_object.get("SPDXID") | ||||||
| document_describes_objects.append(package_spdxid) | ||||||
| package_objects.append(package_info_object) | ||||||
|
|
||||||
| self.document_object["documentDescribes"] = package_objects | ||||||
| self.document_object["documentDescribes"] = document_describes_objects | ||||||
| self.document_object["packages"] = package_objects | ||||||
| # end | ||||||
|
|
||||||
| if self.document.has_comment: | ||||||
| self.document_object["comment"] = self.document.comment | ||||||
|
|
@@ -504,4 +541,6 @@ def create_document(self): | |||||
| if self.document.relationships: | ||||||
| self.document_object["relationships"] = self.create_relationship_info() | ||||||
|
|
||||||
| return {"Document": self.document_object} | ||||||
| # return {"Document": self.document_object}. No need in "Document" key for json and tv format. | ||||||
| # Changed by the WhiteSouse PS Team. | ||||||
|
Comment on lines
+544
to
+545
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more superfluous comments |
||||||
| return self.document_object | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -569,7 +569,7 @@ def relationships(self): | |
| """ | ||
| Return a list of relationship nodes | ||
| """ | ||
| return map(self.create_relationship_node, self.document.relationships) | ||
| return list(map(self.create_relationship_node, self.document.relationships)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes a difference here whether we return an iterable or a list. The doc says it returns a list, but then again all other similar functions return an iterable as well, so I'm inclined to leave it that way (or fix all the docs) |
||
|
|
||
|
|
||
| class CreationInfoWriter(BaseWriter): | ||
|
|
@@ -1016,10 +1016,11 @@ def write(self): | |
| for package_node in self.packages(): | ||
| package_triple = (doc_node, self.spdx_namespace.describesPackage, package_node) | ||
| self.graph.add(package_triple) | ||
| """# Add relationship | ||
| relate_node = self.relationships() | ||
| relate_triple = (doc_node, self.spdx_namespace.relationship, relate_node) | ||
| self.graph.add(relate_triple)""" | ||
| # Add relationship | ||
| for relate_node in self.relationships(): | ||
| relate_triple = (doc_node, self.spdx_namespace.relationship, relate_node) | ||
| self.graph.add(relate_triple) | ||
|
Comment on lines
+1019
to
+1022
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this out using and the output contained this, which doesn't seem to make sense (relationships should be separate entities): I think this either needs more work, or should be handled as a separate issue - whichever way you prefer! |
||
|
|
||
| # Add snippet | ||
| snippet_nodes = self.snippets() | ||
| for snippet in snippet_nodes: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ def write_document(document, out, validate=True): | |
| raise InvalidDocumentError(messages) | ||
|
|
||
| writer = Writer(document) | ||
| document_object = {"SpdxDocument": writer.create_document()} | ||
| # document_object = {"SpdxDocument": writer.create_document()}. | ||
| # hanged by the WhiteSouse PS Team | ||
| document_object = {"Document": writer.create_document()} | ||
|
Comment on lines
-28
to
+30
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this changed? Looks internal |
||
|
|
||
| xmltodict.unparse(document_object, out, encoding="utf-8", pretty=True) | ||
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 assume these changes are from the fork and shouldn't be committed?