Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label collection to help with multiple label comparisons #116

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 2 additions & 69 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = [
]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.9"
click = "^8"
dataclasses-json = "^0.5.8"
tabulate = "^0.9.0"
Expand Down
9 changes: 6 additions & 3 deletions src/yardstick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ def compare_results_against_labels( # pylint: disable=too-many-arguments
for result in results:
result.matches = matches_filter(result.matches)

if not label_entries:
label_entries = store.labels.load_all(year_max_limit=year_max_limit, year_from_cve_only=year_from_cve_only)
if label_entries is None:
label_entries = store.labels.load_all(
year_max_limit=year_max_limit,
year_from_cve_only=year_from_cve_only,
)

comparisons_by_result_id, stats_by_image_tool_pair = comparison.of_results_against_label(
*results,
Expand All @@ -91,7 +94,7 @@ def compare_results_against_labels_by_ecosystem(
results = store.result_set.load_scan_results(result_set, year_max_limit=year_max_limit, skip_sbom_results=True)
results_by_image = arrange.scan_results_by_image(results)

if not label_entries:
if label_entries is None:
label_entries = store.labels.load_all(year_max_limit=year_max_limit, year_from_cve_only=year_from_cve_only)

stats = comparison.of_results_against_label_by_ecosystem(
Expand Down
10 changes: 10 additions & 0 deletions src/yardstick/artifact.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections
import functools
import getpass
import hashlib
import json
Expand Down Expand Up @@ -499,6 +500,15 @@ def effective_year(self, by_cve=False) -> Optional[int]:
return year


class LabelEntryCollection:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. Is this meant to be used as the type of label_entries in src/yardstick/__init__.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not in this PR, no. This PR only adds this object to be used by API consumers. In the future this can be rolled underneath the core API.

def __init__(self, entries: List[LabelEntry]):
self.entries = entries

@functools.cache
def for_image(self, image: str) -> List[LabelEntry]:
return [e for e in self.entries if e.matches_image(image)]


@dataclass()
class ScanRequest:
image: str
Expand Down
1 change: 0 additions & 1 deletion src/yardstick/store/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def load_label_file(
# why note take a file path? in this way we control that all input/output data was derived from the same store,
# and not another store.
path = store_path(filename=filename, store_root=store_root)
logging.debug(f"loading labels location={path}")

try:
with open(path, "r", encoding="utf-8") as data_file:
Expand Down