Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spdx3.model to SPDX v3.0.1 #829

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ pip-log.txt
.coverage.*
nosetests.xml
htmlcov
dummy_path
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.8.x (not yet released)

* spdx3: Update model to v3.0.1

## v0.8.3 (2024-09-27)

### New features and changes
Expand Down
2 changes: 2 additions & 0 deletions src/spdx_tools/spdx3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 The SPDX Contributors
42 changes: 42 additions & 0 deletions src/spdx_tools/spdx3/bump_from_spdx2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2024 The SPDX Contributors

from .actor import bump_actor
from .annotation import bump_annotation
from .bump_utils import handle_no_assertion_or_none
from .checksum import bump_checksum, convert_checksum_algorithm_to_hash_algorithm
from .creation_info import bump_creation_info
from .external_document_ref import bump_external_document_ref
from .file import bump_file
from .license_expression import (
bump_license_exception,
bump_license_expression,
bump_license_expression_or_none_or_no_assertion,
)
from .message import print_missing_conversion
from .package import bump_package
from .positive_integer_range import bump_positive_integer_range
from .relationship import bump_relationship, bump_relationships
from .snippet import bump_snippet
from .spdx_document import bump_spdx_document

__all__ = [
"convert_checksum_algorithm_to_hash_algorithm",
"bump_actor",
"bump_annotation",
"bump_checksum",
"bump_creation_info",
"bump_external_document_ref",
"bump_file",
"bump_license_exception",
"bump_license_expression",
"bump_license_expression_or_none_or_no_assertion",
"bump_package",
"bump_positive_integer_range",
"bump_relationship",
"bump_relationships",
"bump_snippet",
"bump_spdx_document",
"handle_no_assertion_or_none",
"print_missing_conversion",
]
18 changes: 13 additions & 5 deletions src/spdx_tools/spdx3/bump_from_spdx2/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@

from beartype.typing import List

from spdx_tools.spdx3.model import CreationInfo, ExternalIdentifier, ExternalIdentifierType, Organization, Person, Tool
from spdx_tools.spdx3.payload import Payload
from spdx_tools.spdx.model.actor import Actor as Spdx2_Actor
from spdx_tools.spdx.model.actor import ActorType
from spdx_tools.spdx3.model.core import (
CreationInfo,
ExternalIdentifier,
ExternalIdentifierType,
Organization,
Person,
Tool,
)
from spdx_tools.spdx3.payload import Payload


def bump_actor(
spdx2_actor: Spdx2_Actor, payload: Payload, document_namespace: str, creation_info: Optional[CreationInfo] = None
) -> str:
spdx_id: str
name: str = spdx2_actor.name
email: str = spdx2_actor.email
email: str = spdx2_actor.email if spdx2_actor.email is not None else ""
actor_type: ActorType = spdx2_actor.actor_type

external_identifiers: List[ExternalIdentifier] = []
name_without_whitespace = "".join(name.split())
if email:
external_identifiers.append(ExternalIdentifier(ExternalIdentifierType.EMAIL, email))
spdx_id: str = f"{document_namespace}#SPDXRef-Actor-{name_without_whitespace}-{email}"
spdx_id = f"{document_namespace}#SPDXRef-Actor-{name_without_whitespace}-{email}"
else:
spdx_id: str = f"{document_namespace}#SPDXRef-Actor-{name_without_whitespace}"
spdx_id = f"{document_namespace}#SPDXRef-Actor-{name_without_whitespace}"

if spdx_id in payload.get_full_map(): # the agent/tool already exists, so we don't need to create a new one
return spdx_id
Expand Down
6 changes: 3 additions & 3 deletions src/spdx_tools/spdx3/bump_from_spdx2/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# SPDX-License-Identifier: Apache-2.0
from copy import deepcopy

from spdx_tools.spdx.model.actor import ActorType
from spdx_tools.spdx.model.annotation import Annotation as Spdx2_Annotation
from spdx_tools.spdx3.bump_from_spdx2.actor import bump_actor
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
from spdx_tools.spdx3.model import Annotation, AnnotationType, CreationInfo
from spdx_tools.spdx3.model.core import Annotation, AnnotationType, CreationInfo
from spdx_tools.spdx3.payload import Payload
from spdx_tools.spdx.model.actor import ActorType
from spdx_tools.spdx.model.annotation import Annotation as Spdx2_Annotation


def bump_annotation(
Expand Down
2 changes: 2 additions & 0 deletions src/spdx_tools/spdx3/bump_from_spdx2/bump_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ def handle_no_assertion_or_none(field: Union[SpdxNone, SpdxNoAssertion, str], fi
return None
if isinstance(field, str):
return field

return None
4 changes: 1 addition & 3 deletions src/spdx_tools/spdx3/bump_from_spdx2/checksum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: 2023 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0
from spdx_tools.spdx3.model import Hash, HashAlgorithm
from spdx_tools.spdx.model.checksum import Checksum as Spdx2_Checksum
from spdx_tools.spdx.model.checksum import ChecksumAlgorithm
from spdx_tools.spdx3.model.core import Hash, HashAlgorithm


def bump_checksum(spdx2_checksum: Spdx2_Checksum) -> Hash:
Expand All @@ -16,6 +16,4 @@ def bump_checksum(spdx2_checksum: Spdx2_Checksum) -> Hash:
def convert_checksum_algorithm_to_hash_algorithm(checksum_algorithm: ChecksumAlgorithm) -> HashAlgorithm:
if checksum_algorithm.name.startswith("BLAKE"):
return HashAlgorithm[checksum_algorithm.name.replace("_", "")]
if checksum_algorithm == ChecksumAlgorithm.ADLER32:
return HashAlgorithm.OTHER
return HashAlgorithm[checksum_algorithm.name]
20 changes: 12 additions & 8 deletions src/spdx_tools/spdx3/bump_from_spdx2/creation_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
from beartype.typing import List
from semantic_version import Version

from spdx_tools.spdx.model.actor import ActorType
from spdx_tools.spdx.model.document import CreationInfo as Spdx2_CreationInfo
from spdx_tools.spdx3.bump_from_spdx2.actor import bump_actor
from spdx_tools.spdx3.bump_from_spdx2.external_document_ref import bump_external_document_ref
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
from spdx_tools.spdx3.model import CreationInfo, ProfileIdentifierType, SpdxDocument
from spdx_tools.spdx3.model.core import (
CreationInfo,
ProfileIdentifierType,
SpdxDocument,
)
from spdx_tools.spdx3.payload import Payload
from spdx_tools.spdx.model.actor import ActorType
from spdx_tools.spdx.model.document import CreationInfo as Spdx2_CreationInfo


def bump_creation_info(spdx2_creation_info: Spdx2_CreationInfo, payload: Payload) -> SpdxDocument:
Expand All @@ -29,15 +33,15 @@ def bump_creation_info(spdx2_creation_info: Spdx2_CreationInfo, payload: Payload
if spdx2_creation_info.external_document_refs
else ([], [])
)
namespaces = list(namespaces)
imports = list(imports)
namespaces = list(namespaces) # namespaces from spdx2
imports = list(imports) # imports from spdx2
print_missing_conversion(
"creation_info.license_list_version",
0,
"part of licensing profile, " "https://github.com/spdx/spdx-3-model/issues/131",
)
creation_info = CreationInfo(
spec_version=Version("3.0.0"),
spec_version=Version(major=3, minor=0, patch=1),
created=spdx2_creation_info.created,
created_by=[],
profile=[ProfileIdentifierType.CORE, ProfileIdentifierType.SOFTWARE, ProfileIdentifierType.LICENSING],
Expand Down Expand Up @@ -74,6 +78,6 @@ def bump_creation_info(spdx2_creation_info: Spdx2_CreationInfo, payload: Payload
comment=spdx2_creation_info.document_comment,
element=[],
root_element=[],
imports=imports,
namespaces=namespaces,
import_=imports,
namespace=namespaces,
)
4 changes: 2 additions & 2 deletions src/spdx_tools/spdx3/bump_from_spdx2/external_document_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
from beartype.typing import List, Tuple

from spdx_tools.spdx3.bump_from_spdx2.checksum import bump_checksum
from spdx_tools.spdx3.model import ExternalMap, Hash, NamespaceMap
from spdx_tools.spdx.model.external_document_ref import ExternalDocumentRef
from spdx_tools.spdx3.bump_from_spdx2.checksum import bump_checksum
from spdx_tools.spdx3.model.core import ExternalMap, Hash, NamespaceMap


def bump_external_document_ref(external_document_ref: ExternalDocumentRef) -> Tuple[NamespaceMap, ExternalMap]:
Expand Down
12 changes: 6 additions & 6 deletions src/spdx_tools/spdx3/bump_from_spdx2/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# SPDX-License-Identifier: Apache-2.0
from beartype.typing import List

from spdx_tools.spdx.model import ExternalDocumentRef, SpdxNoAssertion
from spdx_tools.spdx.model.file import File as Spdx2_File
from spdx_tools.spdx.spdx_element_utils import get_full_element_spdx_id
from spdx_tools.spdx3.bump_from_spdx2.checksum import bump_checksum
from spdx_tools.spdx3.bump_from_spdx2.message import print_missing_conversion
from spdx_tools.spdx3.model import ExternalMap
from spdx_tools.spdx3.model.core import ExternalMap
from spdx_tools.spdx3.model.software import File
from spdx_tools.spdx3.payload import Payload
from spdx_tools.spdx.model import ExternalDocumentRef, SpdxNoAssertion
from spdx_tools.spdx.model.file import File as Spdx2_File
from spdx_tools.spdx.spdx_element_utils import get_full_element_spdx_id


def bump_file(
spdx2_file: Spdx2_File,
payload: Payload,
document_namespace: str,
external_document_refs: List[ExternalDocumentRef],
imports: List[ExternalMap],
import_: List[ExternalMap],
):
spdx_id = get_full_element_spdx_id(spdx2_file, document_namespace, external_document_refs)
if ":" in spdx2_file.spdx_id:
imports.append(
import_.append(
ExternalMap(
external_id=spdx2_file.spdx_id,
defining_document=f"{spdx2_file.spdx_id.split(':')[0]}:SPDXRef-DOCUMENT",
Expand Down
2 changes: 1 addition & 1 deletion src/spdx_tools/spdx3/bump_from_spdx2/license_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from license_expression import AND, OR, LicenseExpression, LicenseSymbol, LicenseWithExceptionSymbol

from spdx_tools.common.spdx_licensing import spdx_licensing
from spdx_tools.spdx.model import ExtractedLicensingInfo, SpdxNoAssertion, SpdxNone
from spdx_tools.spdx3.model.licensing import (
AnyLicenseInfo,
ConjunctiveLicenseSet,
Expand All @@ -20,7 +21,6 @@
NoneLicense,
WithAdditionOperator,
)
from spdx_tools.spdx.model import ExtractedLicensingInfo, SpdxNoAssertion, SpdxNone


def bump_license_expression_or_none_or_no_assertion(
Expand Down
Loading