Skip to content

Commit

Permalink
Get additional datafile handlers from entry points #3884
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Aug 8, 2024
1 parent 99a4438 commit eeb9e04
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/packagedcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# See https://aboutcode.org for more information about nexB OSS projects.
#

import attr

from commoncode.system import on_linux
from packagedcode import about
from packagedcode import alpine
Expand Down Expand Up @@ -47,6 +45,22 @@
from packagedcode import msi
from packagedcode import win_reg


def get_additional_datafile_handlers():
"""
Return a list of Python module paths to datafile handlers provided by a
plugin.
"""
from importlib import import_module
from importlib_metadata import entry_points
additional_datafile_handlers = entry_points(group='scancode_additional_datafile_handlers')
datafile_handlers = []
for handler in additional_datafile_handlers:
datafile_handler = import_module(handler)
datafile_handlers.append(datafile_handler)
return datafile_handlers


# Note: the order matters: from the most to the least specific parser.
# a handler classes MUST be added to this list to be active
APPLICATION_PACKAGE_DATAFILE_HANDLERS = [
Expand Down Expand Up @@ -251,7 +265,7 @@
APPLICATION_PACKAGE_DATAFILE_HANDLERS + [
p for p in SYSTEM_PACKAGE_DATAFILE_HANDLERS
if p not in APPLICATION_PACKAGE_DATAFILE_HANDLERS
]
] + get_additional_datafile_handlers()
)

HANDLER_BY_DATASOURCE_ID = {handler.datasource_id: handler for handler in ALL_DATAFILE_HANDLERS}
Expand Down

0 comments on commit eeb9e04

Please sign in to comment.