Skip to content

Commit

Permalink
feat: no entrypoint registration required in tree
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
John Andersen committed Jun 21, 2024
1 parent c5da274 commit 74cf191
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
20 changes: 0 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
},
)

Expand Down
22 changes: 16 additions & 6 deletions test/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import re
import sys
import importlib

import pytest

Expand All @@ -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))

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 74cf191

Please sign in to comment.