diff --git a/setup.py b/setup.py index 5f0ba969c6..93c3437410 100644 --- a/setup.py +++ b/setup.py @@ -69,26 +69,6 @@ "cve-bin-tool = cve_bin_tool.cli:main", "csv2cve = cve_bin_tool.csv2cve:main", ], - "cve_bin_tool.checker": [ - "{} = cve_bin_tool.checkers.{}:{}".format( - filename.replace(".py", ""), - filename.replace(".py", ""), - "".join( - (filename.replace(".py", "") + " checker") - .replace("_", " ") - .title() - .split() - ), - ) - for filename in os.listdir( - os.path.join( - os.path.abspath(os.path.dirname(__file__)), - "cve_bin_tool", - "checkers", - ) - ) - if filename.endswith(".py") and "__init__" not in filename - ], }, ) diff --git a/test/test_checkers.py b/test/test_checkers.py index 10ffb136ce..9328daa520 100644 --- a/test/test_checkers.py +++ b/test/test_checkers.py @@ -5,6 +5,7 @@ import re import sys +import importlib import pytest @@ -16,6 +17,19 @@ from importlib import metadata as importlib_metadata else: import importlib_metadata +if sys.version_info >= (3, 9): + import importlib.resources as resources +else: + import importlib_resources as resources + + +CHECKER_CLASSES = { + checker_path.stem: importlib.import_module( + f"cve_bin_tool.checkers.{checker_path.stem}" + ).Checker + for checker_path in resources.files("cve_bin_tool.checkers").iterdir() + if (checker_path.suffix == ".py" and not checker_path.name.startswith("__")) +} Pattern = type(re.compile("", 0)) @@ -136,12 +150,8 @@ def setup_class(cls): ) def test_filename_is(self, checker_name, file_name, expected_results): """Test a checker's filename detection""" - checkers = importlib_metadata.entry_points().select( - group="cve_bin_tool.checker" - ) - for checker in checkers: - if checker.name == checker_name: - Checker = checker.load() + for i_checker_name, Checker in CHECKER_CLASSES.items(): + if i_checker_name == checker_name: checker = Checker() result = checker.get_version("", file_name)