Skip to content

Commit 3585ea9

Browse files
authored
feat: programmatic access to library's version (#417)
adds `cyclonedx.__version__` Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 14c501c commit 3585ea9

File tree

7 files changed

+57
-31
lines changed

7 files changed

+57
-31
lines changed

cyclonedx/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
"""
1818
Python library for generating and representing CycloneDX software bill-of-materials.
1919
"""
20+
21+
# !! version is managed by semantic_release
22+
# do not use typing here, or else `semantic_release` might have issues finding the variable
23+
__version__ = "4.1.0-alpha.1"

cyclonedx/model/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import hashlib
1919
import re
20-
import sys
2120
import warnings
2221
from datetime import datetime, timezone
2322
from enum import Enum
@@ -26,6 +25,7 @@
2625
import serializable
2726
from sortedcontainers import SortedSet
2827

28+
from .. import __version__ as __ThisToolVersion
2929
from ..exception.model import (
3030
InvalidLocaleTypeException,
3131
InvalidUriException,
@@ -1394,15 +1394,6 @@ def __repr__(self) -> str:
13941394
return f'<Copyright text={self.text}>'
13951395

13961396

1397-
if sys.version_info >= (3, 8):
1398-
from importlib.metadata import version as meta_version
1399-
else:
1400-
from importlib_metadata import version as meta_version
1401-
1402-
try:
1403-
__ThisToolVersion: Optional[str] = str(meta_version('cyclonedx-python-lib')) # type: ignore[no-untyped-call]
1404-
except Exception:
1405-
__ThisToolVersion = None
14061397
ThisTool = Tool(vendor='CycloneDX', name='cyclonedx-python-lib', version=__ThisToolVersion or 'UNKNOWN')
14071398
ThisTool.external_references.update([
14081399
ExternalReference(

deps.lowest.r

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33

44
packageurl-python == 0.11.1
55
py-serializable == 0.11.1
6-
importlib-metadata == 3.4.0 # ; python_version < '3.8'
76

87
# file name is a untypical one, so dependabot does not bump this file

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
16-
import pkg_resources
1716

1817
# -- Project information -----------------------------------------------------
1918

@@ -22,7 +21,8 @@
2221
author = 'Paul Horton, Jan Kowalleck, Steve Springett, Patrick Dwyer'
2322

2423
# The full version, including alpha/beta/rc tags
25-
release = pkg_resources.get_distribution("cyclonedx-python-lib").version
24+
# !! version is managed by semantic_release
25+
release = '4.1.0-alpha.1'
2626

2727
# -- General configuration ---------------------------------------------------
2828

poetry.lock

Lines changed: 44 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)