Skip to content

Commit e5dc3c3

Browse files
committedMar 16, 2025
add support for globs
1 parent d31f95c commit e5dc3c3

File tree

6 files changed

+66
-14
lines changed

6 files changed

+66
-14
lines changed
 

‎documentation/reference/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ A full list of `Licensecheck` project modules.
66

77
- [Licensecheck](licensecheck/index.md#licensecheck)
88
- [Module](licensecheck/module.md#module)
9+
- [Checker](licensecheck/checker.md#checker)
910
- [Cli](licensecheck/cli.md#cli)
1011
- [Fmt](licensecheck/fmt.md#fmt)
11-
- [Get Deps](licensecheck/get_deps.md#get-deps)
1212
- [License Matrix](licensecheck/license_matrix/index.md#license-matrix)
1313
- [Spdx](licensecheck/license_matrix/spdx.md#spdx)
1414
- [Packageinfo](licensecheck/packageinfo.md#packageinfo)

‎documentation/reference/licensecheck/get_deps.md ‎documentation/reference/licensecheck/checker.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Get Deps
1+
# Checker
22

3-
[Licensecheck Index](../README.md#licensecheck-index) / [Licensecheck](./index.md#licensecheck) / Get Deps
3+
[Licensecheck Index](../README.md#licensecheck-index) / [Licensecheck](./index.md#licensecheck) / Checker
44

5-
> Auto-generated documentation for [licensecheck.get_deps](../../../licensecheck/get_deps.py) module.
5+
> Auto-generated documentation for [licensecheck.checker](../../../licensecheck/checker.py) module.
66
7-
- [Get Deps](#get-deps)
7+
- [Checker](#checker)
88
- [check](#check)
99
- [resolve_requirements](#resolve_requirements)
1010

1111
## check
1212

13-
[Show source in get_deps.py:42](../../../licensecheck/get_deps.py#L42)
13+
[Show source in checker.py:43](../../../licensecheck/checker.py#L43)
1414

1515
#### Signature
1616

@@ -39,7 +39,7 @@ def check(
3939

4040
## resolve_requirements
4141

42-
[Show source in get_deps.py:16](../../../licensecheck/get_deps.py#L16)
42+
[Show source in checker.py:17](../../../licensecheck/checker.py#L17)
4343

4444
#### Signature
4545

‎documentation/reference/licensecheck/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
## Modules
1111

1212
- [Module](./module.md)
13+
- [Checker](./checker.md)
1314
- [Cli](./cli.md)
1415
- [Fmt](./fmt.md)
15-
- [Get Deps](./get_deps.md)
1616
- [License Matrix](license_matrix/index.md)
1717
- [Packageinfo](./packageinfo.md)
1818
- [Resolvers](resolvers/index.md)

‎licensecheck/get_deps.py ‎licensecheck/checker.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from fnmatch import fnmatch
56
from pathlib import Path
67

78
import tomli
@@ -76,9 +77,9 @@ def check(
7677
# Deal with --ignore-packages and --fail-packages
7778
package.licenseCompat = False
7879
packageName = package.name.upper()
79-
if packageName in ignore_packages:
80+
if any(fnmatch(packageName, pattern) for pattern in ignore_packages):
8081
package.licenseCompat = True
81-
elif packageName in fail_packages:
82+
elif any(fnmatch(packageName, pattern) for pattern in fail_packages):
8283
pass # package.licenseCompat = False
8384
# Else get compat with myLice
8485
else:

‎licensecheck/cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from fhconfparser import FHConfParser, SimpleConf
1414

15-
from licensecheck import fmt, get_deps, license_matrix, packageinfo, types
15+
from licensecheck import checker, fmt, license_matrix, packageinfo, types
1616

1717
stdout.reconfigure(encoding="utf-8") # type: ignore[general-type-issues]
1818

@@ -50,12 +50,12 @@ def cli() -> None: # pragma: no cover
5050
)
5151
parser.add_argument(
5252
"--ignore-packages",
53-
help="List of packages/dependencies to ignore (compat=True)",
53+
help="List of packages/dependencies to ignore (compat=True), globs are supported",
5454
nargs="+",
5555
)
5656
parser.add_argument(
5757
"--fail-packages",
58-
help="List of packages/dependencies to fail (compat=False)",
58+
help="List of packages/dependencies to fail (compat=False), globs are supported",
5959
nargs="+",
6060
)
6161
parser.add_argument(
@@ -151,7 +151,7 @@ def getFromConfig(key: str) -> list[types.ucstr]:
151151

152152
package_info_manager = packageinfo.PackageInfoManager(simpleConf.get("pypi_api"))
153153

154-
incompatible, depsWithLicenses = get_deps.check(
154+
incompatible, depsWithLicenses = checker.check(
155155
requirements_paths=requirements_paths,
156156
groups=simpleConf.get("groups", []),
157157
this_license=this_license,
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from __future__ import annotations
2+
import pytest
3+
from unittest.mock import MagicMock
4+
from licensecheck.types import PackageInfo, ucstr, License
5+
from licensecheck.packageinfo import PackageInfoManager
6+
from licensecheck.checker import check
7+
8+
9+
@pytest.fixture
10+
def mock_package_info_manager() -> PackageInfoManager:
11+
"""Fixture to provide a mocked PackageInfoManager."""
12+
return MagicMock(spec=PackageInfoManager)
13+
14+
15+
@pytest.mark.parametrize(
16+
("ignore_packages", "fail_packages", "fail_licenses", "expected_incompatible"),
17+
[
18+
(None, None, None, False), # No fail conditions, should pass
19+
(["PACKAGE_B"], None, None, False), # Ignored package should not cause failure
20+
(["PACKAGE*"], None, None, False), # Globs are supported in ignore_packages
21+
(None, ["PACKAGE_A"], None, True), # PACKAGE_A in fail_packages should fail
22+
(None, ["PACKAGE*"], None, True), # Globs are supported in fail_packages
23+
(None, None, ["GPL-3.0"], True), # GPL-3.0 should be marked as incompatible
24+
(None, None, ["GPL*"], False), # Globs are not supported on licenses!
25+
],
26+
)
27+
def test_check(
28+
mock_package_info_manager: PackageInfoManager,
29+
ignore_packages: list | None,
30+
fail_packages: list | None,
31+
fail_licenses: list | None,
32+
expected_incompatible: bool,
33+
):
34+
"""Parametrized test for different license check scenarios."""
35+
mock_packages = {
36+
PackageInfo(name="PACKAGE_A", license=ucstr("MIT"), licenseCompat=True),
37+
PackageInfo(name="PACKAGE_B", license=ucstr("GPL-3.0"), licenseCompat=False),
38+
}
39+
mock_package_info_manager.getPackages.return_value = mock_packages
40+
41+
incompatible, packages = check(
42+
requirements_paths=["requirements.txt"],
43+
groups=[],
44+
this_license=License.GPL_3_PLUS,
45+
package_info_manager=mock_package_info_manager,
46+
ignore_packages=ignore_packages,
47+
fail_packages=fail_packages,
48+
fail_licenses=fail_licenses,
49+
)
50+
51+
assert incompatible == expected_incompatible, packages

0 commit comments

Comments
 (0)