Skip to content

Commit 21c47d4

Browse files
[SPDX-3.0] add creation_info comment
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
1 parent 21d7302 commit 21c47d4

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/spdx3/bump_from_spdx2/creation_information.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def bump_creation_information(spdx2_creation_info: Spdx2_CreationInfo, payload:
2828
print_missing_conversion("creation_info.document_namespace", 0)
2929

3030
created: datetime = spdx2_creation_info.created
31-
# creation_info.creator_comment -> ?
32-
print_missing_conversion("creation_info.creator_comment", 0)
31+
comment = spdx2_creation_info.document_comment
3332
data_license = spdx2_creation_info.data_license
3433
# creation_info.external_document_refs -> spdx_document.imports
3534
imports = [
@@ -41,7 +40,7 @@ def bump_creation_information(spdx2_creation_info: Spdx2_CreationInfo, payload:
4140
# creation_info.document_comment -> spdx_document.comment
4241
document_comment = spdx2_creation_info.document_comment
4342
creation_information = CreationInformation(
44-
Version("3.0.0"), created, [], [], ["core", "software", "licensing"], data_license
43+
Version("3.0.0"), created, [], [], ["core", "software", "licensing"], data_license, comment
4544
)
4645

4746
# due to creators having a creation_information themselves which inherits from the document's one,

src/spdx3/model/creation_information.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# SPDX-License-Identifier: Apache-2.0
44
from datetime import datetime
5-
from typing import List
5+
from typing import List, Optional
66

77
from semantic_version import Version
88

@@ -18,6 +18,7 @@ class CreationInformation:
1818
created_using: List[str] # SPDXID of Tools
1919
profile: List[str] # or create an Enum for ProfileIdentifier?
2020
data_license: str
21+
comment: Optional[str] = None
2122

2223
def __init__(
2324
self,
@@ -27,5 +28,6 @@ def __init__(
2728
created_using: List[str],
2829
profile: List[str],
2930
data_license: str = "CC0",
31+
comment: Optional[str] = None,
3032
):
3133
check_types_and_set_values(self, locals())

src/spdx3/writer/console/creation_information_writer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ def write_creation_info(creation_info: CreationInformation, text_output: TextIO,
1818
write_value("created using", created_using, text_output, indent)
1919
write_value("profile", ", ".join(creation_info.profile), text_output, indent)
2020
write_value("data license", creation_info.data_license, text_output, indent)
21+
write_value("comment", creation_info.comment, text_output, indent)

tests/spdx3/model/test_creation_information.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def test_correct_initialization():
1313
creation_information = CreationInformation(
14-
Version("3.0.0"), datetime(2023, 1, 11, 16, 21), [], [], ["core", "software"], "CC0"
14+
Version("3.0.0"), datetime(2023, 1, 11, 16, 21), [], [], ["core", "software"], "CC0", "some comment"
1515
)
1616

1717
assert creation_information.spec_version == Version("3.0.0")
@@ -20,11 +20,12 @@ def test_correct_initialization():
2020
assert creation_information.created_using == []
2121
assert creation_information.profile == ["core", "software"]
2222
assert creation_information.data_license == "CC0"
23+
assert creation_information.comment == "some comment"
2324

2425

2526
def test_invalid_initialization():
2627
with pytest.raises(TypeError) as err:
27-
CreationInformation("2.3", "2012-01-01", [], [], "core", 3)
28+
CreationInformation("2.3", "2012-01-01", [], [], "core", 3, [])
2829

2930
assert err.value.args[0] == [
3031
'SetterError CreationInformation: type of argument "spec_version" must be '
@@ -33,6 +34,8 @@ def test_invalid_initialization():
3334
"datetime.datetime; got str instead: 2012-01-01",
3435
'SetterError CreationInformation: type of argument "profile" must be a list; ' "got str instead: core",
3536
'SetterError CreationInformation: type of argument "data_license" must be ' "str; got int instead: 3",
37+
'SetterError CreationInformation: type of argument "comment" must be'
38+
" one of (str, NoneType); got list instead: []",
3639
]
3740

3841

0 commit comments

Comments
 (0)