Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 2 additions & 3 deletions examples/ort_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from pathlib import Path

import click
import yaml
from pydantic import ValidationError
from rich.pretty import pprint

from ort import OrtResult
from ort import OrtResult, ort_yaml_load

logger = logging.getLogger()

Expand All @@ -26,7 +25,7 @@ def main(
) -> None:
try:
with Path(datafile).open() as fd:
data = yaml.safe_load(fd)
data = ort_yaml_load(fd)
parsed = OrtResult(**data)
if analyzer:
pprint(parsed.analyzer)
Expand Down
5 changes: 2 additions & 3 deletions examples/repo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from pathlib import Path

import click
import yaml
from pydantic import ValidationError
from rich.pretty import pprint

from ort import RepositoryConfiguration
from ort import RepositoryConfiguration, ort_yaml_load

logger = logging.getLogger()

Expand All @@ -20,7 +19,7 @@
def main(datafile: str) -> None:
try:
with Path(datafile).open() as fd:
data = yaml.safe_load(fd)
data = ort_yaml_load(fd)
parsed = RepositoryConfiguration(**data)
pprint(parsed)
except ValidationError as e:
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "uv_build"

[project]
name = "python-ort"
version = "0.6.6"
version = "0.7.0"
description = "A Python Ort model serialization library"
readme = "README.md"
license = "MIT"
Expand Down Expand Up @@ -35,11 +35,11 @@ module-root = "src"

[dependency-groups]
dev = [
"datamodel-code-generator[http]>=0.54.0",
"datamodel-code-generator[http]>=0.55.0",
"pytest>=9.0.2",
"rich>=14.3.3",
"ruff>=0.15.4",
"ty>=0.0.20",
"ruff>=0.15.5",
"ty>=0.0.21",
"types-pyyaml>=6.0.12.20250915",
]

Expand Down
3 changes: 3 additions & 0 deletions src/ort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
from .models.analyzer_result import AnalyzerResult
from .models.config.repository_configuration import RepositoryConfiguration
from .models.ort_result import OrtResult
from .utils.yaml_loader import OrtYamlLoader, ort_yaml_load

__all__ = [
"AnalyzerResult",
"OrtYamlLoader",
"RepositoryConfiguration",
"OrtResult",
"ort_yaml_load",
]
4 changes: 2 additions & 2 deletions src/ort/models/advisor_capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# SPDX-License-Identifier: MIT


from enum import IntEnum
from ort.utils.validated_enum import ValidatedIntEnum


class AdvisorCapability(IntEnum):
class AdvisorCapability(ValidatedIntEnum):
"""
An enum class that defines the capabilities of a specific advisor implementation.

Expand Down
19 changes: 1 addition & 18 deletions src/ort/models/advisor_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: MIT


from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field

from ort.models import AdvisorCapability

Expand All @@ -22,20 +22,3 @@ class AdvisorDetails(BaseModel):
description="The capabilities of the used advisor. This property indicates, which kind of findings"
"are retrieved by the advisor."
)

@field_validator("capabilities", mode="before")
@classmethod
def convert_capability(cls, v):
def _convert(item):
if isinstance(item, str):
try:
return AdvisorCapability[item]
except KeyError:
raise ValueError(f"Invalid capability: {item}")
return item

if isinstance(v, (list, set)):
return {_convert(item) for item in v}
if isinstance(v, str):
return _convert(v)
return v
24 changes: 5 additions & 19 deletions src/ort/models/advisor_run.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

from ort.models import AdvisorResult
from ort.models.config.advisor_configuration import AdvisorConfiguration
from ort.utils.environment import Environment
from pydantic import Field

from .advisor_result import AdvisorResult
from .base_run import BaseRun
from .config.advisor_configuration import AdvisorConfiguration
from .identifier import Identifier


class AdvisorRun(BaseModel):
class AdvisorRun(BaseRun):
"""
Type alias for a function that allows filtering of [AdvisorResult]s.

"""

model_config = ConfigDict(
extra="forbid",
)
start_time: datetime = Field(
description="The time the advisor was started.",
)
end_time: datetime = Field(
description="The time the advisor has finished.",
)
environment: Environment = Field(
description="The [Environment] in which the advisor was executed.",
)
config: AdvisorConfiguration = Field(
description="The [AdvisorConfiguration] used for this run.",
)
Expand Down
23 changes: 5 additions & 18 deletions src/ort/models/analyzer_run.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field
from pydantic import Field

from ort.models import AnalyzerResult
from ort.models.config.analyzer_configuration import AnalyzerConfiguration
from ort.utils.environment import Environment
from .analyzer_result import AnalyzerResult
from .base_run import BaseRun
from .config.analyzer_configuration import AnalyzerConfiguration


class AnalyzerRun(BaseModel):
class AnalyzerRun(BaseRun):
"""
The summary of a single run of the analyzer.

"""

model_config = ConfigDict(
extra="forbid",
)
start_time: datetime = Field(
description="The time the analyzer was started.",
)
end_time: datetime = Field(
description="The time the analyzer has finished.",
)
environment: Environment = Field(
description="The [Environment] in which the analyzer was executed.",
)
config: AnalyzerConfiguration = Field(
description="The [AnalyzerConfiguration] used for this run.",
)
Expand Down
28 changes: 28 additions & 0 deletions src/ort/models/base_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

from ort.utils.environment import Environment


class BaseRun(BaseModel):
"""
The summary of a single run of the analyzer.
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

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

The BaseRun docstring says "The summary of a single run of the analyzer" but this is a generic base class used by AnalyzerRun, AdvisorRun, and EvaluatorRun. The docstring should reflect that it's a base class, e.g. "Base class for ORT tool run summaries."

Suggested change
The summary of a single run of the analyzer.
Base class for ORT tool run summaries.

Copilot uses AI. Check for mistakes.

"""

model_config = ConfigDict(
extra="forbid",
)
start_time: datetime = Field(
description="The time the analyzer was started.",
)
end_time: datetime = Field(
description="The time the analyzer has finished.",
)
environment: Environment = Field(
description="The [Environment] in which the analyzer was executed.",
)
9 changes: 1 addition & 8 deletions src/ort/models/config/issue_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: MIT


from pydantic import BaseModel, ConfigDict, Field, field_validator

from ort.utils import convert_enum
from pydantic import BaseModel, ConfigDict, Field

from .issue_resolution_reason import IssueResolutionReason

Expand Down Expand Up @@ -32,8 +30,3 @@ class IssueResolution(BaseModel):
comment: str = Field(
description="A comment to further explain why the [reason] is applicable here.",
)

@field_validator("reason", mode="before")
@classmethod
def validate_reason(cls, value):
return convert_enum(IssueResolutionReason, value)
4 changes: 2 additions & 2 deletions src/ort/models/config/issue_resolution_reason.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from enum import IntEnum
from ort.utils.validated_enum import ValidatedIntEnum


class IssueResolutionReason(IntEnum):
class IssueResolutionReason(ValidatedIntEnum):
"""
Possible reasons for resolving an Issue using an IssueResolution.

Expand Down
9 changes: 1 addition & 8 deletions src/ort/models/config/path_exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: MIT


from pydantic import BaseModel, ConfigDict, Field, field_validator

from ort.utils import convert_enum
from pydantic import BaseModel, ConfigDict, Field

from .path_exclude_reason import PathExcludeReason

Expand Down Expand Up @@ -32,8 +30,3 @@ class PathExclude(BaseModel):
default_factory=str,
description="A comment to further explain why the [reason] is applicable here.",
)

@field_validator("reason", mode="before")
@classmethod
def validate_reason(cls, value):
return convert_enum(PathExcludeReason, value)
4 changes: 2 additions & 2 deletions src/ort/models/config/path_exclude_reason.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from enum import IntEnum
from ort.utils.validated_enum import ValidatedIntEnum


class PathExcludeReason(IntEnum):
class PathExcludeReason(ValidatedIntEnum):
"""
Possible reasons for excluding a path.

Expand Down
9 changes: 1 addition & 8 deletions src/ort/models/config/path_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: MIT


from pydantic import BaseModel, ConfigDict, Field, field_validator

from ort.utils import convert_enum
from pydantic import BaseModel, ConfigDict, Field

from .path_include_reason import PathIncludeReason

Expand Down Expand Up @@ -32,8 +30,3 @@ class PathInclude(BaseModel):
default_factory=str,
description="A comment to further explain why the [reason] is applicable here.",
)

@field_validator("reason", mode="before")
@classmethod
def validate_reason(cls, value):
return convert_enum(PathIncludeReason, value)
4 changes: 2 additions & 2 deletions src/ort/models/config/path_include_reason.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from enum import IntEnum
from ort.utils.validated_enum import ValidatedIntEnum


class PathIncludeReason(IntEnum):
class PathIncludeReason(ValidatedIntEnum):
"""
Possible reasons for including a path.

Expand Down
2 changes: 1 addition & 1 deletion src/ort/models/config/repository_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .package_configuration import PackageConfiguration
from .repository_analyzer_configuration import RepositoryAnalyzerConfiguration
from .resolutions import Resolutions
from .snippet_choices import SnippetChoices
from .snippet.snippet_choices import SnippetChoices


class RepositoryConfiguration(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions src/ort/models/config/rule_violation_reason.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from enum import IntEnum
from ort.utils.validated_enum import ValidatedIntEnum


class RuleViolationResolutionReason(IntEnum):
class RuleViolationResolutionReason(ValidatedIntEnum):
"""
Properties:
CANT_FIX_EXCEPTION:
Expand Down
9 changes: 1 addition & 8 deletions src/ort/models/config/rule_violation_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: MIT


from pydantic import BaseModel, ConfigDict, Field, field_validator

from ort.utils import convert_enum
from pydantic import BaseModel, ConfigDict, Field

from .rule_violation_reason import RuleViolationResolutionReason

Expand Down Expand Up @@ -32,8 +30,3 @@ class RuleViolationResolution(BaseModel):
comment: str = Field(
description="A comment to further explain why the [reason] is applicable here.",
)

@field_validator("reason", mode="before")
@classmethod
def validate_reason(cls, value):
return convert_enum(RuleViolationResolutionReason, value)
8 changes: 1 addition & 7 deletions src/ort/models/config/scope_exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# SPDX-License-Identifier: MIT


from pydantic import BaseModel, ConfigDict, Field, field_validator
from pydantic import BaseModel, ConfigDict, Field

from ort.models.config.scope_exclude_reason import ScopeExcludeReason
from ort.utils import convert_enum


class ScopeExclude(BaseModel):
Expand All @@ -29,8 +28,3 @@ class ScopeExclude(BaseModel):
default_factory=str,
description="A comment to further explain why the [reason] is applicable here.",
)

@field_validator("reason", mode="before")
@classmethod
def validate_reason(cls, value):
return convert_enum(ScopeExcludeReason, value)
Loading
Loading