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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ wheels/
.python-version

# Old python requirements
requirements.txt
requirements.txtq

# Ort directories
output
36 changes: 0 additions & 36 deletions .pre-commit-config.yaml

This file was deleted.

77 changes: 77 additions & 0 deletions prek.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Configuration file for `prek`, a git hook framework written in Rust.
# See https://prek.j178.dev for more information.
#:schema https://www.schemastore.org/prek.json

default_language_version.python = "3.13"
default_install_hook_types = ["pre-commit", "commit-msg"]

[[repos]]
repo = "https://github.com/pre-commit/pre-commit-hooks"
rev = "v6.0.0"
hooks = [
{ id = "trailing-whitespace" },
{ id = "end-of-file-fixer" },
{ id = "check-yaml" },
{ id = "check-added-large-files" },
{ id = "check-symlinks" },
{
id = "mixed-line-ending",
args = ["--fix=lf"]
}
]

[[repos]]
repo = "https://github.com/astral-sh/ruff-pre-commit"
rev = "v0.15.4"
hooks = [
{
id = "ruff",
args = ["--fix"]
},
{ id = "ruff-format" }
]

[[repos]]
repo = "https://github.com/compilerla/conventional-pre-commit"
rev = "v4.4.0"
hooks = [
{
id = "conventional-pre-commit",
stages = ["commit-msg"]
}
]

[[repos]]
repo = "https://github.com/astral-sh/uv-pre-commit"
rev = "0.10.8"
hooks = [
{ id = "uv-lock" }
]

[[repos]]
repo = "https://github.com/codespell-project/codespell"
rev = "v2.4.1"
hooks = [
{ id = "codespell" }
]

[[repos]]
repo = "https://github.com/allganize/ty-pre-commit"
rev = "v0.0.20"
hooks = [
{
id = "ty-check",
args = [
"--verbose",
"--output-format=full"
],
additional_dependencies = [
"pydantic",
"pyyaml",
"pytest",
"packageurl-python",
"click",
"rich",
]
}
]
8 changes: 1 addition & 7 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.5"
version = "0.6.6"
description = "A Python Ort model serialization library"
readme = "README.md"
license = "MIT"
Expand Down Expand Up @@ -159,9 +159,3 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false

[tool.pyrefly]
project_includes = [
"src/ort/**",
"tests/**",
]
Empty file.
4 changes: 2 additions & 2 deletions 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.snippet_choice import SnippetChoice
from .snippet_choices import SnippetChoices


class RepositoryConfiguration(BaseModel):
Expand Down Expand Up @@ -60,7 +60,7 @@ class RepositoryConfiguration(BaseModel):
None,
description="A configuration to select a license from a multi-licensed package.",
)
snippet_choices: list[SnippetChoice] = Field(
snippet_choices: list[SnippetChoices] = Field(
default_factory=list,
description="A configuration to select a snippet from a package with multiple snippet findings.",
)
Empty file.
18 changes: 17 additions & 1 deletion src/ort/models/config/snippet/snippet_choice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

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

from ort.utils import convert_enum

from ....types.purl_type import PurlType
from ...text_location import TextLocation
Expand Down Expand Up @@ -44,6 +46,11 @@ class Choice(BaseModel):
description="An optional comment describing the snippet choice.",
)

@field_validator("reason", mode="before")
@classmethod
def validate_reason(cls, value):
return convert_enum(SnippetChoiceReason, value)
Comment on lines 46 to +52
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

While adding enum parsing for reason, note that the ORT repository-configuration schema allows choice.purl to be null / omitted, but this model currently requires purl. That means valid configs (e.g. reason: NO_RELEVANT_FINDING) will fail validation. Consider making purl optional with a default, and optionally validate that it is present only when required by the selected reason.

Copilot uses AI. Check for mistakes.


class SnippetChoice(BaseModel):
"""
Expand All @@ -61,3 +68,12 @@ class SnippetChoice(BaseModel):
...,
description="The snippet criteria to make the snippet choice.",
)

# @model_validator(mode="before")
# @classmethod
# def validate_snippet_choice(cls, v):
# print(v)
# breakpoint()
# if not isinstance(v, dict):
# raise ValueError("SnippetChoice must be a dictionary.")
# return v
Comment on lines +71 to +79
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

There is commented-out debug / validation code left in the model (@model_validator with print() / breakpoint()). Even commented, it adds noise and can accidentally be re-enabled later. Please remove this block before merging.

Suggested change
# @model_validator(mode="before")
# @classmethod
# def validate_snippet_choice(cls, v):
# print(v)
# breakpoint()
# if not isinstance(v, dict):
# raise ValueError("SnippetChoice must be a dictionary.")
# return v

Copilot uses AI. Check for mistakes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT
#
from pydantic import AnyUrl, BaseModel, ConfigDict, Field


class Provenance(BaseModel):
class SnippetProvenance(BaseModel):
"""
The URL of the [RepositoryProvenance] the snippet choice applies to.
"""
Expand Down
25 changes: 25 additions & 0 deletions src/ort/models/config/snippet_choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from pydantic import BaseModel, ConfigDict, Field

from .snippet.snippet_choice import SnippetChoice
from .snippet.snippet_provenance import SnippetProvenance


class SnippetChoices(BaseModel):
"""
A collection of snippet choices for a given provenance.
"""

model_config = ConfigDict(
extra="forbid",
)
provenance: SnippetProvenance = Field(
...,
description="The source file for which the snippet choice is made.",
)
choices: list[SnippetChoice] = Field(
...,
description="The snippet choice for the given source file.",
)
85 changes: 85 additions & 0 deletions src/ort/models/provenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
# SPDX-License-Identifier: MIT

from pydantic import BaseModel, ConfigDict, Field, model_validator

from .remote_artifact import RemoteArtifact
from .vcsinfo import VcsInfo


class SnippetProvenance(BaseModel):
"""
Provenance information about the origin of source code.

This is a union type that can be one of the following:
- UnknownProvenance: No provenance information is available.
- ArtifactProvenance: Provenance information for a source artifact.
- RepositoryProvenance: Provenance information for a Version Control System location.
"""

model_config = ConfigDict(extra="allow")

@model_validator(mode="before")
@classmethod
def validate_provenance(cls, v):
print(v)
breakpoint()
Comment on lines +25 to +26
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

validate_provenance() currently contains debugging statements (print() and breakpoint()). This will pause execution / spam stdout if the model is ever validated, which is not acceptable for library code. Please remove these statements before merging (use logging only if strictly necessary, and behind an opt-in flag).

Suggested change
print(v)
breakpoint()

Copilot uses AI. Check for mistakes.
if not isinstance(v, dict):
raise ValueError("Provenance must be a dictionary.")
if "source_artifact" in v:
return ArtifactProvenance(**v)
elif "vcs_info" in v and "resolved_revision" in v:
return RepositoryProvenance(**v)
else:
return UnknownProvenance()


class UnknownProvenance(BaseModel):
"""
Provenance information about the origin of source code.
"""

model_config = ConfigDict(extra="forbid")


class KnownProvenance(BaseModel):
"""
Provenance information about the origin of source code.
"""

model_config = ConfigDict(extra="forbid")


class RemoteProvenance(KnownProvenance):
"""
Provenance information about the origin of source code.
"""

model_config = ConfigDict(extra="forbid")


class ArtifactProvenance(RemoteProvenance):
"""
Provenance information for a source artifact.
"""

model_config = ConfigDict(extra="forbid")

source_artifact: RemoteArtifact = Field(
description="The source artifact that was downloaded.",
)


class RepositoryProvenance(BaseModel):
"""
Provenance information for a Version Control System location.
"""

model_config = ConfigDict(extra="forbid")

vcs_info: VcsInfo = Field(
description="VCS info used to resolve the revision. May still contain a moving revision like a branch.",
)
resolved_revision: str = Field(
description="Resolved fixed VCS revision, not blank and not moving (e.g. Git commit SHA1)."
)
Loading