Skip to content

Commit b6fef39

Browse files
authored
feat(package_config): Merge PR 13
2 parents ca389f1 + 8cb4fbb commit b6fef39

24 files changed

Lines changed: 556 additions & 168 deletions

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.3.1"
7+
version = "0.4.0"
88
description = "A Python Ort model serialization library"
99
readme = "README.md"
1010
license = "MIT"

schemas/repository-configuration-schema.json

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@
796796
"vcs": {
797797
"anyOf": [
798798
{
799-
"$ref": "#/$defs/VcsInfo"
799+
"$ref": "#/$defs/VcsInfoCurationData"
800800
},
801801
{
802802
"type": "null"
@@ -1263,49 +1263,72 @@
12631263
"title": "Sw360Configuration",
12641264
"type": "object"
12651265
},
1266-
"VcsInfo": {
1266+
"VcsInfoCurationData": {
12671267
"description": "Bundles general Version Control System information.\n\nAttributes:\n type(VcsType): The type of the VCS, for example Git, GitRepo, Mercurial, etc.\n url(AnyUrl): The URL to the VCS repository.\n revision(str): The VCS-specific revision (tag, branch, SHA1) that the version of the package maps to.\n path(str): The path inside the VCS to take into account.\n If the VCS supports checking out only a subdirectory, only this path is checked out.",
12681268
"properties": {
12691269
"type": {
1270-
"$ref": "#/$defs/VcsType",
1270+
"anyOf": [
1271+
{
1272+
"$ref": "#/$defs/VcsType"
1273+
},
1274+
{
1275+
"type": "null"
1276+
}
1277+
],
1278+
"default": null,
12711279
"description": "The type of the VCS, for example Git, GitRepo, Mercurial, etc."
12721280
},
12731281
"url": {
1282+
"anyOf": [
1283+
{
1284+
"format": "uri",
1285+
"minLength": 1,
1286+
"type": "string"
1287+
},
1288+
{
1289+
"type": "null"
1290+
}
1291+
],
1292+
"default": null,
12741293
"description": "The URL to the VCS repository.",
1275-
"format": "uri",
1276-
"minLength": 1,
1277-
"title": "Url",
1278-
"type": "string"
1294+
"title": "Url"
12791295
},
12801296
"revision": {
1297+
"anyOf": [
1298+
{
1299+
"type": "string"
1300+
},
1301+
{
1302+
"type": "null"
1303+
}
1304+
],
1305+
"default": null,
12811306
"description": "The VCS-specific revision (tag, branch, SHA1) that the version of the package maps to.",
1282-
"title": "Revision",
1283-
"type": "string"
1307+
"title": "Revision"
12841308
},
12851309
"path": {
1286-
"default": "",
1310+
"anyOf": [
1311+
{
1312+
"type": "string"
1313+
},
1314+
{
1315+
"type": "null"
1316+
}
1317+
],
1318+
"default": null,
12871319
"description": "The path inside the VCS to take into account.If the VCS supports checking out only a subdirectory, only this path is checked out.",
1288-
"title": "Path",
1289-
"type": "string"
1320+
"title": "Path"
12901321
}
12911322
},
1292-
"required": [
1293-
"url",
1294-
"revision"
1295-
],
1296-
"title": "VcsInfo",
1323+
"title": "VcsInfoCurationData",
12971324
"type": "object"
12981325
},
12991326
"VcsType": {
1300-
"description": "A class for Version Control System types. Each type has one or more [aliases] associated to it,\nwhere the first alias is the definite name. This class is not implemented as an enum as\nconstructing from an unknown type should be supported while maintaining that type as the primary\nalias for the string representation.\n\nAttributes:\n aliases(list[str]): Primary name and aliases",
1327+
"description": "A class for Version Control System types. Each type has one or more [aliases] associated to it,\nwhere the first alias is the definite name. This class is not implemented as an enum as\nconstructing from an unknown type should be supported while maintaining that type as the primary\nalias for the string representation.\n\nAttributes:\n name(str): Primary name and aliases",
13011328
"properties": {
1302-
"aliases": {
1303-
"description": "Primary name and aliases",
1304-
"items": {
1305-
"type": "string"
1306-
},
1307-
"title": "Aliases",
1308-
"type": "array"
1329+
"name": {
1330+
"title": "Name",
1331+
"type": "string"
13091332
}
13101333
},
13111334
"title": "VcsType",

src/ort/__init__.py

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

5-
from ort.models.analyzer_configurations import OrtAnalyzerConfigurations
6-
from ort.models.ort_configuration import OrtConfiguration, Scanner, Severity, Storages
7-
from ort.models.package_managers import OrtPackageManagerConfigurations, OrtPackageManagers
85
from ort.models.repository_configuration import OrtRepositoryConfiguration
96

107
__all__ = [
11-
"OrtAnalyzerConfigurations",
12-
"OrtConfiguration",
13-
"OrtPackageManagerConfigurations",
14-
"OrtPackageManagers",
158
"OrtRepositoryConfiguration",
16-
"Scanner",
17-
"Severity",
18-
"Storages",
199
]

src/ort/models/analyzer_configurations.py

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field
6+
7+
from ort.models.config.package_manager_configuration import PackageManagerConfiguration
8+
9+
_package_managers: list[str] = [
10+
"Bazel",
11+
"Bower",
12+
"Bundler",
13+
"Cargo",
14+
"Carthage",
15+
"CocoaPods",
16+
"Composer",
17+
"Conan",
18+
"GoMod",
19+
"GradleInspector",
20+
"Maven",
21+
"NPM",
22+
"NuGet",
23+
"PIP",
24+
"Pipenv",
25+
"PNPM",
26+
"Poetry",
27+
"Pub",
28+
"SBT",
29+
"SpdxDocumentFile",
30+
"Stack",
31+
"SwiftPM",
32+
"Tycho",
33+
"Unmanaged",
34+
"Yarn",
35+
"Yarn2",
36+
]
37+
38+
39+
class AnalyzerConfiguration(BaseModel):
40+
"""
41+
Enable the analysis of projects that use version ranges to declare their dependencies. If set to true,
42+
dependencies of exactly the same project might change with another scan done at a later time if any of the
43+
(transitive) dependencies are declared using version ranges and a new version of such a dependency was
44+
published in the meantime. If set to false, analysis of projects that use version ranges will fail. Defaults to
45+
false.
46+
"""
47+
48+
model_config = ConfigDict(
49+
extra="forbid",
50+
)
51+
allow_dynamic_versions: bool = Field(
52+
default=False,
53+
description="Enable the analysis of projects that use version ranges to declare their dependencies."
54+
"If set to true, dependencies of exactly the same project might change with another scan done at a later time"
55+
"if any of the (transitive) dependencies are declared using version ranges and a new version of such a"
56+
"dependency was published in the meantime. If set to false, analysis of projects that use version ranges will"
57+
"fail. Defaults to false.",
58+
)
59+
enabled_package_managers: list[str] = Field(
60+
default=_package_managers,
61+
description="A list of the case-insensitive names of package managers that are enabled."
62+
"Disabling a package manager in [disabledPackageManagers] overrides enabling it here.",
63+
)
64+
disabled_package_managers: list[str] | None = Field(
65+
default=None,
66+
description="A list of the case-insensitive names of package managers that are disabled."
67+
"Disabling a package manager in this list overrides [enabledPackageManagers].",
68+
)
69+
package_managers: dict[str, PackageManagerConfiguration] | None = Field(
70+
default=None,
71+
description="Get a [PackageManagerConfiguration] from [packageManagers]. The difference to accessing the map"
72+
"directly is that [packageManager] can be case-insensitive.",
73+
)
74+
skip_excluded: bool = Field(
75+
default=False,
76+
description="A flag to control whether excluded scopes and paths should be skipped during the analysis.",
77+
)

src/ort/models/config/license_finding_curation.py

Lines changed: 17 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 typing import Any
6+
7+
from pydantic import BaseModel, ConfigDict, Field, field_validator
68

79
from ort.models.config.license_finding_curation_reason import LicenseFindingCurationReason
810

@@ -59,3 +61,17 @@ class LicenseFindingCuration(BaseModel):
5961
default=None,
6062
description="A comment explaining this [LicenseFindingCuration].",
6163
)
64+
65+
@field_validator("start_lines", mode="before")
66+
@classmethod
67+
def parse_start_lines(cls, value: Any) -> list[int] | None:
68+
if value is None or value == "":
69+
return None
70+
if isinstance(value, str):
71+
# CSV style split
72+
return [int(x.strip()) for x in value.split(",") if x.strip()]
73+
if isinstance(value, list):
74+
return [int(x) for x in value]
75+
if isinstance(value, int):
76+
return [value]
77+
raise ValueError("start_lines must be a comma-separated string or a list of integers")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field
6+
7+
from ort.models.config.license_finding_curation import LicenseFindingCuration
8+
from ort.models.config.path_exclude import PathExclude
9+
from ort.models.config.vcsmatcher import VcsMatcher
10+
from ort.models.identifier import Identifier
11+
from ort.models.source_code_origin import SourceCodeOrigin
12+
13+
14+
class PackageConfiguration(BaseModel):
15+
"""
16+
A class used in the [OrtConfiguration] to configure [PathExclude]s and [LicenseFindingCuration]s for a specific
17+
[Package]'s [Identifier] (and [Provenance]).
18+
Note that [PathExclude]s and [LicenseFindingCuration]s for [Project]s are configured by a
19+
[RepositoryConfiguration]'s excludes and curations properties instead.
20+
21+
Attributes:
22+
id (Identifier): The [Identifier] which must match with the identifier of the package in
23+
order for this package curation to apply. The [version][Identifier.version] can be
24+
either a plain version string matched for equality, or an Ivy-style version matchers.
25+
* The other components of the [identifier][id] are matched by equality.
26+
source_artifact_url (str | None): The source artifact this configuration applies to.
27+
vcs (VcsMatcher | None): The vcs and revision this configuration applies to.
28+
source_code_origin (SourceCodeOrigin | None): The source code origin this configuration
29+
applies to.
30+
path_excludes (list[PathExclude]): Path excludes.
31+
license_finding_curations (list[LicenseFindingCuration]): License finding curations.
32+
"""
33+
34+
model_config = ConfigDict(
35+
extra="forbid",
36+
)
37+
38+
id: Identifier = Field(
39+
description="The [Identifier] which must match with the identifier of the package in order for this package"
40+
"curation to apply. The [version][Identifier.version] can be either a plain version string matched for"
41+
"equality, or an Ivy-style version matchers."
42+
"* The other components of the [identifier][id] are matched by equality.",
43+
)
44+
45+
source_artifact_url: str | None = Field(
46+
default=None,
47+
description="The source artifact this configuration applies to.",
48+
)
49+
50+
vcs: VcsMatcher | None = Field(
51+
default=None,
52+
description="The vcs and revision this configuration applies to.",
53+
)
54+
55+
source_code_origin: SourceCodeOrigin | None = Field(
56+
default=None,
57+
description="The source code origin this configuration applies to.",
58+
)
59+
60+
path_excludes: list[PathExclude] = Field(
61+
default_factory=list,
62+
description="Path excludes.",
63+
)
64+
65+
license_finding_curations: list[LicenseFindingCuration] = Field(
66+
default_factory=list,
67+
description="License finding curations.",
68+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
2+
# SPDX-License-Identifier: MIT
3+
4+
5+
from pydantic import BaseModel, ConfigDict, Field
6+
7+
8+
class PackageManagerConfiguration(BaseModel):
9+
model_config = ConfigDict(
10+
extra="forbid",
11+
)
12+
13+
must_run_after: list[str] | None = Field(
14+
default=None,
15+
description="The configuration model for a package manager. This class is (de-)serialized in the following"
16+
"places:"
17+
"- Deserialized from config.yml as part of [OrtConfiguration] (via Hoplite)."
18+
"- Deserialized from .ort.yml as part of [RepositoryAnalyzerConfiguration] (via Jackson)"
19+
"- (De-)Serialized as part of [org.ossreviewtoolkit.model.OrtResult] (via Jackson).",
20+
)
21+
22+
options: dict[str, str] | None = Field(
23+
default=None,
24+
description="Custom configuration options for the package manager. See the documentation of the respective"
25+
"class for available options.",
26+
)

0 commit comments

Comments
 (0)