File tree Expand file tree Collapse file tree 4 files changed +15
-5
lines changed Expand file tree Collapse file tree 4 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1+ - Support deprecated licences for ` reuse download ` . (#606 )
Original file line number Diff line number Diff line change 1515
1616import click
1717
18- from .._licenses import ALL_NON_DEPRECATED_MAP
18+ from .._licenses import ALL_MAP , ALL_NON_DEPRECATED_MAP
1919from .._util import _strip_plus_from_identifier
2020from ..download import _path_to_license_file , put_license_in_file
2121from ..i18n import _
3030def _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:
8784def _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?" ))
Original file line number Diff line number Diff line change 1414from urllib .error import URLError
1515from urllib .parse import urljoin
1616
17+ from ._licenses import ALL_NON_DEPRECATED_MAP
1718from ._util import find_licenses_directory
1819from .extract import _LICENSEREF_PATTERN
1920from .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 )
Original file line number Diff line number Diff line change 66
77import urllib .request
88from pathlib import Path
9+ from unittest .mock import MagicMock
910from urllib .error import URLError
1011
1112import 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+
6574def test_put_simple (fake_repository , monkeypatch ):
6675 """Straightforward test."""
6776 monkeypatch .setattr (
You can’t perform that action at this time.
0 commit comments