Skip to content

Commit 97856a8

Browse files
committed
fix case insensitive cmp
1 parent e079e51 commit 97856a8

6 files changed

Lines changed: 29 additions & 15 deletions

File tree

licensecheck/checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ def check(
5454
# Deal with --ignore-packages and --fail-packages
5555
package.licenseCompat = False
5656
packageName = package.name.upper()
57-
if any(fnmatch(packageName, pattern) for pattern in ignore_packages):
57+
if any(fnmatch(packageName, pattern.upper()) for pattern in ignore_packages):
5858
package.licenseCompat = True
59-
elif any(fnmatch(packageName, pattern) for pattern in fail_packages):
59+
elif any(fnmatch(packageName, pattern.upper()) for pattern in fail_packages):
6060
pass # package.licenseCompat = False
6161
# Else get compat with myLice
6262
else:

licensecheck/license_matrix/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import csv
4343
from pathlib import Path
44+
from typing import Any
4445

4546
from loguru import logger
4647

@@ -109,7 +110,7 @@
109110
)
110111

111112

112-
def licenseLookup(licenseStr: str, ignoreLicenses: set[str] | None = None) -> L:
113+
def _licenseLookup(licenseStr: str, ignoreLicenses: set[str] | None = None) -> L:
113114
"""
114115
Identify a license from an uppercase string representation of a license.
115116
@@ -118,22 +119,23 @@ def licenseLookup(licenseStr: str, ignoreLicenses: set[str] | None = None) -> L:
118119
:return L: License represented by licenseStr
119120
"""
120121
licenseStr = licenseStr.upper()
122+
ignoreLicenses_: set[str] = {x.upper() for x in ignoreLicenses or {}}
121123
if len(licenseStr or "") < 1:
122124
return L.NO_LICENSE
123125

124126
for liceStr, lice in termToLicense.items():
125127
if liceStr.strip() in licenseStr:
126128
return lice
127129

128-
if licenseStr not in (ignoreLicenses or ""):
130+
if licenseStr not in (ignoreLicenses_ or ""):
129131
logger.warning(f"'{licenseStr}' License not identified so falling back to UNKNOWN")
130132
return L.UNKNOWN
131133

132134

133135
def _lst_licenseType(lice: str, ignoreLicenses: set[str] | None = None) -> list[L]:
134136
if len(lice or "") < 1:
135137
return [L.NO_LICENSE]
136-
return [licenseLookup(str(x), ignoreLicenses) for x in lice.split(JOINS)]
138+
return [_licenseLookup(str(x), ignoreLicenses) for x in lice.split(JOINS)]
137139

138140

139141
def licenseType(lice: str, ignoreLicenses: set[str] | None = None) -> set[L]:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "licensecheck"
3-
version = "2026.0.2"
3+
version = "2026.0.3"
44
description = "Output the licenses used by dependencies and check if these are compatible with the project license"
55
authors = [{ name = "FredHappyface" }]
66
requires-python = ">=3.12"

tests/io/test_cli_main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

3-
from licensecheck.models.config import LC_Config
43
from licensecheck.io.cli import main
4+
from licensecheck.models.config import LC_Config
55

66

77
@pytest.fixture
@@ -51,7 +51,7 @@ def test_main_success(
5151
def test_main_invalid_format(
5252
config: LC_Config,
5353
monkeypatch,
54-
):
54+
) -> None:
5555
config.format = "does-not-exist"
5656

5757
monkeypatch.setattr(
@@ -106,7 +106,7 @@ def test_main_exit_code_zero_mode(
106106
def test_main_invalid_hidden_parameter(
107107
config: LC_Config,
108108
monkeypatch,
109-
):
109+
) -> None:
110110
config.hide_output_parameters = {"NOT_A_FIELD"}
111111

112112
monkeypatch.setattr(
@@ -133,7 +133,7 @@ def test_main_valid_hidden_parameters(
133133
config: LC_Config,
134134
monkeypatch,
135135
hidden: list[str],
136-
):
136+
) -> None:
137137
config.hide_output_parameters = hidden
138138

139139
monkeypatch.setattr(
@@ -157,7 +157,7 @@ def test_main_valid_hidden_parameters(
157157
def test_main_passes_args_to_checker(
158158
config: LC_Config,
159159
monkeypatch,
160-
):
160+
) -> None:
161161
called = {}
162162

163163
def fake_check(**kwargs):
@@ -190,7 +190,7 @@ def test_main_closes_output_file(
190190
config: LC_Config,
191191
monkeypatch,
192192
tmp_path,
193-
):
193+
) -> None:
194194
output = tmp_path / "out.txt"
195195

196196
config.file = str(output)

tests/test_checker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ def mock_package_info_manager() -> PackageInfoManager:
2626
(None, {"PACKAGE*"}, None, True), # Globs are supported in fail_packages
2727
(None, None, {"GPL-3.0"}, True), # GPL-3.0 should be marked as incompatible
2828
(None, None, {"GPL*"}, False), # Globs are not supported on licenses!
29+
({"package_b"}, None, None, False), # Ignored package should not cause failure
30+
({"package*"}, None, None, False), # Globs are supported in ignore_packages
31+
(None, {"package_a"}, None, True), # PACKAGE_A in fail_packages should fail
32+
(None, {"package*"}, None, True), # Globs are supported in fail_packages
33+
(None, None, {"gpl-3.0"}, True), # GPL-3.0 should be marked as incompatible
34+
(None, None, {"gpl*"}, False), # Globs are not supported on licenses!
2935
],
3036
)
3137
def test_check(

tests/test_license_matrix.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_licenseLookup() -> None:
4343
"""
4444
licenses = []
4545
for rawLicense in Path(f"{THISDIR}/data/rawLicenses.txt").read_text("utf-8").splitlines():
46-
licenseName = license_matrix.licenseLookup(rawLicense)._name_
46+
licenseName = license_matrix._licenseLookup(rawLicense)._name_
4747
licenses.append(licenseName)
4848

4949
licenses.append("NO_LICENSE")
@@ -99,7 +99,7 @@ def test_whitelistedLicenseCompat() -> None:
9999

100100
def test_warningsForIgnoredLicense(caplog: LogCaptureFixture) -> None:
101101
zope = "ZOPE PUBLIC LICENSE"
102-
license_matrix.licenseLookup(zope, set())
102+
license_matrix._licenseLookup(zope, set())
103103
assert any(
104104
record.levelname == "WARNING"
105105
and f"'{zope}' License not identified so falling back to UNKNOWN" in record.message
@@ -109,5 +109,11 @@ def test_warningsForIgnoredLicense(caplog: LogCaptureFixture) -> None:
109109

110110
def test_warningsForIgnoredLicenseIgnored(caplog: LogCaptureFixture) -> None:
111111
zope = "ZOPE PUBLIC LICENSE"
112-
license_matrix.licenseLookup(zope, {zope})
112+
license_matrix._licenseLookup(zope, {zope})
113+
assert caplog.text == ""
114+
115+
116+
def test_warningsForIgnoredLicenseIgnored_lc(caplog: LogCaptureFixture) -> None:
117+
zope = "ZOPE PUBLIC LICENSE"
118+
license_matrix._licenseLookup(zope, {zope.lower()})
113119
assert caplog.text == ""

0 commit comments

Comments
 (0)