Skip to content

Commit 8c007d2

Browse files
committed
feat!: this-builder
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 0ec785d commit 8c007d2

File tree

5 files changed

+120
-47
lines changed

5 files changed

+120
-47
lines changed

cyclonedx/builder/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
# Copyright (c) OWASP Foundation. All Rights Reserved.
15+
16+
"""
17+
Builders used in this library.
18+
"""

cyclonedx/builder/this.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License");
2+
# you may not use this file except in compliance with the License.
3+
# You may obtain a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
#
13+
# SPDX-License-Identifier: Apache-2.0
14+
# Copyright (c) OWASP Foundation. All Rights Reserved.
15+
16+
"""Representation of this very python library."""
17+
18+
__all__ = ['this_tool', 'this_component']
19+
20+
from typing import Iterable
21+
22+
from .. import __version__ as __ThisVersion # noqa: N812
23+
from ..model import ExternalReference, ExternalReferenceType, XsUri
24+
from ..model.component import Component, ComponentType
25+
from ..model.license import DisjunctiveLicense, LicenseAcknowledgement
26+
from ..model.tool import Tool
27+
28+
# !!! keep this file in sync with `pyproject.toml`
29+
30+
# !!!
31+
# things in here are built on demand, rather than using prepared frozen constants.
32+
# this is currently a draft and may change in the future.
33+
# !!!
34+
35+
36+
def __ext_refs() -> Iterable[ExternalReference]:
37+
return (
38+
ExternalReference(
39+
type=ExternalReferenceType.BUILD_SYSTEM,
40+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/actions')
41+
),
42+
ExternalReference(
43+
type=ExternalReferenceType.DISTRIBUTION,
44+
url=XsUri('https://pypi.org/project/cyclonedx-python-lib/')
45+
),
46+
ExternalReference(
47+
type=ExternalReferenceType.DOCUMENTATION,
48+
url=XsUri('https://cyclonedx-python-library.readthedocs.io/')
49+
),
50+
ExternalReference(
51+
type=ExternalReferenceType.ISSUE_TRACKER,
52+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/issues')
53+
),
54+
ExternalReference(
55+
type=ExternalReferenceType.LICENSE,
56+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE')
57+
),
58+
ExternalReference(
59+
type=ExternalReferenceType.RELEASE_NOTES,
60+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md')
61+
),
62+
ExternalReference(
63+
type=ExternalReferenceType.VCS,
64+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib')
65+
),
66+
ExternalReference(
67+
type=ExternalReferenceType.WEBSITE,
68+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/#readme')
69+
),
70+
)
71+
72+
73+
def this_tool() -> Tool:
74+
"""Representation of this very python library as a :class:`Tool`."""
75+
76+
return Tool(
77+
vendor='CycloneDX',
78+
name='cyclonedx-python-lib',
79+
version=__ThisVersion or 'UNKNOWN',
80+
external_references=__ext_refs(),
81+
)
82+
83+
84+
def this_component() -> Component:
85+
"""Representation of this very python library as a :class:`Component`."""
86+
87+
return Component(
88+
type=ComponentType.LIBRARY,
89+
group='CycloneDX',
90+
name='cyclonedx-python-lib',
91+
version=__ThisVersion or 'UNKNOWN',
92+
description='Python library for CycloneDX',
93+
licenses=(DisjunctiveLicense(id='Apache-2.0',
94+
acknowledgement=LicenseAcknowledgement.DECLARED),),
95+
external_references=__ext_refs(),
96+
# to be expanded ...
97+
)

cyclonedx/model/__init__.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import serializable
3333
from sortedcontainers import SortedSet
3434

35-
from .. import __version__ as __ThisToolVersion # noqa: N812
3635
from .._internal.compare import ComparableTuple as _ComparableTuple
3736
from ..exception.model import (
3837
InvalidLocaleTypeException,
@@ -1262,47 +1261,3 @@ def __hash__(self) -> int:
12621261

12631262
def __repr__(self) -> str:
12641263
return f'<Copyright text={self.text}>'
1265-
1266-
1267-
# Importing here to avoid a circular import
1268-
from .tool import Tool # pylint: disable=wrong-import-position # noqa: E402
1269-
1270-
ThisTool = Tool(
1271-
vendor='CycloneDX',
1272-
name='cyclonedx-python-lib',
1273-
version=__ThisToolVersion or 'UNKNOWN',
1274-
external_references=[
1275-
ExternalReference(
1276-
type=ExternalReferenceType.BUILD_SYSTEM,
1277-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/actions')
1278-
),
1279-
ExternalReference(
1280-
type=ExternalReferenceType.DISTRIBUTION,
1281-
url=XsUri('https://pypi.org/project/cyclonedx-python-lib/')
1282-
),
1283-
ExternalReference(
1284-
type=ExternalReferenceType.DOCUMENTATION,
1285-
url=XsUri('https://cyclonedx-python-library.readthedocs.io/')
1286-
),
1287-
ExternalReference(
1288-
type=ExternalReferenceType.ISSUE_TRACKER,
1289-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/issues')
1290-
),
1291-
ExternalReference(
1292-
type=ExternalReferenceType.LICENSE,
1293-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE')
1294-
),
1295-
ExternalReference(
1296-
type=ExternalReferenceType.RELEASE_NOTES,
1297-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md')
1298-
),
1299-
ExternalReference(
1300-
type=ExternalReferenceType.VCS,
1301-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib')
1302-
),
1303-
ExternalReference(
1304-
type=ExternalReferenceType.WEBSITE,
1305-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/#readme')
1306-
)
1307-
]
1308-
)

cyclonedx/model/bom.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from sortedcontainers import SortedSet
2727

2828
from .._internal.time import get_now_utc as _get_now_utc
29+
from ..builder.this import this_component
2930
from ..exception.model import LicenseExpressionAlongWithOthersException, UnknownComponentDependencyException
3031
from ..schema.schema import (
3132
SchemaVersion1Dot0,
@@ -37,7 +38,7 @@
3738
SchemaVersion1Dot6,
3839
)
3940
from ..serialization import LicenseRepositoryHelper, UrnUuidHelper
40-
from . import ExternalReference, Property, ThisTool
41+
from . import ExternalReference, Property
4142
from .bom_ref import BomRef
4243
from .component import Component
4344
from .contact import OrganizationalContact, OrganizationalEntity
@@ -90,7 +91,7 @@ def __init__(
9091
DeprecationWarning)
9192

9293
if not tools:
93-
self.tools.tools.add(ThisTool)
94+
self.tools.components.add(this_component())
9495

9596
@property
9697
@serializable.type_mapping(serializable.helpers.XsdDateTime)

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
6+
# keep in sync with `cyclonedx/builder/this.py`
67
name = "cyclonedx-python-lib"
78
# !! version is managed by semantic_release
89
version = "7.6.0"
@@ -63,6 +64,7 @@ keywords = [
6364
]
6465

6566
[tool.poetry.urls]
67+
# keep in sync with `cyclonedx/builder/this.py`
6668
"Bug Tracker" = "https://github.com/CycloneDX/cyclonedx-python-lib/issues"
6769
"Funding" = "https://owasp.org/donate/?reponame=www-project-cyclonedx&title=OWASP+CycloneDX"
6870

0 commit comments

Comments
 (0)