Skip to content

Commit 1dc829f

Browse files
bumping: make creation_info optional, remove licenses for now
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
1 parent dfe48d8 commit 1dc829f

File tree

13 files changed

+43
-116
lines changed

13 files changed

+43
-116
lines changed

src/spdx_tools/spdx3/bump_from_spdx2/actor.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-FileCopyrightText: 2023 spdx contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4+
from typing import Optional
5+
46
from beartype.typing import List
57

68
from spdx_tools.spdx3.model import CreationInfo, ExternalIdentifier, ExternalIdentifierType, Organization, Person, Tool
@@ -10,7 +12,7 @@
1012

1113

1214
def bump_actor(
13-
spdx2_actor: Spdx2_Actor, payload: Payload, creation_info: CreationInfo, document_namespace: str
15+
spdx2_actor: Spdx2_Actor, payload: Payload, document_namespace: str, creation_info: Optional[CreationInfo] = None
1416
) -> str:
1517
name: str = spdx2_actor.name
1618
email: str = spdx2_actor.email
@@ -27,20 +29,21 @@ def bump_actor(
2729
if spdx_id in payload.get_full_map(): # the agent/tool already exists, so we don't need to create a new one
2830
return spdx_id
2931

32+
value_dict = {
33+
"spdx_id": spdx_id,
34+
"creation_info": creation_info,
35+
"name": name,
36+
"external_identifier": external_identifiers,
37+
}
38+
3039
if actor_type == ActorType.PERSON:
31-
agent_or_tool = Person(
32-
spdx_id=spdx_id, creation_info=creation_info, name=name, external_identifier=external_identifiers
33-
)
40+
agent_or_tool = Person(**value_dict)
3441

3542
elif actor_type == ActorType.ORGANIZATION:
36-
agent_or_tool = Organization(
37-
spdx_id=spdx_id, creation_info=creation_info, name=name, external_identifier=external_identifiers
38-
)
43+
agent_or_tool = Organization(**value_dict)
3944

4045
elif actor_type == ActorType.TOOL:
41-
agent_or_tool = Tool(
42-
spdx_id=spdx_id, creation_info=creation_info, name=name, external_identifier=external_identifiers
43-
)
46+
agent_or_tool = Tool(**value_dict)
4447

4548
else:
4649
raise ValueError(f"no conversion rule defined for ActorType {actor_type}")

src/spdx_tools/spdx3/bump_from_spdx2/annotation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def bump_annotation(
2525
# caution: the annotator and the annotation will only share the same creation_info if the actor
2626
# has not been previously defined
2727
annotator = spdx2_annotation.annotator
28-
creator_id: str = bump_actor(annotator, payload, creation_info, document_namespace)
28+
creator_id: str = bump_actor(annotator, payload, document_namespace, creation_info)
2929
if annotator.actor_type in [ActorType.PERSON, ActorType.ORGANIZATION]:
3030
creation_info.created_by = [creator_id]
3131
else:

src/spdx_tools/spdx3/bump_from_spdx2/creation_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def bump_creation_info(spdx2_creation_info: Spdx2_CreationInfo, payload: Payload
4646
creator_ids: List[str] = []
4747
tool_ids: List[str] = []
4848
for creator in spdx2_creation_info.creators:
49-
bumped_actor_id = bump_actor(creator, payload, creation_info, document_namespace)
49+
bumped_actor_id = bump_actor(creator, payload, document_namespace, creation_info)
5050
if creator.actor_type in [ActorType.PERSON, ActorType.ORGANIZATION]:
5151
creator_ids.append(bumped_actor_id)
5252
else:

src/spdx_tools/spdx3/bump_from_spdx2/file.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
from beartype.typing import List
55

66
from spdx_tools.spdx3.bump_from_spdx2.checksum import bump_checksum
7-
from spdx_tools.spdx3.bump_from_spdx2.license_expression import bump_license_expression_or_none_or_no_assertion
87
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
9-
from spdx_tools.spdx3.model import CreationInfo, ExternalMap
8+
from spdx_tools.spdx3.model import ExternalMap
109
from spdx_tools.spdx3.model.software import File
1110
from spdx_tools.spdx3.payload import Payload
12-
from spdx_tools.spdx.model import ExternalDocumentRef, ExtractedLicensingInfo, SpdxNoAssertion
11+
from spdx_tools.spdx.model import ExternalDocumentRef, SpdxNoAssertion
1312
from spdx_tools.spdx.model.file import File as Spdx2_File
1413
from spdx_tools.spdx.spdx_element_utils import get_full_element_spdx_id
1514

1615

1716
def bump_file(
1817
spdx2_file: Spdx2_File,
1918
payload: Payload,
20-
creation_info: CreationInfo,
2119
document_namespace: str,
22-
extracted_licensing_info: List[ExtractedLicensingInfo],
2320
external_document_refs: List[ExternalDocumentRef],
2421
imports: List[ExternalMap],
2522
):
@@ -36,9 +33,6 @@ def bump_file(
3633
print_missing_conversion(
3734
"file.file_type", 0, "different cardinalities, " "https://github.com/spdx/spdx-3-model/issues/82"
3835
)
39-
license_concluded = bump_license_expression_or_none_or_no_assertion(
40-
spdx2_file.license_concluded, extracted_licensing_info
41-
)
4236
copyright_text = None
4337
if isinstance(spdx2_file.copyright_text, str):
4438
copyright_text = spdx2_file.copyright_text
@@ -53,11 +47,9 @@ def bump_file(
5347
payload.add_element(
5448
File(
5549
spdx_id,
56-
creation_info=creation_info,
5750
name=spdx2_file.name,
5851
comment=spdx2_file.comment,
5952
verified_using=integrity_methods,
60-
concluded_license=license_concluded,
6153
copyright_text=copyright_text,
6254
attribution_text=", ".join(spdx2_file.attribution_texts),
6355
)

src/spdx_tools/spdx3/bump_from_spdx2/package.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from spdx_tools.spdx3.bump_from_spdx2.actor import bump_actor
77
from spdx_tools.spdx3.bump_from_spdx2.bump_utils import handle_no_assertion_or_none
88
from spdx_tools.spdx3.bump_from_spdx2.checksum import bump_checksum
9-
from spdx_tools.spdx3.bump_from_spdx2.license_expression import bump_license_expression_or_none_or_no_assertion
109
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
1110
from spdx_tools.spdx3.model import (
12-
CreationInfo,
1311
ExternalIdentifier,
1412
ExternalIdentifierType,
1513
ExternalMap,
@@ -19,7 +17,7 @@
1917
from spdx_tools.spdx3.model.software import Package, SoftwarePurpose
2018
from spdx_tools.spdx3.payload import Payload
2119
from spdx_tools.spdx.model import Actor as Spdx2_Actor
22-
from spdx_tools.spdx.model import ExternalDocumentRef, ExtractedLicensingInfo, SpdxNoAssertion
20+
from spdx_tools.spdx.model import ExternalDocumentRef, SpdxNoAssertion
2321
from spdx_tools.spdx.model.package import ExternalPackageRef
2422
from spdx_tools.spdx.model.package import Package as Spdx2_Package
2523
from spdx_tools.spdx.spdx_element_utils import get_full_element_spdx_id
@@ -28,9 +26,7 @@
2826
def bump_package(
2927
spdx2_package: Spdx2_Package,
3028
payload: Payload,
31-
creation_info: CreationInfo,
3229
document_namespace: str,
33-
extracted_licensing_info: List[ExtractedLicensingInfo],
3430
external_document_refs: List[ExternalDocumentRef],
3531
imports: List[ExternalMap],
3632
):
@@ -46,24 +42,18 @@ def bump_package(
4642
download_location = handle_no_assertion_or_none(spdx2_package.download_location, "package.download_location")
4743
print_missing_conversion("package2.file_name", 0, "https://github.com/spdx/spdx-3-model/issues/83")
4844
if isinstance(spdx2_package.supplier, Spdx2_Actor):
49-
supplied_by_spdx_id = [bump_actor(spdx2_package.supplier, payload, creation_info, document_namespace)]
45+
supplied_by_spdx_id = [bump_actor(spdx2_package.supplier, payload, document_namespace)]
5046
else:
5147
supplied_by_spdx_id = None
5248
if isinstance(spdx2_package.originator, Spdx2_Actor):
53-
originated_by_spdx_id = [bump_actor(spdx2_package.originator, payload, creation_info, document_namespace)]
49+
originated_by_spdx_id = [bump_actor(spdx2_package.originator, payload, document_namespace)]
5450
else:
5551
originated_by_spdx_id = None
5652
print_missing_conversion("package2.files_analyzed", 0, "https://github.com/spdx/spdx-3-model/issues/84")
5753
print_missing_conversion(
5854
"package2.verification_code", 1, "of IntegrityMethod, https://github.com/spdx/spdx-3-model/issues/85"
5955
)
6056
integrity_methods = [bump_checksum(checksum) for checksum in spdx2_package.checksums]
61-
declared_license = bump_license_expression_or_none_or_no_assertion(
62-
spdx2_package.license_declared, extracted_licensing_info
63-
)
64-
concluded_license = bump_license_expression_or_none_or_no_assertion(
65-
spdx2_package.license_concluded, extracted_licensing_info
66-
)
6757
copyright_text = None
6858
if isinstance(spdx2_package.copyright_text, str):
6959
copyright_text = spdx2_package.copyright_text
@@ -99,7 +89,6 @@ def bump_package(
9989
Package(
10090
spdx_id,
10191
spdx2_package.name,
102-
creation_info=creation_info,
10392
summary=spdx2_package.summary,
10493
description=spdx2_package.description,
10594
comment=spdx2_package.comment,
@@ -119,8 +108,6 @@ def bump_package(
119108
source_info=spdx2_package.source_info,
120109
copyright_text=copyright_text,
121110
attribution_text=", ".join(spdx2_package.attribution_texts),
122-
concluded_license=concluded_license,
123-
declared_license=declared_license,
124111
)
125112
)
126113

src/spdx_tools/spdx3/bump_from_spdx2/relationship.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
from beartype.typing import Dict, List, Optional, Tuple, Union
88

99
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
10-
from spdx_tools.spdx3.model import (
11-
CreationInfo,
12-
LifecycleScopeType,
13-
Relationship,
14-
RelationshipCompleteness,
15-
RelationshipType,
16-
)
10+
from spdx_tools.spdx3.model import LifecycleScopeType, Relationship, RelationshipCompleteness, RelationshipType
1711
from spdx_tools.spdx3.model.software import (
1812
DependencyConditionalityType,
1913
SoftwareDependencyLinkType,
@@ -158,12 +152,11 @@
158152
def bump_relationships(
159153
spdx2_relationships: List[Spdx2_Relationship],
160154
payload: Payload,
161-
creation_info: CreationInfo,
162155
document_namespace: str,
163156
):
164157
generated_relationships: Dict[Tuple[str, str], List[Relationship]] = {}
165158
for counter, spdx2_relationship in enumerate(spdx2_relationships):
166-
relationship = bump_relationship(spdx2_relationship, creation_info, document_namespace, counter)
159+
relationship = bump_relationship(spdx2_relationship, document_namespace, counter)
167160
if relationship:
168161
generated_relationships.setdefault(
169162
(relationship.from_element, relationship.relationship_type.name), []
@@ -178,7 +171,6 @@ def bump_relationships(
178171

179172
def bump_relationship(
180173
spdx2_relationship: Spdx2_Relationship,
181-
creation_info: CreationInfo,
182174
document_namespace: str,
183175
counter: int,
184176
) -> Optional[Union[Relationship, SoftwareDependencyRelationship]]:
@@ -208,7 +200,6 @@ def bump_relationship(
208200
f"{document_namespace}#{from_element}",
209201
relationship_type,
210202
[f"{document_namespace}#{t}" for t in to],
211-
creation_info=creation_info,
212203
comment=spdx2_relationship.comment,
213204
completeness=completeness,
214205
scope=parameters.get("scope"),
@@ -221,7 +212,6 @@ def bump_relationship(
221212
f"{document_namespace}#{from_element}",
222213
relationship_type,
223214
[f"{document_namespace}#{t}" for t in to],
224-
creation_info=creation_info,
225215
comment=spdx2_relationship.comment,
226216
completeness=completeness,
227217
)

src/spdx_tools/spdx3/bump_from_spdx2/snippet.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
# SPDX-License-Identifier: Apache-2.0
44
from beartype.typing import List, Optional, Tuple
55

6-
from spdx_tools.spdx3.bump_from_spdx2.license_expression import bump_license_expression_or_none_or_no_assertion
76
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
8-
from spdx_tools.spdx3.model import CreationInfo, ExternalMap
7+
from spdx_tools.spdx3.model import ExternalMap
98
from spdx_tools.spdx3.model.positive_integer_range import PositiveIntegerRange
109
from spdx_tools.spdx3.model.software import Snippet
1110
from spdx_tools.spdx3.payload import Payload
12-
from spdx_tools.spdx.model import ExternalDocumentRef, ExtractedLicensingInfo, SpdxNoAssertion
11+
from spdx_tools.spdx.model import ExternalDocumentRef, SpdxNoAssertion
1312
from spdx_tools.spdx.model.snippet import Snippet as Spdx2_Snippet
1413
from spdx_tools.spdx.spdx_element_utils import get_full_element_spdx_id
1514

@@ -21,9 +20,7 @@ def bump_integer_range(spdx2_range: Optional[Tuple[int, int]]) -> PositiveIntege
2120
def bump_snippet(
2221
spdx2_snippet: Spdx2_Snippet,
2322
payload: Payload,
24-
creation_info: CreationInfo,
2523
document_namespace: str,
26-
extracted_licensing_info: List[ExtractedLicensingInfo],
2724
external_document_refs: List[ExternalDocumentRef],
2825
imports: List[ExternalMap],
2926
):
@@ -37,9 +34,6 @@ def bump_snippet(
3734
)
3835

3936
print_missing_conversion("snippet.file_spdx_id", 0, "https://github.com/spdx/spdx-3-model/issues/130")
40-
concluded_license = bump_license_expression_or_none_or_no_assertion(
41-
spdx2_snippet.license_concluded, extracted_licensing_info
42-
)
4337
copyright_text = None
4438
if isinstance(spdx2_snippet.copyright_text, str):
4539
copyright_text = spdx2_snippet.copyright_text
@@ -54,13 +48,11 @@ def bump_snippet(
5448
payload.add_element(
5549
Snippet(
5650
spdx_id=spdx_id,
57-
creation_info=creation_info,
5851
name=spdx2_snippet.name,
5952
comment=spdx2_snippet.comment,
6053
byte_range=bump_integer_range(spdx2_snippet.byte_range),
6154
line_range=bump_integer_range(spdx2_snippet.line_range),
6255
copyright_text=copyright_text,
6356
attribution_text=", ".join(spdx2_snippet.attribution_texts),
64-
concluded_license=concluded_license,
6557
)
6658
)

src/spdx_tools/spdx3/bump_from_spdx2/spdx_document.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def bump_spdx_document(document: Spdx2_Document) -> Payload:
3737
bump_package(
3838
spdx2_package,
3939
payload,
40-
creation_info,
4140
document_namespace,
42-
document.extracted_licensing_info,
4341
document.creation_info.external_document_refs,
4442
spdx_document.imports,
4543
)
@@ -48,9 +46,7 @@ def bump_spdx_document(document: Spdx2_Document) -> Payload:
4846
bump_file(
4947
spdx2_file,
5048
payload,
51-
creation_info,
5249
document_namespace,
53-
document.extracted_licensing_info,
5450
document.creation_info.external_document_refs,
5551
spdx_document.imports,
5652
)
@@ -59,14 +55,12 @@ def bump_spdx_document(document: Spdx2_Document) -> Payload:
5955
bump_snippet(
6056
spdx2_snippet,
6157
payload,
62-
creation_info,
6358
document_namespace,
64-
document.extracted_licensing_info,
6559
document.creation_info.external_document_refs,
6660
spdx_document.imports,
6761
)
6862

69-
bump_relationships(document.relationships, payload, creation_info, document_namespace)
63+
bump_relationships(document.relationships, payload, document_namespace)
7064

7165
for counter, spdx2_annotation in enumerate(document.annotations):
7266
bump_annotation(spdx2_annotation, payload, creation_info, document_namespace, counter)

tests/spdx3/bump/test_actor_bump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_bump_actor(actor_type, actor_name, actor_mail, element_type, new_spdx_i
4040
creation_info = CreationInfo(Version("3.0.0"), datetime(2022, 1, 1), ["Creator"], [], [ProfileIdentifier.CORE])
4141
actor = Actor(actor_type, actor_name, actor_mail)
4242

43-
agent_or_tool_id = bump_actor(actor, payload, creation_info, document_namespace)
43+
agent_or_tool_id = bump_actor(actor, payload, document_namespace, creation_info)
4444
agent_or_tool = payload.get_element(agent_or_tool_id)
4545

4646
assert isinstance(agent_or_tool, element_type)
@@ -68,7 +68,7 @@ def test_bump_actor_that_already_exists():
6868
)
6969

7070
actor = Actor(ActorType.PERSON, name, "some@mail.com")
71-
agent_spdx_id = bump_actor(actor, payload, creation_info_new, document_namespace)
71+
agent_spdx_id = bump_actor(actor, payload, document_namespace, creation_info_new)
7272

7373
# assert that there is only one Person in the payload
7474
assert (

tests/spdx3/bump/test_file_bump.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
# SPDX-FileCopyrightText: 2023 spdx contributors
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from unittest import mock
54

65
from spdx_tools.spdx3.bump_from_spdx2.file import bump_file
76
from spdx_tools.spdx3.model import Hash, HashAlgorithm
8-
from spdx_tools.spdx3.model.licensing import ConjunctiveLicenseSet, ListedLicense
97
from spdx_tools.spdx3.model.software import File
108
from spdx_tools.spdx3.payload import Payload
119
from spdx_tools.spdx.model.file import File as Spdx2_File
1210
from tests.spdx.fixtures import file_fixture
1311

1412

15-
@mock.patch("spdx_tools.spdx3.model.CreationInfo", autospec=True)
16-
def test_bump_file(creation_info):
13+
def test_bump_file():
1714
payload = Payload()
1815
document_namespace = "https://doc.namespace"
1916
spdx2_file: Spdx2_File = file_fixture()
2017
integrity_method: Hash = Hash(HashAlgorithm.SHA1, "71c4025dd9897b364f3ebbb42c484ff43d00791c")
2118
expected_new_file_id = f"{document_namespace}#{spdx2_file.spdx_id}"
2219

23-
bump_file(spdx2_file, payload, creation_info, document_namespace, [], [], [])
20+
bump_file(spdx2_file, payload, document_namespace, [], [])
2421
file = payload.get_element(expected_new_file_id)
2522

2623
assert isinstance(file, File)
2724
assert file.spdx_id == expected_new_file_id
2825
assert file.verified_using == [integrity_method]
29-
assert file.concluded_license == ConjunctiveLicenseSet(
30-
[ListedLicense("MIT", "MIT", "blank"), ListedLicense("GPL-2.0-only", "GPL-2.0-only", "blank")]
31-
)
3226
assert file.copyright_text == spdx2_file.copyright_text
3327
assert file.attribution_text == spdx2_file.attribution_texts[0]

0 commit comments

Comments
 (0)