Skip to content

Commit daf67e3

Browse files
committed
Work around spdx-tools assuming a "str" file instead of "unicode"
Fixes #436.
1 parent f827cdc commit daf67e3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/scancode/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,20 @@ def save_results(files_count, scanned_files, format, input, output_file):
712712
doc.package.license_declared = NoAssert()
713713
doc.package.conc_lics = NoAssert()
714714

715+
# As the spdx-tools package can only write the document to a "str" file but ScanCode provides a "unicode" file,
716+
# write to a "str" buffer first and then manually write the value to a "unicode" file.
717+
from StringIO import StringIO
718+
719+
str_buffer = StringIO()
720+
715721
if format == 'spdx-tv':
716722
from spdx.writers.tagvalue import write_document
717-
write_document(doc, output_file)
723+
write_document(doc, str_buffer)
718724
else:
719725
from spdx.writers.rdf import write_document
720-
write_document(doc, output_file)
726+
write_document(doc, str_buffer)
727+
728+
output_file.write(str_buffer.getvalue())
721729

722730
else:
723731
raise Exception('Unknown format')

0 commit comments

Comments
 (0)