Skip to content

Add support for SPDX JSON, XML, and YAML output formats - #5590

Open
chinyeungli wants to merge 3 commits into
developfrom
3698_support_various_spdx_output
Open

chinyeungli wants to merge 3 commits into
developfrom
3698_support_various_spdx_output

Conversation

@chinyeungli

@chinyeungli chinyeungli commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor
  • Use spdx-tools to support additional SPDX output formats.
  • Update tests, test fixtures, and CLI documentation.
  • Remove the "No results for package" message to ensure empty scans produce valid SPDX documents across all output formats.
  • Update CHANGELOG

Fixes #3698

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁
  • Updated documentation pages (if applicable)
  • Updated CHANGELOG.rst (if applicable)

Signed-off-by: Chin Yeung Li tli@nexb.com

* Use `spdx-tools` to support additional SPDX output formats.
* Update tests, test fixtures, and CLI documentation.
* Remove the "No results for package" message to ensure empty scans produce valid SPDX documents across all output formats.
* Update CHANGELOG

Signed-off-by: Chin Yeung Li <tli@nexb.com>
* Add `_safe_test_path()` to validate test fixture and temporary file paths.

Signed-off-by: Chin Yeung Li <tli@nexb.com>
content = strip_variable_text(content)
data = xmltodict.parse(content, dict_constructor=dict)
return sort_nested(data)

@@ -158,26 +180,99 @@ def load_and_clean_tv(location):
# only keep the left side of

return _clean_spdx_mapping(data)



return _clean_spdx_mapping(data)



data = xmltodict.parse(content, dict_constructor=dict)

return _clean_spdx_mapping(data, doc_root='Document')
Signed-off-by: Chin Yeung Li <tli@nexb.com>
safe_result_file = _safe_test_path(result_file, roots=('temp',))
safe_expected_file = _safe_test_path(expected_file, roots=('data',))

shutil.copyfile(safe_result_file, safe_expected_file)
safe_result_file = _safe_test_path(result_file, roots=('temp',))
safe_expected_file = _safe_test_path(expected_file, roots=('data',))

shutil.copyfile(safe_result_file, safe_expected_file)
result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx')
run_scan_click(['--from-json', test_file, '--spdx-rdf', result_file])
with io.open(result_file, encoding='utf-8') as res:
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx')
run_scan_click(['--from-json', test_file, '--spdx-tv', result_file])
with io.open(result_file, encoding='utf-8') as res:
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
result_file = test_env.get_temp_file(extension='json', file_name='test_spdx')
run_scan_click(['--from-json', test_file, '--spdx-json', result_file])

with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
result_file = test_env.get_temp_file(extension='spdx', file_name='test_spdx')
run_scan_click([test_dir, '-clip', '--spdx-tv', result_file])
with io.open(result_file, encoding='utf-8') as res:
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
test_dir = test_env.get_test_loc('spdx/empty/scan/somefile')
result_file = test_env.get_temp_file('rdf')
run_scan_click([test_dir, '-clip', '--spdx-rdf', result_file])
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
test_dir = test_env.get_test_loc('spdx/empty/scan/somefile')
result_file = test_env.get_temp_file('json')
run_scan_click([test_dir, '-clip', '--spdx-json', result_file])
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
test_dir = test_env.get_test_loc('spdx/empty/scan/somefile')
result_file = test_env.get_temp_file('yaml')
run_scan_click([test_dir, '-clip', '--spdx-yaml', result_file])
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:
test_dir = test_env.get_test_loc('spdx/empty/scan/somefile')
result_file = test_env.get_temp_file('xml')
run_scan_click([test_dir, '-clip', '--spdx-xml', result_file])
with io.open(_safe_test_path(result_file, roots=('temp',)), encoding='utf-8') as res:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support SPDX JSON output format

2 participants