Skip to content

Commit a2dbe72

Browse files
authored
Merge pull request #606 from carmenbianca/deprecated-download
Support deprecated licenses for download
2 parents daa04d1 + 0b19360 commit a2dbe72

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Support deprecated licences for `reuse download`. (#606)

src/reuse/cli/download.py

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

1616
import click
1717

18-
from .._licenses import ALL_NON_DEPRECATED_MAP
18+
from .._licenses import ALL_MAP, ALL_NON_DEPRECATED_MAP
1919
from .._util import _strip_plus_from_identifier
2020
from ..download import _path_to_license_file, put_license_in_file
2121
from ..i18n import _
@@ -30,9 +30,6 @@
3030
def _similar_spdx_identifiers(identifier: str) -> list[str]:
3131
"""Given an incorrect SPDX identifier, return a list of similar ones."""
3232
suggestions: list[str] = []
33-
if identifier in ALL_NON_DEPRECATED_MAP:
34-
return suggestions
35-
3633
for valid_identifier in ALL_NON_DEPRECATED_MAP:
3734
distance = SequenceMatcher(
3835
a=identifier.lower(), b=valid_identifier[: len(identifier)].lower()
@@ -87,7 +84,7 @@ def _not_found(path: StrPath) -> None:
8784
def _could_not_download(identifier: str) -> None:
8885
click.echo(_("Error: Failed to download license."))
8986
click.echo("")
90-
if identifier not in ALL_NON_DEPRECATED_MAP:
87+
if identifier not in ALL_MAP:
9188
_print_incorrect_spdx_identifier(identifier, out=sys.stdout)
9289
else:
9390
click.echo(_("Is your internet connection working?"))

src/reuse/download.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from urllib.error import URLError
1515
from urllib.parse import urljoin
1616

17+
from ._licenses import ALL_NON_DEPRECATED_MAP
1718
from ._util import find_licenses_directory
1819
from .extract import _LICENSEREF_PATTERN
1920
from .project import Project
@@ -40,6 +41,8 @@ def download_license(spdx_identifier: str) -> str:
4041
Returns:
4142
The license text.
4243
"""
44+
if spdx_identifier not in ALL_NON_DEPRECATED_MAP:
45+
spdx_identifier = f"deprecated_{spdx_identifier}"
4346
# This is fairly naive, but I can't see anything wrong with it.
4447
url = urljoin(_SPDX_REPOSITORY_BASE_URL, "".join((spdx_identifier, ".txt")))
4548
_LOGGER.debug("downloading license from '%s'", url)

tests/test_download.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import urllib.request
88
from pathlib import Path
9+
from unittest.mock import MagicMock
910
from urllib.error import URLError
1011

1112
import pytest
@@ -62,6 +63,14 @@ def raise_exception(_):
6263
download_license("hello world")
6364

6465

66+
def test_download_deprecated(monkeypatch):
67+
"""Adjust the requested file for deprecated licenses."""
68+
mocked = MagicMock(return_value=MockResponse("hello", 200))
69+
monkeypatch.setattr(urllib.request, "urlopen", mocked)
70+
download_license("GPL-3.0")
71+
assert "deprecated_GPL-3.0" in mocked.call_args[0][0]
72+
73+
6574
def test_put_simple(fake_repository, monkeypatch):
6675
"""Straightforward test."""
6776
monkeypatch.setattr(

0 commit comments

Comments
 (0)