Skip to content

Commit f148e49

Browse files
committed
feat!: this-builder
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 77628be commit f148e49

File tree

5 files changed

+119
-43
lines changed

5 files changed

+119
-43
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: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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, Tool, XsUri
24+
from ..model.component import Component, ComponentType
25+
from ..model.license import DisjunctiveLicense, LicenseAcknowledgement
26+
27+
# !!! keep this file in sync with `pyproject.toml`
28+
29+
# !!!
30+
# things in here are built on demand, rather than using prepared frozen constants.
31+
# this is currently a draft and may change in the future.
32+
# !!!
33+
34+
35+
def __ext_refs() -> Iterable[ExternalReference]:
36+
return (
37+
ExternalReference(
38+
type=ExternalReferenceType.BUILD_SYSTEM,
39+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/actions')
40+
),
41+
ExternalReference(
42+
type=ExternalReferenceType.DISTRIBUTION,
43+
url=XsUri('https://pypi.org/project/cyclonedx-python-lib/')
44+
),
45+
ExternalReference(
46+
type=ExternalReferenceType.DOCUMENTATION,
47+
url=XsUri('https://cyclonedx-python-library.readthedocs.io/')
48+
),
49+
ExternalReference(
50+
type=ExternalReferenceType.ISSUE_TRACKER,
51+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/issues')
52+
),
53+
ExternalReference(
54+
type=ExternalReferenceType.LICENSE,
55+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE')
56+
),
57+
ExternalReference(
58+
type=ExternalReferenceType.RELEASE_NOTES,
59+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md')
60+
),
61+
ExternalReference(
62+
type=ExternalReferenceType.VCS,
63+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib')
64+
),
65+
ExternalReference(
66+
type=ExternalReferenceType.WEBSITE,
67+
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/#readme')
68+
),
69+
)
70+
71+
72+
def this_tool() -> Tool:
73+
"""Representation of this very python library as a :class:`Tool`."""
74+
75+
return Tool(
76+
vendor='CycloneDX',
77+
name='cyclonedx-python-lib',
78+
version=__ThisVersion or 'UNKNOWN',
79+
external_references=__ext_refs(),
80+
)
81+
82+
83+
def this_component() -> Component:
84+
"""Representation of this very python library as a :class:`Component`."""
85+
86+
return Component(
87+
type=ComponentType.LIBRARY,
88+
group='CycloneDX',
89+
name='cyclonedx-python-lib',
90+
version=__ThisVersion or 'UNKNOWN',
91+
description='Python library for CycloneDX',
92+
licenses=(DisjunctiveLicense(id='Apache-2.0',
93+
acknowledgement=LicenseAcknowledgement.DECLARED),),
94+
external_references=__ext_refs(),
95+
# to be expanded ...
96+
)

cyclonedx/model/__init__.py

Lines changed: 0 additions & 41 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,
@@ -1370,43 +1369,3 @@ def __hash__(self) -> int:
13701369

13711370
def __repr__(self) -> str:
13721371
return f'<Copyright text={self.text}>'
1373-
1374-
1375-
ThisTool = Tool(
1376-
vendor='CycloneDX',
1377-
name='cyclonedx-python-lib',
1378-
version=__ThisToolVersion or 'UNKNOWN',
1379-
external_references=[
1380-
ExternalReference(
1381-
type=ExternalReferenceType.BUILD_SYSTEM,
1382-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/actions')
1383-
),
1384-
ExternalReference(
1385-
type=ExternalReferenceType.DISTRIBUTION,
1386-
url=XsUri('https://pypi.org/project/cyclonedx-python-lib/')
1387-
),
1388-
ExternalReference(
1389-
type=ExternalReferenceType.DOCUMENTATION,
1390-
url=XsUri('https://cyclonedx-python-library.readthedocs.io/')
1391-
),
1392-
ExternalReference(
1393-
type=ExternalReferenceType.ISSUE_TRACKER,
1394-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/issues')
1395-
),
1396-
ExternalReference(
1397-
type=ExternalReferenceType.LICENSE,
1398-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE')
1399-
),
1400-
ExternalReference(
1401-
type=ExternalReferenceType.RELEASE_NOTES,
1402-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md')
1403-
),
1404-
ExternalReference(
1405-
type=ExternalReferenceType.VCS,
1406-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib')
1407-
),
1408-
ExternalReference(
1409-
type=ExternalReferenceType.WEBSITE,
1410-
url=XsUri('https://github.com/CycloneDX/cyclonedx-python-lib/#readme')
1411-
)
1412-
])

cyclonedx/model/bom.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
SchemaVersion1Dot6,
3838
)
3939
from ..serialization import LicenseRepositoryHelper, UrnUuidHelper
40-
from . import ExternalReference, Property, ThisTool, Tool
40+
from . import ExternalReference, Property, Tool
41+
from ..builder.this import this_tool
4142
from .bom_ref import BomRef
4243
from .component import Component
4344
from .contact import OrganizationalContact, OrganizationalEntity
@@ -89,7 +90,7 @@ def __init__(
8990
DeprecationWarning)
9091

9192
if not tools:
92-
self.tools.add(ThisTool)
93+
self.tools.add(this_tool())
9394

9495
@property
9596
@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.5.1"
@@ -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)