Coverage for pipxl/license.py: 100%
15 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-28 20:56 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-28 20:56 +0100
1# SPDX-FileCopyrightText: 2022-present Jeroen van Zundert <mail@jeroenvanzundert.nl>
2#
3# SPDX-License-Identifier: MIT
5from __future__ import annotations
7from pathlib import Path
9from pipxl.resolver import pip_resolve
12def license(files_in: list[Path] | None = None, package_spec: list[str] | None = None) -> dict[str | None, list[str]]:
13 reqs, _ = pip_resolve(files_in, package_spec)
15 by_license = {}
16 for r in reqs:
17 lic = _parse_license(r.license)
18 if lic not in by_license:
19 by_license[lic] = [r.name]
20 else:
21 by_license[lic] += [r.name]
23 # return sorted by license
24 by_license = dict(sorted(by_license.items(), key=lambda item: item[0] if item[0] is not None else "*"))
26 return by_license
29def _parse_license(lic: str | None) -> str | None:
30 return lic if (lic is not None and len(lic) < 50) else None