Skip to content

Commit f05464d

Browse files
authored
Merge pull request #22 from heliocastro/feat/evaluation_result
feat(evaluator): Implement evaluator-result parsing
2 parents 68b8d79 + 8f53544 commit f05464d

43 files changed

Lines changed: 3159 additions & 281 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/ort_result.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from pathlib import Path
77

88
import click
9-
import yaml
109
from pydantic import ValidationError
1110
from rich.pretty import pprint
1211

13-
from ort import OrtResult
12+
from ort import OrtResult, ort_yaml_load
1413

1514
logger = logging.getLogger()
1615

@@ -26,7 +25,7 @@ def main(
2625
) -> None:
2726
try:
2827
with Path(datafile).open() as fd:
29-
data = yaml.safe_load(fd)
28+
data = ort_yaml_load(fd)
3029
parsed = OrtResult(**data)
3130
if analyzer:
3231
pprint(parsed.analyzer)

examples/repo_config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from pathlib import Path
77

88
import click
9-
import yaml
109
from pydantic import ValidationError
1110
from rich.pretty import pprint
1211

13-
from ort import RepositoryConfiguration
12+
from ort import RepositoryConfiguration, ort_yaml_load
1413

1514
logger = logging.getLogger()
1615

@@ -20,7 +19,7 @@
2019
def main(datafile: str) -> None:
2120
try:
2221
with Path(datafile).open() as fd:
23-
data = yaml.safe_load(fd)
22+
data = ort_yaml_load(fd)
2423
parsed = RepositoryConfiguration(**data)
2524
pprint(parsed)
2625
except ValidationError as e:

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "uv_build"
44

55
[project]
66
name = "python-ort"
7-
version = "0.6.6"
7+
version = "0.7.0"
88
description = "A Python Ort model serialization library"
99
readme = "README.md"
1010
license = "MIT"
@@ -35,11 +35,11 @@ module-root = "src"
3535

3636
[dependency-groups]
3737
dev = [
38-
"datamodel-code-generator[http]>=0.54.0",
38+
"datamodel-code-generator[http]>=0.55.0",
3939
"pytest>=9.0.2",
4040
"rich>=14.3.3",
41-
"ruff>=0.15.4",
42-
"ty>=0.0.20",
41+
"ruff>=0.15.5",
42+
"ty>=0.0.21",
4343
"types-pyyaml>=6.0.12.20250915",
4444
]
4545

src/ort/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
from .models.analyzer_result import AnalyzerResult
66
from .models.config.repository_configuration import RepositoryConfiguration
77
from .models.ort_result import OrtResult
8+
from .utils.yaml_loader import OrtYamlLoader, ort_yaml_load
89

910
__all__ = [
1011
"AnalyzerResult",
12+
"OrtYamlLoader",
1113
"RepositoryConfiguration",
1214
"OrtResult",
15+
"ort_yaml_load",
1316
]

src/ort/models/advisor_capability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# SPDX-License-Identifier: MIT
33

44

5-
from enum import IntEnum
5+
from ort.utils.validated_enum import ValidatedIntEnum
66

77

8-
class AdvisorCapability(IntEnum):
8+
class AdvisorCapability(ValidatedIntEnum):
99
"""
1010
An enum class that defines the capabilities of a specific advisor implementation.
1111

src/ort/models/advisor_details.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44

5-
from pydantic import BaseModel, ConfigDict, Field, field_validator
5+
from pydantic import BaseModel, ConfigDict, Field
66

77
from ort.models import AdvisorCapability
88

@@ -22,20 +22,3 @@ class AdvisorDetails(BaseModel):
2222
description="The capabilities of the used advisor. This property indicates, which kind of findings"
2323
"are retrieved by the advisor."
2424
)
25-
26-
@field_validator("capabilities", mode="before")
27-
@classmethod
28-
def convert_capability(cls, v):
29-
def _convert(item):
30-
if isinstance(item, str):
31-
try:
32-
return AdvisorCapability[item]
33-
except KeyError:
34-
raise ValueError(f"Invalid capability: {item}")
35-
return item
36-
37-
if isinstance(v, (list, set)):
38-
return {_convert(item) for item in v}
39-
if isinstance(v, str):
40-
return _convert(v)
41-
return v

src/ort/models/advisor_run.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,21 @@
11
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
22
# SPDX-License-Identifier: MIT
33

4-
from datetime import datetime
54

6-
from pydantic import BaseModel, ConfigDict, Field
7-
8-
from ort.models import AdvisorResult
9-
from ort.models.config.advisor_configuration import AdvisorConfiguration
10-
from ort.utils.environment import Environment
5+
from pydantic import Field
116

7+
from .advisor_result import AdvisorResult
8+
from .base_run import BaseRun
9+
from .config.advisor_configuration import AdvisorConfiguration
1210
from .identifier import Identifier
1311

1412

15-
class AdvisorRun(BaseModel):
13+
class AdvisorRun(BaseRun):
1614
"""
1715
Type alias for a function that allows filtering of [AdvisorResult]s.
1816
1917
"""
2018

21-
model_config = ConfigDict(
22-
extra="forbid",
23-
)
24-
start_time: datetime = Field(
25-
description="The time the advisor was started.",
26-
)
27-
end_time: datetime = Field(
28-
description="The time the advisor has finished.",
29-
)
30-
environment: Environment = Field(
31-
description="The [Environment] in which the advisor was executed.",
32-
)
3319
config: AdvisorConfiguration = Field(
3420
description="The [AdvisorConfiguration] used for this run.",
3521
)

src/ort/models/analyzer_run.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
22
# SPDX-License-Identifier: MIT
33

4-
from datetime import datetime
54

6-
from pydantic import BaseModel, ConfigDict, Field
5+
from pydantic import Field
76

8-
from ort.models import AnalyzerResult
9-
from ort.models.config.analyzer_configuration import AnalyzerConfiguration
10-
from ort.utils.environment import Environment
7+
from .analyzer_result import AnalyzerResult
8+
from .base_run import BaseRun
9+
from .config.analyzer_configuration import AnalyzerConfiguration
1110

1211

13-
class AnalyzerRun(BaseModel):
12+
class AnalyzerRun(BaseRun):
1413
"""
1514
The summary of a single run of the analyzer.
1615
1716
"""
1817

19-
model_config = ConfigDict(
20-
extra="forbid",
21-
)
22-
start_time: datetime = Field(
23-
description="The time the analyzer was started.",
24-
)
25-
end_time: datetime = Field(
26-
description="The time the analyzer has finished.",
27-
)
28-
environment: Environment = Field(
29-
description="The [Environment] in which the analyzer was executed.",
30-
)
3118
config: AnalyzerConfiguration = Field(
3219
description="The [AnalyzerConfiguration] used for this run.",
3320
)

src/ort/models/base_run.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
from datetime import datetime
5+
6+
from pydantic import BaseModel, ConfigDict, Field
7+
8+
from ort.utils.environment import Environment
9+
10+
11+
class BaseRun(BaseModel):
12+
"""
13+
The summary of a single run of the analyzer.
14+
15+
"""
16+
17+
model_config = ConfigDict(
18+
extra="forbid",
19+
)
20+
start_time: datetime = Field(
21+
description="The time the analyzer was started.",
22+
)
23+
end_time: datetime = Field(
24+
description="The time the analyzer has finished.",
25+
)
26+
environment: Environment = Field(
27+
description="The [Environment] in which the analyzer was executed.",
28+
)

src/ort/models/config/issue_resolution.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# SPDX-License-Identifier: MIT
33

44

5-
from pydantic import BaseModel, ConfigDict, Field, field_validator
6-
7-
from ort.utils import convert_enum
5+
from pydantic import BaseModel, ConfigDict, Field
86

97
from .issue_resolution_reason import IssueResolutionReason
108

@@ -32,8 +30,3 @@ class IssueResolution(BaseModel):
3230
comment: str = Field(
3331
description="A comment to further explain why the [reason] is applicable here.",
3432
)
35-
36-
@field_validator("reason", mode="before")
37-
@classmethod
38-
def validate_reason(cls, value):
39-
return convert_enum(IssueResolutionReason, value)

0 commit comments

Comments
 (0)