Skip to content

Do not attempt to write empty package info to SPDX - #1011

Closed
ThorstenHarter wants to merge 2 commits into
aboutcode-org:developfrom
ThorstenHarter:develop
Closed

ThorstenHarter wants to merge 2 commits into
aboutcode-org:developfrom
ThorstenHarter:develop

Conversation

@ThorstenHarter

@ThorstenHarter ThorstenHarter commented Mar 28, 2018

Copy link
Copy Markdown
Contributor

When you scan a component without any copyright or license info, ScanCode will report an error:
spdx.writers.tagvalue.InvalidDocumentError: [u'Package must have at least one file.']

Adding a check before writing spdx_output will fix this problem, the output file will only contain the string ""# No results for package [name]."

Signed-off-by: Thorsten Harter thorsten.harter@gmx.net

When you scan a component without any copyright or license info, ScanCode will report an error:
spdx.writers.tagvalue.InvalidDocumentError: [u'Package must have at least one file.']

Adding a check before writing spdx_output will fix this problem, the output file will only contain the string ""# No results for package [name]."

@pombredanne pombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ThorstenHarter Thank you for this PR! This makes sense to me though it may be a tad surprising to have nothing written at all in this case?

In fact we have discussed with SPDX on ways to relax the spec to allow writing documents that would have no files alright.

Do you think you could add a small test for this?
Here is an example using these scanned files (under /scan) and expected files: https://github.com/nexB/scancode-toolkit/tree/fd2e483e346a38ee9634538a0f05ca4dd96fb622/tests/formattedcode/data/spdx/tree

In your case you would expect no file at all so I guess the test would check that the written file does not exist?

Do you mind also adding a line at the end of your commit message with:
Signed-off-by: Your Name <your email>

We use the same sign-off way that's used in the kernel. See also https://github.com/nexB/scancode-toolkit/blob/develop/CONTRIBUTING.rst for extra details
Alternatively you can add this signoff in a PR message

@yash-nisar ping FYI since that's an area of interest.
@sschuberth ping too for review

Comment thread src/formattedcode/output_spdx.py Outdated
if as_tagvalue:
result = result.encode('utf-8')
output_file.write(result)
if len(package.files) > 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could also write the simpler form: if package.files:

Comment thread src/formattedcode/output_spdx.py Outdated
if len(package.files) > 0:
from StringIO import StringIO
spdx_output = StringIO()
if len(package.files) > 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You likely do not need to repeat this test here since this is already True based on your test above.

@codecov

codecov Bot commented Mar 28, 2018

Copy link
Copy Markdown

Codecov Report

Merging #1011 into develop will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1011      +/-   ##
===========================================
+ Coverage    79.12%   79.17%   +0.05%     
===========================================
  Files          104      104              
  Lines        12971    12972       +1     
===========================================
+ Hits         10263    10271       +8     
+ Misses        2708     2701       -7
Impacted Files Coverage Δ
src/formattedcode/output_spdx.py 86.57% <100%> (+0.09%) ⬆️
src/scancode/cli.py 75.23% <0%> (+0.37%) ⬆️
src/scancode/api.py 94.4% <0%> (+0.8%) ⬆️
src/scancode_config.py 67.85% <0%> (+7.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd2e483...227b8f9. Read the comment docs.

@ThorstenHarter

Copy link
Copy Markdown
Contributor Author

@pombredanne : The output SPDX file is created, because of this code at line 250ff:

    if len(package.files) == 0:
        if as_tagvalue:
            output_file.write("# No results for package '{}'.\n".format(package.name))
        else:
            output_file.write("<!-- No results for package '{}'. -->\n".format(package.name))

For example: # No results for package 'test'.

@pombredanne

Copy link
Copy Markdown
Member

I respun the build on Appveyor that failed for some mysterious reason

pombredanne added a commit that referenced this pull request Apr 3, 2018
Reported-by: Thorsten Harter <thorsten.harter@gmx.net>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne

pombredanne commented Apr 3, 2018

Copy link
Copy Markdown
Member

@ThorstenHarter This is merged with: 71128eb
I ameneded your commits to add the signoff that you added to this PR message : Signed-off-by: Thorsten Harter <thorsten.harter@gmx.net> and pushed some tests too.

I also created a follow up #1016 as we should not produce a mostly empty document IMHO in these cases.

Thank you ++

@pombredanne pombredanne closed this Apr 3, 2018
steven-esser pushed a commit that referenced this pull request Apr 3, 2018
Reported-by: Thorsten Harter <thorsten.harter@gmx.net>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants