Skip to content

Commit eea2593

Browse files
committed
feat: programmatic access to library's version
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 0e35d88 commit eea2593

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
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(

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
author = 'Paul Horton, Jan Kowalleck, Steve Springett, Patrick Dwyer'
2323

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

2728
# -- General configuration ---------------------------------------------------
2829

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "cyclonedx-python-lib"
7-
version = "4.0.1"
7+
# !! version is managed by semantic_release
8+
version = "4.1.0-alpha.1"
89
description = "A library for producing CycloneDX SBOM (Software Bill of Materials) files."
910
authors = ["Paul Horton <phorton@sonatype.com>"]
1011
maintainers = [
@@ -76,6 +77,10 @@ commit_message = "chore(release): {version}\n\nAutomatically generated by python
7677
upload_to_vcs_release = true
7778
build_command = "pip install poetry && poetry build"
7879
version_toml = ["pyproject.toml:tool.poetry.version"]
80+
version_variables = [
81+
"cyclonedx/__init__.py:__version__",
82+
"docs/conf.py:release",
83+
]
7984
[tool.semantic_release.changelog]
8085
changelog_file = "CHANGELOG.md"
8186
exclude_commit_patterns = [

0 commit comments

Comments
 (0)