Skip to content

Commit ffa5260

Browse files
authored
Merge pull request #15 from OPPIDA/fix/dataset-loading
2 parents 9167760 + 2968965 commit ffa5260

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

codesectools/datasets/BenchmarkJava/dataset.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,17 @@ def load_dataset(self) -> list[TestCode]:
148148
for row in reader:
149149
filename = f"{row[0]}.java"
150150
filepath = testcode_dir / filename
151-
content = filepath.read_text()
152-
cwes = [CWEs.from_id(int(row[3]))]
153-
has_vuln = True if row[2] == "true" else False
154-
files.append(
155-
TestCode(
156-
filepath.relative_to(self.directory),
157-
content,
158-
cwes,
159-
has_vuln,
151+
if filepath.is_file():
152+
content = filepath.read_text()
153+
cwes = [CWEs.from_id(int(row[3]))]
154+
has_vuln = True if row[2] == "true" else False
155+
files.append(
156+
TestCode(
157+
filepath.relative_to(self.directory),
158+
content,
159+
cwes,
160+
has_vuln,
161+
)
160162
)
161-
)
162163

163164
return files

codesectools/datasets/core/dataset.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ def __init__(self, lang: str | None = None) -> None:
5757
"""
5858
self.directory = USER_CACHE_DIR / self.name
5959
self.lang = lang
60+
self._files = []
6061
if self.lang:
6162
self.full_name = f"{self.name}_{self.lang}"
6263
assert self.full_name in self.list_dataset_full_names()
63-
self.files: list[File] = self.load_dataset()
64-
else:
65-
self.files = []
64+
65+
@property
66+
def files(self) -> list:
67+
"""Get the list of dataset files, loading them if necessary."""
68+
if self.lang:
69+
self._files = self.load_dataset()
70+
return self._files
6671

6772
@classmethod
6873
def is_cached(cls) -> bool:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "CodeSecTools"
3-
version = "0.12.2"
3+
version = "0.12.4"
44
description = "A framework for code security that provides abstractions for static analysis tools and datasets to support their integration, testing, and evaluation."
55
readme = "README.md"
66
license = "AGPL-3.0-only"

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)