diff --git a/setup.py b/setup.py index 46be23a9a..402e9bf32 100755 --- a/setup.py +++ b/setup.py @@ -12,8 +12,8 @@ def test_suite(): long_description = fh.read() setup( - name='ws-spdx-tools', - version='0.7.0a3.post7', + name='spdx-tools', + version='0.7.0a3', description='SPDX parser and tools.', long_description=long_description, long_description_content_type='text/markdown', diff --git a/spdx/package.py b/spdx/package.py index 9f51e7f7d..e2533d5f1 100644 --- a/spdx/package.py +++ b/spdx/package.py @@ -271,17 +271,11 @@ def validate_str_fields(self, fields, optional, messages): return messages def validate_checksum(self, messages): - 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 ) - if not self.check_sum.value: - delattr(self, 'check_sum') - except: - pass + 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" + ) return messages diff --git a/spdx/relationship.py b/spdx/relationship.py index 20fae0408..fce84498f 100644 --- a/spdx/relationship.py +++ b/spdx/relationship.py @@ -83,7 +83,10 @@ def __init__(self, relationship=None, relationship_comment=None): self.relationship_comment = relationship_comment def __eq__(self, other): - return True if self.relationship == other.relationship else False + return ( + isinstance(other, Relationship) + and self.relationship == other.relationship + ) @property def has_comment(self): diff --git a/spdx/writers/json.py b/spdx/writers/json.py index c9e257d04..a2b226fdf 100644 --- a/spdx/writers/json.py +++ b/spdx/writers/json.py @@ -14,20 +14,14 @@ from spdx.writers.tagvalue import InvalidDocumentError from spdx.writers.jsonyamlxml import Writer from spdx.parsers.loggers import ErrorMessages -import numpy as np 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): - return obj.__str__() + if isinstance(obj, datetime.datetime): + return str(obj) + else: + raise TypeError("No implementation available to serialize objects of type " + type(obj).__name__) def write_document(document, out, validate=True): diff --git a/spdx/writers/jsonyamlxml.py b/spdx/writers/jsonyamlxml.py index 8c3f88a59..d9c399c30 100644 --- a/spdx/writers/jsonyamlxml.py +++ b/spdx/writers/jsonyamlxml.py @@ -47,8 +47,6 @@ def checksum(self, checksum_field): """ checksum_object = dict() checksum_object["algorithm"] = ( - #"checksumAlgorithm_" + checksum_field.identifier.lower() - # Changed by the WhiteSouse PS Team. checksum_field.identifier ) checksum_object["checksumValue"] = checksum_field.value @@ -151,8 +149,6 @@ 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 - # commented by the WS PS Team, sha1 is already exist in check_sum if package.has_optional_field("description"): package_object["description"] = package.description @@ -378,10 +374,6 @@ def __init__(self, document): def create_extracted_license(self): extracted_license_objects = [] - # 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(): @@ -485,23 +477,11 @@ 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 - # 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. package_objects = [] document_describes_objects = [] for package in unique_doc_packages.values(): @@ -509,14 +489,13 @@ def create_document(self): # SPDX 2.2 says to omit if filesAnalyzed = False if package.files: package_info_object["files"] = self.create_file_info(package) - # create a list of the packages' names for the 'documentDescribes' field - package_spdxid = package_info_object.get("SPDXID") - document_describes_objects.append(package_spdxid) + # create a list of the packages' ids for the 'documentDescribes' field + package_spdx_id = package_info_object.get("SPDXID") + document_describes_objects.append(package_spdx_id) package_objects.append(package_info_object) 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 @@ -543,6 +522,4 @@ def create_document(self): if self.document.relationships: self.document_object["relationships"] = self.create_relationship_info() - # return {"Document": self.document_object}. No need in "Document" key for json and tv format. - # Changed by the WhiteSouse PS Team. return self.document_object diff --git a/spdx/writers/rdf.py b/spdx/writers/rdf.py index a7cfcff48..fc6173a25 100644 --- a/spdx/writers/rdf.py +++ b/spdx/writers/rdf.py @@ -569,7 +569,7 @@ def relationships(self): """ Return a list of relationship nodes """ - return list(map(self.create_relationship_node, self.document.relationships)) + return map(self.create_relationship_node, self.document.relationships) class CreationInfoWriter(BaseWriter): diff --git a/spdx/writers/xml.py b/spdx/writers/xml.py index c2b18d999..14bbd4b99 100644 --- a/spdx/writers/xml.py +++ b/spdx/writers/xml.py @@ -25,8 +25,6 @@ def write_document(document, out, validate=True): raise InvalidDocumentError(messages) writer = Writer(document) - # document_object = {"SpdxDocument": writer.create_document()}. - # hanged by the WhiteSouse PS Team document_object = {"Document": writer.create_document()} xmltodict.unparse(document_object, out, encoding="utf-8", pretty=True)