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 spdx-tools requirement from <=0.7.1 to <=0.8.2 #65

Merged
merged 7 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"gitpython",
"rospkg",
"scancode-toolkit>=32.0.8",
"spdx-tools<=0.7.1"
"spdx-tools>=0.8.2"
]
requires-python = ">=3.7"

Expand Down
39 changes: 10 additions & 29 deletions src/ros_license_toolkit/license_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,12 @@
from glob import glob
from typing import Any, Dict, List, Optional, Set

from spdx.config import LICENSE_MAP
from license_expression import get_spdx_licensing


def is_license_name_in_spdx_list(license_name: str) -> bool:
"""Check if a license name is in the SPDX list of licenses."""
return license_name in LICENSE_MAP or \
license_name in LICENSE_MAP.values()


def to_spdx_license_tag(license_name: str) -> str:
"""Convert a license name to a SPDX license tag
(assuming it is shorter than the name).
This is because the dict from spdx.config.LICENSE_MAP
contains both pairings (tag, name) and (name, tag).
"""
for tag, name in LICENSE_MAP.items():
if license_name in [tag, name]:
if len(tag) < len(name):
return tag
# else
return name
raise ValueError("License name not in SPDX list.")
return license_name in get_spdx_licensing().known_symbols


def _eval_glob(glob_str: str, pkg_path: str) -> Set[str]:
Expand Down Expand Up @@ -74,17 +58,14 @@ def __init__(self, element: ET.Element,
# be found out through declaration, this field contains the tag
self.id_from_license_text: Optional[str] = None

try:
self.id = to_spdx_license_tag(raw_license_name)
except ValueError:
# If the license name is not in the SPDX list,
# we assume it is a custom license and use the name as-is.
# This will be detected in `LicenseTagIsInSpdxListCheck`.
self.id = raw_license_name
# If a file is linked to the tag, set its id for internal checks
if license_file_scan_results:
self.id_from_license_text = \
get_id_from_license_text(license_file_scan_results)
# If the license name is not in the SPDX list,
# we assume it is a custom license and use the name as-is.
# This will be detected in `LicenseTagIsInSpdxListCheck`.
self.id = raw_license_name
# If a file is linked to the tag, set its id for internal checks
if license_file_scan_results:
self.id_from_license_text = \
get_id_from_license_text(license_file_scan_results)

# Path to the file containing the license text
# (relative to package root)
Expand Down
2 changes: 1 addition & 1 deletion test/_test_data/copyright_file_contents/test_pkg_spdx_name
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Upstream-Name: test_pkg_spdx_name
Files:
**
Copyright: 2003 Lawrence E. Rosen
License: AFL-2.0
License: Academic Free License v2.0
ant-u marked this conversation as resolved.
Show resolved Hide resolved
The Academic Free License
v. 2.0

Expand Down
3 changes: 0 additions & 3 deletions test/unittest/test_license_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ def test_init(self):
by_spdx_tag = LicenseTag(ET.fromstring(
"<license>Apache-2.0</license>"), "")
self.assertEqual(by_spdx_tag.id, "Apache-2.0")
by_spdx_name = LicenseTag(ET.fromstring(
"<license>Apache License 2.0</license>"), "")
self.assertEqual(by_spdx_name.id, "Apache-2.0")


if __name__ == '__main__':
Expand Down
Loading