-
Notifications
You must be signed in to change notification settings - Fork 1
Snippet repository config #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ wheels/ | |
| .python-version | ||
|
|
||
| # Old python requirements | ||
| requirements.txt | ||
| requirements.txtq | ||
|
|
||
| # Ort directories | ||
| output | ||
This file was deleted.
| 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", | ||
| ] | ||
| } | ||
| ] |
| 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 | ||||||||||||||||||||
|
|
@@ -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) | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| class SnippetChoice(BaseModel): | ||||||||||||||||||||
| """ | ||||||||||||||||||||
|
|
@@ -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
|
||||||||||||||||||||
| # @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 |
| 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.", | ||
| ) |
| 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
|
||||||
| print(v) | |
| breakpoint() |
There was a problem hiding this comment.
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 allowschoice.purlto be null / omitted, but this model currently requirespurl. That means valid configs (e.g.reason: NO_RELEVANT_FINDING) will fail validation. Consider makingpurloptional with a default, and optionally validate that it is present only when required by the selectedreason.