Skip to content

Commit 590bbfa

Browse files
[issue-806] replace Licensing() with spdx_licensing
Signed-off-by: Armin Tänzer <[email protected]>
1 parent 552940a commit 590bbfa

File tree

10 files changed

+42
-37
lines changed

10 files changed

+42
-37
lines changed

src/spdx_tools/spdx/parser/jsonlikedict/license_expression_parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
from beartype.typing import Union
5-
from license_expression import ExpressionError, LicenseExpression, Licensing
5+
from license_expression import ExpressionError, LicenseExpression
66

7+
from spdx_tools.common.spdx_licensing import spdx_licensing
78
from spdx_tools.spdx.model import SpdxNoAssertion, SpdxNone
89
from spdx_tools.spdx.parser.error import SPDXParsingError
910

@@ -18,7 +19,7 @@ def parse_license_expression(license_expression_str: str) -> Union[LicenseExpres
1819
return SpdxNone()
1920

2021
try:
21-
license_expression = Licensing().parse(license_expression_str)
22+
license_expression = spdx_licensing.parse(license_expression_str)
2223
except ExpressionError as err:
2324
err_msg = f'Error parsing LicenseExpression: "{license_expression_str}"'
2425
if err.args:

tests/spdx/jsonschema/test_file_converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from unittest.mock import MagicMock, NonCallableMagicMock
88

99
import pytest
10-
from license_expression import Licensing
1110

11+
from spdx_tools.common.spdx_licensing import spdx_licensing
1212
from spdx_tools.spdx.jsonschema.annotation_converter import AnnotationConverter
1313
from spdx_tools.spdx.jsonschema.file_converter import FileConverter
1414
from spdx_tools.spdx.jsonschema.file_properties import FileProperty
@@ -81,8 +81,8 @@ def test_successful_conversion(converter: FileConverter):
8181
spdx_id="spdxId",
8282
checksums=[Checksum(ChecksumAlgorithm.SHA224, "sha224"), Checksum(ChecksumAlgorithm.MD2, "md2")],
8383
file_types=[FileType.SPDX, FileType.OTHER],
84-
license_concluded=Licensing().parse("MIT and GPL-2.0"),
85-
license_info_in_file=[Licensing().parse("MIT"), Licensing().parse("GPL-2.0"), SpdxNoAssertion()],
84+
license_concluded=spdx_licensing.parse("MIT and GPL-2.0"),
85+
license_info_in_file=[spdx_licensing.parse("MIT"), spdx_licensing.parse("GPL-2.0"), SpdxNoAssertion()],
8686
license_comment="licenseComment",
8787
copyright_text="copyrightText",
8888
comment="comment",
@@ -115,8 +115,8 @@ def test_successful_conversion(converter: FileConverter):
115115
converter.json_property_name(FileProperty.FILE_NAME): "name",
116116
converter.json_property_name(FileProperty.FILE_TYPES): ["SPDX", "OTHER"],
117117
converter.json_property_name(FileProperty.LICENSE_COMMENTS): "licenseComment",
118-
converter.json_property_name(FileProperty.LICENSE_CONCLUDED): "MIT AND GPL-2.0",
119-
converter.json_property_name(FileProperty.LICENSE_INFO_IN_FILES): ["MIT", "GPL-2.0", "NOASSERTION"],
118+
converter.json_property_name(FileProperty.LICENSE_CONCLUDED): "MIT AND GPL-2.0-only",
119+
converter.json_property_name(FileProperty.LICENSE_INFO_IN_FILES): ["MIT", "GPL-2.0-only", "NOASSERTION"],
120120
converter.json_property_name(FileProperty.NOTICE_TEXT): "notice",
121121
}
122122

tests/spdx/jsonschema/test_package_converter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from unittest.mock import MagicMock, NonCallableMagicMock
88

99
import pytest
10-
from license_expression import Licensing
1110

11+
from spdx_tools.common.spdx_licensing import spdx_licensing
1212
from spdx_tools.spdx.jsonschema.annotation_converter import AnnotationConverter
1313
from spdx_tools.spdx.jsonschema.package_converter import PackageConverter
1414
from spdx_tools.spdx.jsonschema.package_properties import PackageProperty
@@ -123,9 +123,9 @@ def test_successful_conversion(converter: PackageConverter):
123123
checksums=[Checksum(ChecksumAlgorithm.SHA1, "sha1"), Checksum(ChecksumAlgorithm.BLAKE2B_256, "blake")],
124124
homepage="homepage",
125125
source_info="sourceInfo",
126-
license_concluded=Licensing().parse("MIT and GPL-2.0"),
127-
license_info_from_files=[Licensing().parse("MIT"), Licensing().parse("GPL-2.0")],
128-
license_declared=Licensing().parse("MIT or GPL-2.0 "),
126+
license_concluded=spdx_licensing.parse("MIT and GPL-2.0"),
127+
license_info_from_files=[spdx_licensing.parse("MIT"), spdx_licensing.parse("GPL-2.0")],
128+
license_declared=spdx_licensing.parse("MIT or GPL-2.0 "),
129129
license_comment="licenseComment",
130130
copyright_text="copyrightText",
131131
summary="summary",
@@ -168,9 +168,9 @@ def test_successful_conversion(converter: PackageConverter):
168168
],
169169
converter.json_property_name(PackageProperty.HOMEPAGE): "homepage",
170170
converter.json_property_name(PackageProperty.SOURCE_INFO): "sourceInfo",
171-
converter.json_property_name(PackageProperty.LICENSE_CONCLUDED): "MIT AND GPL-2.0",
172-
converter.json_property_name(PackageProperty.LICENSE_INFO_FROM_FILES): ["MIT", "GPL-2.0"],
173-
converter.json_property_name(PackageProperty.LICENSE_DECLARED): "MIT OR GPL-2.0",
171+
converter.json_property_name(PackageProperty.LICENSE_CONCLUDED): "MIT AND GPL-2.0-only",
172+
converter.json_property_name(PackageProperty.LICENSE_INFO_FROM_FILES): ["MIT", "GPL-2.0-only"],
173+
converter.json_property_name(PackageProperty.LICENSE_DECLARED): "MIT OR GPL-2.0-only",
174174
converter.json_property_name(PackageProperty.LICENSE_COMMENTS): "licenseComment",
175175
converter.json_property_name(PackageProperty.COPYRIGHT_TEXT): "copyrightText",
176176
converter.json_property_name(PackageProperty.SUMMARY): "summary",

tests/spdx/jsonschema/test_snippet_converter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from unittest.mock import MagicMock, NonCallableMagicMock
88

99
import pytest
10-
from license_expression import Licensing
1110

11+
from spdx_tools.common.spdx_licensing import spdx_licensing
1212
from spdx_tools.spdx.jsonschema.annotation_converter import AnnotationConverter
1313
from spdx_tools.spdx.jsonschema.snippet_converter import SnippetConverter
1414
from spdx_tools.spdx.jsonschema.snippet_properties import SnippetProperty
@@ -72,8 +72,8 @@ def test_successful_conversion(converter: SnippetConverter):
7272
file_spdx_id=file_spdx_id,
7373
byte_range=(1, 2),
7474
line_range=(3, 4),
75-
license_concluded=Licensing().parse("MIT and GPL-2.0"),
76-
license_info_in_snippet=[Licensing().parse("MIT"), Licensing().parse("GPL-2.0")],
75+
license_concluded=spdx_licensing.parse("MIT and GPL-2.0"),
76+
license_info_in_snippet=[spdx_licensing.parse("MIT"), spdx_licensing.parse("GPL-2.0")],
7777
license_comment="licenseComment",
7878
copyright_text="copyrightText",
7979
comment="comment",
@@ -98,8 +98,8 @@ def test_successful_conversion(converter: SnippetConverter):
9898
converter.json_property_name(SnippetProperty.COMMENT): "comment",
9999
converter.json_property_name(SnippetProperty.COPYRIGHT_TEXT): "copyrightText",
100100
converter.json_property_name(SnippetProperty.LICENSE_COMMENTS): "licenseComment",
101-
converter.json_property_name(SnippetProperty.LICENSE_CONCLUDED): "MIT AND GPL-2.0",
102-
converter.json_property_name(SnippetProperty.LICENSE_INFO_IN_SNIPPETS): ["MIT", "GPL-2.0"],
101+
converter.json_property_name(SnippetProperty.LICENSE_CONCLUDED): "MIT AND GPL-2.0-only",
102+
converter.json_property_name(SnippetProperty.LICENSE_INFO_IN_SNIPPETS): ["MIT", "GPL-2.0-only"],
103103
converter.json_property_name(SnippetProperty.NAME): "name",
104104
converter.json_property_name(SnippetProperty.RANGES): [
105105
{

tests/spdx/model/test_package.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from unittest import mock
77

88
import pytest
9-
from license_expression import LicenseExpression, Licensing
9+
from license_expression import LicenseExpression
1010

11+
from spdx_tools.common.spdx_licensing import spdx_licensing
1112
from spdx_tools.spdx.model import Checksum, ChecksumAlgorithm, Package, PackagePurpose, SpdxNoAssertion, SpdxNone
1213

1314

@@ -30,7 +31,7 @@ def test_correct_initialization(actor, verif_code, checksum, ext_ref):
3031
"homepage",
3132
"source_info",
3233
None,
33-
[Licensing().parse("license and expression"), SpdxNoAssertion()],
34+
[spdx_licensing.parse("license and expression"), SpdxNoAssertion()],
3435
SpdxNone(),
3536
"comment on license",
3637
"copyright",
@@ -57,7 +58,7 @@ def test_correct_initialization(actor, verif_code, checksum, ext_ref):
5758
assert package.homepage == "homepage"
5859
assert package.source_info == "source_info"
5960
assert package.license_concluded is None
60-
assert package.license_info_from_files == [Licensing().parse("license and expression"), SpdxNoAssertion()]
61+
assert package.license_info_from_files == [spdx_licensing.parse("license and expression"), SpdxNoAssertion()]
6162
assert package.license_declared == SpdxNone()
6263
assert package.license_comment == "comment on license"
6364
assert package.copyright_text == "copyright"

tests/spdx/parser/jsonlikedict/test_file_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from unittest import TestCase
55

66
import pytest
7-
from license_expression import Licensing
87

8+
from spdx_tools.common.spdx_licensing import spdx_licensing
99
from spdx_tools.spdx.model import Checksum, ChecksumAlgorithm, FileType, SpdxNoAssertion, SpdxNone
1010
from spdx_tools.spdx.parser.error import SPDXParsingError
1111
from spdx_tools.spdx.parser.jsonlikedict.dict_parsing_functions import parse_list_of_elements
@@ -82,10 +82,10 @@ def test_parse_file(copyright_text, expected_copyright_text):
8282
"IBM Corporation",
8383
],
8484
)
85-
assert file.license_concluded == Licensing().parse("(LGPL-2.0-only OR LicenseRef-2)")
85+
assert file.license_concluded == spdx_licensing.parse("(LGPL-2.0-only OR LicenseRef-2)")
8686
TestCase().assertCountEqual(
8787
file.license_info_in_file,
88-
[Licensing().parse("GPL-2.0-only"), Licensing().parse("LicenseRef-2"), SpdxNoAssertion()],
88+
[spdx_licensing.parse("GPL-2.0-only"), spdx_licensing.parse("LicenseRef-2"), SpdxNoAssertion()],
8989
)
9090
assert (
9191
file.license_comment == "The concluded license was taken from the package level that the file was included in."

tests/spdx/parser/jsonlikedict/test_license_expression_parser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
[
1717
("First License", spdx_licensing.parse("First License")),
1818
("Second License", spdx_licensing.parse("Second License")),
19+
("Apache-1.1", spdx_licensing.parse("Apache-1.1")),
20+
("Zlib", spdx_licensing.parse("zlib")),
1921
("NOASSERTION", SpdxNoAssertion()),
2022
("NONE", SpdxNone()),
2123
],
@@ -34,7 +36,8 @@ def test_parse_license_expression(license_expression_str, expected_license):
3436
(
3537
"LGPL-2.1, GPL-2.0, GPL-3.0",
3638
[
37-
"Error parsing LicenseExpression: \"LGPL-2.1, GPL-2.0, GPL-3.0\": Invalid license key: the valid characters are: letters and numbers, underscore, dot, colon or hyphen signs and spaces: 'LGPL-2.1, GPL-2.0, GPL-3.0'" # noqa: E501
39+
# the error message we receive from the license_expression library somehow cuts off the last license
40+
"Error parsing LicenseExpression: \"LGPL-2.1, GPL-2.0, GPL-3.0\": Invalid license key: the valid characters are: letters and numbers, underscore, dot, colon or hyphen signs and spaces: 'LGPL-2.1, GPL-2.0,'" # noqa: E501
3841
],
3942
),
4043
("Apache License (2.0)", ['Error parsing LicenseExpression: "Apache License (2.0)"']),

tests/spdx/parser/jsonlikedict/test_package_parser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from unittest import TestCase
66

77
import pytest
8-
from license_expression import Licensing
98

9+
from spdx_tools.common.spdx_licensing import spdx_licensing
1010
from spdx_tools.spdx.model import (
1111
Actor,
1212
ActorType,
@@ -173,17 +173,17 @@ def test_parse_package(
173173
)
174174
assert package.homepage == expected_homepage
175175
assert package.source_info == "uses glibc-2_11-branch from git://sourceware.org/git/glibc.git."
176-
assert package.license_concluded == Licensing().parse("(LGPL-2.0-only OR LicenseRef-3)")
176+
assert package.license_concluded == spdx_licensing.parse("(LGPL-2.0-only OR LicenseRef-3)")
177177
TestCase().assertCountEqual(
178178
package.license_info_from_files,
179179
[
180-
Licensing().parse("GPL-2.0-only"),
181-
Licensing().parse("LicenseRef-2"),
182-
Licensing().parse("LicenseRef-1"),
180+
spdx_licensing.parse("GPL-2.0-only"),
181+
spdx_licensing.parse("LicenseRef-2"),
182+
spdx_licensing.parse("LicenseRef-1"),
183183
SpdxNoAssertion(),
184184
],
185185
)
186-
assert package.license_declared == Licensing().parse("(LGPL-2.0-only AND LicenseRef-3)")
186+
assert package.license_declared == spdx_licensing.parse("(LGPL-2.0-only AND LicenseRef-3)")
187187
assert (
188188
package.license_comment
189189
== "The license for this project changed with the release of version x.y. The version of the project included"

tests/spdx/parser/jsonlikedict/test_snippet_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from unittest import TestCase
55

66
import pytest
7-
from license_expression import Licensing
87

8+
from spdx_tools.common.spdx_licensing import spdx_licensing
99
from spdx_tools.spdx.model import SpdxNoAssertion, SpdxNone
1010
from spdx_tools.spdx.parser.error import SPDXParsingError
1111
from spdx_tools.spdx.parser.jsonlikedict.snippet_parser import SnippetParser
@@ -65,8 +65,8 @@ def test_parse_snippet(copyright_text, expected_copyright_text):
6565
assert snippet.byte_range == (310, 420)
6666
assert snippet.line_range == (5, 23)
6767
assert snippet.file_spdx_id == "SPDXRef-DoapSource"
68-
assert snippet.license_info_in_snippet == [Licensing().parse("GPL-2.0-only"), SpdxNoAssertion()]
69-
assert snippet.license_concluded == Licensing().parse("GPL-2.0-only")
68+
assert snippet.license_info_in_snippet == [spdx_licensing.parse("GPL-2.0-only"), SpdxNoAssertion()]
69+
assert snippet.license_concluded == spdx_licensing.parse("GPL-2.0-only")
7070
assert snippet.attribution_texts == ["Some example attibution text."]
7171

7272

tests/spdx/validation/test_package_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from unittest import TestCase
77

88
import pytest
9-
from license_expression import Licensing
109

10+
from spdx_tools.common.spdx_licensing import spdx_licensing
1111
from spdx_tools.spdx.constants import DOCUMENT_SPDX_ID
1212
from spdx_tools.spdx.model import Relationship, RelationshipType, SpdxNoAssertion, SpdxNone
1313
from spdx_tools.spdx.validation.package_validator import validate_package, validate_package_within_document
@@ -45,7 +45,7 @@ def test_valid_package():
4545
(
4646
package_fixture(
4747
files_analyzed=False,
48-
license_info_from_files=[Licensing().parse("some_license")],
48+
license_info_from_files=[spdx_licensing.parse("some_license")],
4949
verification_code=None,
5050
),
5151
"license_info_from_files must be None if files_analyzed is False, but is: [LicenseSymbol('some_license', "

0 commit comments

Comments
 (0)