Skip to content

Commit b4798f0

Browse files
authored
Merge pull request #20 from heliocastro/fix/enumerations
fix(models): Update model enum translations for reasoning
2 parents f7e6d31 + a9364a3 commit b4798f0

10 files changed

Lines changed: 91 additions & 9 deletions

File tree

.github/workflows/publish.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
name: Publish
66

77
on:
8-
push:
9-
tags:
10-
- 'v*'
11-
paths-ignore:
12-
- '**.md'
8+
workflow_run:
9+
workflows:
10+
- Build
11+
- Validation
12+
types:
13+
- completed
1314

1415
jobs:
1516
publish:
1617
name: Publish Python Ort on PyPI
1718
runs-on: ubuntu-24.04
19+
if: github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'v')
1820
environment:
1921
name: PyPI
2022
permissions:

examples/model_relation_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import inspect
2+
3+
from pydantic import BaseModel
4+
5+
import ort.models # or your top-level models package
6+
7+
8+
def iter_models(module):
9+
for _, obj in inspect.getmembers(module):
10+
if inspect.isclass(obj) and issubclass(obj, BaseModel):
11+
yield obj
12+
13+
14+
for model in iter_models(ort.models):
15+
try:
16+
print("Rebuilding:", model)
17+
model.model_rebuild()
18+
except Exception:
19+
print("FAILED:", model)
20+
raise

pyproject.toml

Lines changed: 1 addition & 1 deletion
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.4"
7+
version = "0.6.5"
88
description = "A Python Ort model serialization library"
99
readme = "README.md"
1010
license = "MIT"

src/ort/models/config/issue_resolution.py

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

44

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

79
from .issue_resolution_reason import IssueResolutionReason
810

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

src/ort/models/config/vulnerability_resolution.py

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

44

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

79
from .vulnerability_resolution_reason import VulnerabilityResolutionReason
810

@@ -29,3 +31,8 @@ class VulnerabilityResolution(BaseModel):
2931
comment: str = Field(
3032
description="A comment to further explain why the [reason] is applicable here.",
3133
)
34+
35+
@field_validator("reason", mode="before")
36+
@classmethod
37+
def validate_reason(cls, value):
38+
return convert_enum(VulnerabilityResolutionReason, value)

src/ort/models/scope.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ class Scope(BaseModel):
2828
"testing the product. But transitive dependencies would not be test dependencies of the test "
2929
"dependencies, but compile dependencies of test dependencies.",
3030
)
31+
32+
def __hash__(self) -> int:
33+
return hash(self.name)
34+
35+
def __eq__(self, other) -> bool:
36+
if not isinstance(other, Scope):
37+
return NotImplemented
38+
return self.name == other.name

tests/data/analyzer-result.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,7 @@ analyzer:
15341534
url: "https://github.com/pypa/virtualenv.git"
15351535
revision: ""
15361536
path: ""
1537+
scopes: []
15371538
dependency_graphs:
15381539
PIP:
15391540
packages:

tests/data/repo_config/str_boolean.ort.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@ excludes:
2222
- pattern: '**/doc/**'
2323
reason: OTHER
2424
comment: Documentation not in scan scope
25+
resolutions:
26+
issues:
27+
- message: "IOException: Could not resolve provenance for package 'Maven:com.google.*"
28+
reason: CANT_FIX_ISSUE
29+
comment: "Google is not publishing sources for all their android libraries, especially the ones from the play-services or MLKit"
30+
- message: "IOException: Could not resolve provenance for package 'Maven:com.phrase.*"
31+
reason: CANT_FIX_ISSUE
32+
comment: "Phrase is licensed by a proprietary license and the sources of their libraries aren't published."
33+
- message: "IOException: Could not resolve provenance for package 'Maven:org.jetbrains.kotlin:kotlin-stdlib-common:.*"
34+
reason: CANT_FIX_ISSUE
35+
comment: "The 'org.jetbrains.kotlin:kotlin-stdlib-common' library is a metadata library for which no sources are published by JetBrains"

tests/test_repo_config_files.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
from pathlib import Path
5+
6+
import pytest
7+
import yaml
8+
from pydantic import ValidationError
9+
10+
from ort.models.config.repository_configuration import RepositoryConfiguration
11+
12+
REPO_CONFIG_DIR = Path(__file__).parent / "data" / "repo_config"
13+
14+
# Collect all YAML files that are expected to be valid RepositoryConfiguration documents
15+
_VALID_FILES = [f for f in REPO_CONFIG_DIR.glob("*.yml") if f.name != "only_include_reason_fail.yml"]
16+
17+
18+
@pytest.mark.parametrize("config_file", _VALID_FILES, ids=lambda f: f.name)
19+
def test_repo_config_file_loads_without_validation_error(config_file: Path) -> None:
20+
"""Each file in tests/data/repo_config (except known-invalid ones) must load
21+
into RepositoryConfiguration without raising a pydantic ValidationError."""
22+
data = yaml.safe_load(config_file.read_text())
23+
try:
24+
RepositoryConfiguration.model_validate(data or {})
25+
except ValidationError as exc:
26+
pytest.fail(f"{config_file.name} raised ValidationError: {exc}")

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)