Skip to content

Commit 39e4ffb

Browse files
authored
Merge pull request #18 from heliocastro/refactor/repository_config
refactor(repoconfig): Get rid of legacy classes
2 parents 640ceb2 + 8a6eae6 commit 39e4ffb

32 files changed

Lines changed: 824 additions & 380 deletions

src/ort/__init__.py

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

5-
from ort.models.analyzer_result import AnalyzerResult
6-
from ort.models.ort_result import OrtResult
7-
from ort.models.repository_configuration import RepositoryConfiguration
5+
from .models.analyzer_result import AnalyzerResult
6+
from .models.config.repository_configuration import RepositoryConfiguration
7+
from .models.ort_result import OrtResult
88

99
__all__ = [
1010
"AnalyzerResult",

src/ort/models/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from .advisor_run import AdvisorRun
77
from .analyzer_result import AnalyzerResult
88
from .analyzer_run import AnalyzerRun
9+
from .config.excludes import Excludes
10+
from .config.includes import Includes
11+
from .config.path_exclude import PathExclude
12+
from .config.path_exclude_reason import PathExcludeReason
13+
from .config.path_include import PathInclude
14+
from .config.path_include_reason import PathIncludeReason
15+
from .config.repository_configuration import RepositoryConfiguration
916
from .dependency_graph import DependencyGraph
1017
from .dependency_graph_edge import DependencyGraphEdge
1118
from .dependency_graph_node import DependencyGraphNode
@@ -23,7 +30,6 @@
2330
from .project import Project
2431
from .remote_artifact import RemoteArtifact
2532
from .repository import Repository
26-
from .repository_configuration import RepositoryConfiguration
2733
from .root_dependency_index import RootDependencyIndex
2834
from .scope import Scope
2935
from .source_code_origin import SourceCodeOrigin
@@ -44,13 +50,19 @@
4450
"Hash",
4551
"HashAlgorithm",
4652
"Identifier",
53+
"Includes",
54+
"Excludes",
4755
"Issue",
4856
"OrtResult",
4957
"Package",
5058
"PackageCuration",
5159
"PackageCurationData",
5260
"PackageLinkage",
5361
"PackageReference",
62+
"PathExcludeReason",
63+
"PathIncludeReason",
64+
"PathExclude",
65+
"PathInclude",
5466
"Project",
5567
"RemoteArtifact",
5668
"Repository",

src/ort/models/config/excludes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field
6+
7+
from .path_exclude import PathExclude
8+
from .scope_exclude import ScopeExclude
9+
10+
11+
class Excludes(BaseModel):
12+
"""
13+
Defines which parts of a repository should be excluded.
14+
"""
15+
16+
model_config = ConfigDict(
17+
extra="forbid",
18+
)
19+
20+
paths: list[PathExclude] = Field(
21+
default_factory=list,
22+
description="Path excludes.",
23+
)
24+
25+
scopes: list[ScopeExclude] = Field(
26+
default_factory=list,
27+
description="Scopes that will be excluded from all projects.",
28+
)

src/ort/models/config/includes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field
6+
7+
from .path_include import PathInclude
8+
9+
10+
class Includes(BaseModel):
11+
"""
12+
Defines which parts of a repository should be excluded.
13+
"""
14+
15+
model_config = ConfigDict(
16+
extra="forbid",
17+
)
18+
19+
paths: list[PathInclude] = Field(
20+
default_factory=list,
21+
description="Path includes.",
22+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field
6+
7+
from .issue_resolution_reason import IssueResolutionReason
8+
9+
10+
class IssueResolution(BaseModel):
11+
"""
12+
Defines the resolution of an [Issue]. This can be used to silence false positives, or issues that have been
13+
identified as not being relevant.
14+
"""
15+
16+
model_config = ConfigDict(
17+
extra="forbid",
18+
)
19+
20+
message: str = Field(
21+
description="A regular expression string to match the messages of issues to resolve. Whitespace in the message"
22+
"will be [collapsed][collapseWhitespace] and it will be converted to a [Regex] using"
23+
"[RegexOption.DOT_MATCHES_ALL].",
24+
)
25+
26+
reason: IssueResolutionReason = Field(
27+
description="The reason why the issue is resolved.",
28+
)
29+
30+
comment: str = Field(
31+
description="A comment to further explain why the [reason] is applicable here.",
32+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
from enum import IntEnum
5+
6+
7+
class IssueResolutionReason(IntEnum):
8+
"""
9+
Possible reasons for resolving an Issue using an IssueResolution.
10+
11+
properties:
12+
BUILD_TOOL_ISSUE:
13+
The issue originates from the build tool used by the project.
14+
CANT_FIX_ISSUE:
15+
The issue can not be fixed.
16+
For example, it requires a change to be made by a third party that is not responsive.
17+
SCANNER_ISSUE:
18+
The issue is due to an irrelevant scanner issue.
19+
For example, a time out on a large file that is not distributed.
20+
"""
21+
22+
BUILD_TOOL_ISSUE = 1
23+
CANT_FIX_ISSUE = 2
24+
SCANNER_ISSUE = 3
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
from pydantic import BaseModel, ConfigDict, Field
4+
5+
from ...utils.spdx.spdx_license_choice import SpdxLicenseChoice
6+
from ..identifier import Identifier
7+
8+
9+
class PackageLicenseChoice(BaseModel):
10+
"""
11+
SpdxLicenseChoice]s defined for an artifact.
12+
"""
13+
14+
model_config = ConfigDict(
15+
extra="forbid",
16+
)
17+
package_id: Identifier = Field(
18+
...,
19+
description="Package ID",
20+
)
21+
license_choice: list[SpdxLicenseChoice] = Field(
22+
default_factory=list,
23+
description="List of spdx license",
24+
)
25+
26+
27+
class LicenseChoice(BaseModel):
28+
"""
29+
[SpdxLicenseChoice]s that are applied to all packages in the repository. As the [SpdxLicenseChoice] is applied to
30+
each package that offers this license as a choice, [SpdxLicenseChoice.given] can not be null. This helps only
31+
applying the choice to a wanted [SpdxLicenseChoice.given] as opposed to all licenses with that choice, which
32+
could lead to unwanted applied choices.
33+
"""
34+
35+
model_config = ConfigDict(
36+
extra="forbid",
37+
)
38+
repository_license_choices: list[SpdxLicenseChoice] = Field(
39+
default_factory=list,
40+
description="SPDX",
41+
)
42+
package_license_choice: list[PackageLicenseChoice] = Field(
43+
default_factory=list,
44+
description="Package",
45+
)

src/ort/models/config/path_exclude.py

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

44

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

7-
from ort.models.config.path_exclude_reason import PathExcludeReason
7+
from ort.utils import convert_enum
8+
9+
from .path_exclude_reason import PathExcludeReason
810

911

1012
class PathExclude(BaseModel):
@@ -30,3 +32,8 @@ class PathExclude(BaseModel):
3032
default_factory=str,
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(PathExcludeReason, value)
Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,47 @@
11
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
22
# SPDX-License-Identifier: MIT
33

4-
from enum import Enum, auto
4+
from enum import IntEnum
55

66

7-
class PathExcludeReason(Enum):
7+
class PathExcludeReason(IntEnum):
88
"""
99
Possible reasons for excluding a path.
10-
Attributes
10+
11+
Attributes:
1112
BUILD_TOOL_OF
1213
The path only contains tools used for building source code which are not included in
1314
distributed build artifacts.
14-
1515
DATA_FILE_OF
1616
The path only contains data files such as fonts or images which are not included in
1717
distributed build artifacts.
18-
1918
DOCUMENTATION_OF
2019
The path only contains documentation which is not included in distributed build artifacts.
21-
2220
EXAMPLE_OF
2321
The path only contains source code examples which are not included in distributed build
2422
artifacts.
25-
2623
OPTIONAL_COMPONENT_OF
2724
The path only contains optional components for the code that is built which are not included
2825
in distributed build artifacts.
29-
3026
OTHER
3127
Any other reason which cannot be represented by any other element of PathExcludeReason.
32-
3328
PROVIDED_BY
3429
The path only contains packages or sources for packages that have to be provided by the user
3530
of distributed build artifacts.
36-
3731
TEST_OF
3832
The path only contains files used for testing source code which are not included in
3933
distributed build artifacts.
40-
4134
TEST_TOOL_OF
4235
The path only contains tools used for testing source code which are not included in
4336
distributed build artifacts.
4437
"""
4538

46-
# The path only contains tools used for building source code which are not included in distributed build artifacts.
47-
BUILD_TOOL_OF = auto()
48-
49-
# The path only contains data files such as fonts or images which are not included in distributed build artifacts.
50-
DATA_FILE_OF = auto()
51-
52-
# The path only contains documentation which is not included in distributed build artifacts.
53-
DOCUMENTATION_OF = auto()
54-
55-
# The path only contains source code examples which are not included in distributed build artifacts.
56-
EXAMPLE_OF = auto()
57-
58-
# The path only contains optional components for the code that is built which are not included
59-
# in distributed build artifacts.
60-
OPTIONAL_COMPONENT_OF = auto()
61-
62-
# Any other reason which cannot be represented by any other element of PathExcludeReason.
63-
OTHER = auto()
64-
65-
# The path only contains packages or sources for packages that have to be provided by the user
66-
# of distributed build artifacts.
67-
PROVIDED_BY = auto()
68-
69-
# The path only contains files used for testing source code which are not included in distributed build artifacts.
70-
TEST_OF = auto()
71-
72-
# The path only contains tools used for testing source code which are not included in distributed build artifacts.
73-
TEST_TOOL_OF = auto()
39+
BUILD_TOOL_OF = 1
40+
DATA_FILE_OF = 2
41+
DOCUMENTATION_OF = 3
42+
EXAMPLE_OF = 4
43+
OPTIONAL_COMPONENT_OF = 5
44+
OTHER = 6
45+
PROVIDED_BY = 7
46+
TEST_OF = 8
47+
TEST_TOOL_OF = 9
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# SPDX-FileCopyrightText: 2026 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field, field_validator
6+
7+
from ort.utils import convert_enum
8+
9+
from .path_include_reason import PathIncludeReason
10+
11+
12+
class PathInclude(BaseModel):
13+
"""
14+
Defines paths which should be excluded. Each file or directory that is matched by the [glob][pattern] is marked as
15+
excluded. If a project definition file is matched by the [pattern], the whole project is excluded. For details about
16+
the glob syntax see the [FileMatcher] implementation.
17+
"""
18+
19+
model_config = ConfigDict(
20+
extra="forbid",
21+
)
22+
23+
pattern: str = Field(
24+
description="A glob to match the path of the project definition file, relative to the root of the repository."
25+
)
26+
27+
reason: PathIncludeReason = Field(
28+
description="The reason why the project is included, out of a predefined choice.",
29+
)
30+
31+
comment: str = Field(
32+
default_factory=str,
33+
description="A comment to further explain why the [reason] is applicable here.",
34+
)
35+
36+
@field_validator("reason", mode="before")
37+
@classmethod
38+
def validate_reason(cls, value):
39+
return convert_enum(PathIncludeReason, value)

0 commit comments

Comments
 (0)