Skip to content

Reduce dependencies for license scanning API - #5298

Open
shivd1410 wants to merge 1 commit into
aboutcode-org:developfrom
shivd1410:fix-5115-license-api-dependencies
Open

Reduce dependencies for license scanning API#5298
shivd1410 wants to merge 1 commit into
aboutcode-org:developfrom
shivd1410:fix-5115-license-api-dependencies

Conversation

@shivd1410

@shivd1410 shivd1410 commented Sep 4, 2026

Copy link
Copy Markdown

Fixes #5115

Summary

This PR reduces the dependencies loaded when using scancode.api.get_licenses().

Changes

  • Removed the packagedcode.utils import from get_licenses().
  • Import combine_expressions directly from license_expression instead.
  • Moved typecode imports into the functions where file-type information is actually needed.
  • Added a regression test to make sure importing get_licenses() does not load typecode, extractcode, or packagedcode.

Procedure

I started by tracing the imports pulled in when importing scancode.api.get_licenses().

  • packagedcode.utils was pulling in a much larger package-scanning dependency tree, even though get_licenses() only needed combine_expressions.
  • The top-level typecode import was also pulling in extractcode and other dependencies through its import chain.
  • I checked where typecode was actually used and moved those imports to those specific functions instead of loading it when the module is imported.
  • I then checked that the license scanning path still works without these dependencies being loaded upfront.

Testing

  • Lightweight import regression test: passed
  • get_licenses() functional check: passed (MIT detected correctly)
  • pytest tests/scancode/test_api.py: 11 passed, 2 failed
  • The 2 failures are in the existing licensedcode/cache.py boolean-expression handling and are unrelated to these changes.
  • git diff --check: passed

CI

  • Several CI jobs are currently failing in areas unrelated to this change, including
    ClueCode, misc/scancode, and cross-platform test suites.
  • The same license_expression boolean-evaluation failure was also reproduced
    locally in the existing API tests and is unrelated to the changes in this PR.
  • The new regression test for the lightweight get_licenses() import passes.

Signed-off-by: Shivam Pandey <sd.scores4455@gmail.com>
@shivd1410
shivd1410 force-pushed the fix-5115-license-api-dependencies branch from 8a56b44 to ea97933 Compare September 4, 2026 05:04
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.

Make scancode.api.get_licenses more widely useful by reducing dependencies

1 participant