Do not attempt to write empty package info to SPDX - #1011
ThorstenHarter wants to merge 2 commits into
Conversation
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]."
There was a problem hiding this comment.
@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
| if as_tagvalue: | ||
| result = result.encode('utf-8') | ||
| output_file.write(result) | ||
| if len(package.files) > 0: |
There was a problem hiding this comment.
You could also write the simpler form: if package.files:
| if len(package.files) > 0: | ||
| from StringIO import StringIO | ||
| spdx_output = StringIO() | ||
| if len(package.files) > 0: |
There was a problem hiding this comment.
You likely do not need to repeat this test here since this is already True based on your test above.
Updated after review by @pombredanne.
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
@pombredanne : The output SPDX file is created, because of this code at line 250ff: For example: |
|
I respun the build on Appveyor that failed for some mysterious reason |
Reported-by: Thorsten Harter <thorsten.harter@gmx.net> Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
|
@ThorstenHarter This is merged with: 71128eb I also created a follow up #1016 as we should not produce a mostly empty document IMHO in these cases. Thank you ++ |
Reported-by: Thorsten Harter <thorsten.harter@gmx.net> Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
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