Skip to content

Bug fixes - #207

Closed
tamari-oz wants to merge 18 commits into
spdx:mainfrom
whitesource-ps:ws-patches
Closed

tamari-oz wants to merge 18 commits into
spdx:mainfrom
whitesource-ps:ws-patches

Conversation

@tamari-oz

Copy link
Copy Markdown

4 fixes are addressed:

  1. Relationship generation on non-TV output formats (was working only on TV).
  2. Missing encoding when dumping to YAML.
  3. Fixed Validation error not returning in relationship.
  4. NoAssert does not contain default repr

pombredanne and others added 8 commits January 16, 2022 12:07
The qualifiers where not correct

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
Reported-by: Rich Steenwyk <rich.steenwyk@gmail.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
1. yaml creation missing encoding.
2. NoAssert cannot be written to a file (not serializable) as it does not have default repr.
3. Problem creating relationships

Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
1. yaml creation missing encoding.
2. NoAssert cannot be written to a file (not serializable) as it does not have default repr.
3. Problem creating relationships

Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>
Signed-off-by: OzTamari <oz.tamari@whitesourcesoftware.com>

@licquia licquia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we're going to add a dependency on numpy for all users of the library. Also, could you add tests for the specific deficiencies you fixed?

Comment thread spdx/writers/json.py
from spdx.writers.tagvalue import InvalidDocumentError
from spdx.writers.jsonyamlxml import Writer
from spdx.parsers.loggers import ErrorMessages
import numpy as np

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you remove the dependency on numpy? You should be able to test for regular int, float, etc.

rammatzkvosky and others added 5 commits March 27, 2022 14:42
Signed-off-by: rammatzkvosky <ram.matzkovsky@whitesourcesoftware.com>
…ue is not available at WhiteSource

Updating setup.py version to '0.7.0a3.post6'

Signed-off-by: rammatzkvosky <ram.matzkovsky@whitesourcesoftware.com>

@nicoweidner nicoweidner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There are several valuable fixes in this PR, but several other things need more work.

@tamari-oz: Given the age of this PR, it would be greatly appreciated if you could indicate whether you are still active and will have time to finish the PR. Else I would try to take over so we can get the fixes merged.

Comment thread setup.py
Comment on lines +15 to +16
name='ws-spdx-tools',
version='0.7.0a3.post7',

Copy link
Copy Markdown
Collaborator

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?

Comment thread spdx/package.py
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 )

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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!

Comment thread spdx/package.py
Comment on lines +283 to +284
except:
pass

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just swallowing all exceptions is bad. Why was this added?

Comment thread spdx/package.py
Comment on lines +281 to +282
if not self.check_sum.value:
delattr(self, 'check_sum')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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?
Also, if the instance check above fails, we are still adding a validation error message. Is that intended?

Sorry if I am being slow here, I just started working on this project 😅

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 tv format, there is a downstream check for that which fails the report.

For that reason, we add this check.

Comment thread spdx/relationship.py
self.relationship_comment = relationship_comment

def __eq__(self, other):
return True if self.relationship == other.relationship else False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should include an instance check on the other object:

Suggested change
return True if self.relationship == other.relationship else False
return (
isInstance(other, Relationship)
and self.relationship == other.relationship
)

Comment on lines +488 to +491
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Comment on lines +493 to +503
# 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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.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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# create a list of the packages' names for the 'documentDescribes' field
# create a list of the packages' spdx ids for the 'documentDescribes' field

Comment thread spdx/writers/rdf.py
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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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)

Comment thread spdx/writers/rdf.py
Comment on lines +1019 to +1022
# Add relationship
for relate_node in self.relationships():
relate_triple = (doc_node, self.spdx_namespace.relationship, relate_node)
self.graph.add(relate_triple)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tried this out using

$ convertor -f tag data/SPDXTagExample -o output.rdf

and the output contained this, which doesn't seem to make sense (relationships should be separate entities):

    <ns1:relationship>
      <ns1:Relationship rdf:about="SPDXRef-DOCUMENT">
        <ns1:relationshipType>CONTAINS</ns1:relationshipType>
        <ns1:relationshipType>DESCRIBES</ns1:relationshipType>
        <ns1:relationshipType>COPY_OF</ns1:relationshipType>
        <ns1:relatedSpdxElement>SPDXRef-File</ns1:relatedSpdxElement>
        <ns1:relatedSpdxElement>DocumentRef-spdx-tool-1.2:SPDXRef-ToolsElement</ns1:relatedSpdxElement>
        <ns1:relatedSpdxElement>SPDXRef-Package</ns1:relatedSpdxElement>
      </ns1:Relationship>
    </ns1:relationship>

I think this either needs more work, or should be handled as a separate issue - whichever way you prefer!

@armintaenzertng

Copy link
Copy Markdown
Collaborator

@tamari-oz, do you plan to get back to this?

@nicoweidner nicoweidner mentioned this pull request Nov 2, 2022
@nicoweidner

Copy link
Copy Markdown
Collaborator

I will continue this in #263, which I already rebased on main

@nicoweidner nicoweidner closed this Nov 2, 2022
@meretp meretp mentioned this pull request Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants