Skip to content

Commit 288ace8

Browse files
committed
rel 2024.1.3
1 parent 1e37a9d commit 288ace8

22 files changed

+141
-61
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All major and minor version changes will be documented in this file. Details of
44
patch-level version changes can be found in [commit messages](../../commits/master).
55

6+
## 2024.1.3 - 2024/03/20
7+
8+
- fix https://github.com/FHPythonUtils/LicenseCheck/issues/74
9+
- update tests (as env has changed, ideally we'd mock more than we do atm)
10+
- linting fixes
11+
612
## 2024.1.2 - 2024/03/20
713

814
- fix: use `appdirs` for storing the db for `requests_cache`

documentation/reference/licensecheck/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def cli() -> None: ...
2828

2929
Test entry point.
3030

31+
Note: FHConfParser (Parses in the following order: `pyproject.toml`,
32+
`setup.cfg`, `licensecheck.toml`, `licensecheck.json`,
33+
`licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini`)
34+
3135
#### Signature
3236

3337
```python

documentation/reference/licensecheck/get_deps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def do_get_reqs(
4949

5050
## getDepsWithLicenses
5151

52-
[Show source in get_deps.py:189](../../../licensecheck/get_deps.py#L189)
52+
[Show source in get_deps.py:188](../../../licensecheck/get_deps.py#L188)
5353

5454
Get a set of dependencies with licenses and determine license compatibility.
5555

documentation/reference/licensecheck/license_matrix.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## depCompatWMyLice
1414

15-
[Show source in license_matrix.py:136](../../../licensecheck/license_matrix.py#L136)
15+
[Show source in license_matrix.py:130](../../../licensecheck/license_matrix.py#L130)
1616

1717
Identify if the end user license is compatible with the dependency license(s).
1818

@@ -50,7 +50,7 @@ def depCompatWMyLice(
5050

5151
## liceCompat
5252

53-
[Show source in license_matrix.py:176](../../../licensecheck/license_matrix.py#L176)
53+
[Show source in license_matrix.py:170](../../../licensecheck/license_matrix.py#L170)
5454

5555
Identify if the end user license is compatible with the dependency license.
5656

@@ -93,14 +93,13 @@ Identify a license from an uppercase string representation of a license.
9393

9494
#### Arguments
9595

96-
----
97-
- `licenseStr` *ucstr* - uppercase string representation of a license
98-
ignoreLicenses (list[ucstr] | None) licenses to ignore. Default=None
96+
- `licenseStr` *ucstr* - uppercase string representation of a license
97+
:param list[ucstr] | None ignoreLicenses: licenses to ignore, defaults to None
9998

10099
#### Returns
101100

102-
-------
103-
- `L` - License represented by licenseStr
101+
Type: *L*
102+
License represented by licenseStr
104103

105104
#### Signature
106105

@@ -117,7 +116,7 @@ def licenseLookup(licenseStr: ucstr, ignoreLicenses: list[ucstr] | None = None)
117116

118117
## licenseType
119118

120-
[Show source in license_matrix.py:117](../../../licensecheck/license_matrix.py#L117)
119+
[Show source in license_matrix.py:111](../../../licensecheck/license_matrix.py#L111)
121120

122121
Return a list of license types from a license string.
123122

documentation/reference/licensecheck/packageinfo.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
> Auto-generated documentation for [licensecheck.packageinfo](../../../licensecheck/packageinfo.py) module.
66
77
- [Packageinfo](#packageinfo)
8+
- [_pkgMetadataGet](#_pkgmetadataget)
89
- [getModuleSize](#getmodulesize)
910
- [getMyPackageLicense](#getmypackagelicense)
1011
- [getMyPackageMetadata](#getmypackagemetadata)
@@ -13,9 +14,23 @@
1314
- [getPackages](#getpackages)
1415
- [licenseFromClassifierlist](#licensefromclassifierlist)
1516

17+
## _pkgMetadataGet
18+
19+
[Show source in packageinfo.py:17](../../../licensecheck/packageinfo.py#L17)
20+
21+
Get a string from a key from pkgMetadata.
22+
23+
#### Signature
24+
25+
```python
26+
def _pkgMetadataGet(pkgMetadata: metadata.PackageMetadata, key: str) -> str: ...
27+
```
28+
29+
30+
1631
## getModuleSize
1732

18-
[Show source in packageinfo.py:181](../../../licensecheck/packageinfo.py#L181)
33+
[Show source in packageinfo.py:192](../../../licensecheck/packageinfo.py#L192)
1934

2035
Get the size of a given module as an int.
2136

@@ -44,7 +59,7 @@ def getModuleSize(path: Path, name: ucstr) -> int: ...
4459

4560
## getMyPackageLicense
4661

47-
[Show source in packageinfo.py:162](../../../licensecheck/packageinfo.py#L162)
62+
[Show source in packageinfo.py:173](../../../licensecheck/packageinfo.py#L173)
4863

4964
Get the package license from "setup.cfg", "pyproject.toml" or user input.
5065

@@ -66,7 +81,7 @@ def getMyPackageLicense() -> ucstr: ...
6681

6782
## getMyPackageMetadata
6883

69-
[Show source in packageinfo.py:136](../../../licensecheck/packageinfo.py#L136)
84+
[Show source in packageinfo.py:144](../../../licensecheck/packageinfo.py#L144)
7085

7186
Get the package classifiers and license from "setup.cfg", "pyproject.toml".
7287

@@ -84,7 +99,7 @@ def getMyPackageMetadata() -> dict[str, Any]: ...
8499

85100
## getPackageInfoLocal
86101

87-
[Show source in packageinfo.py:17](../../../licensecheck/packageinfo.py#L17)
102+
[Show source in packageinfo.py:25](../../../licensecheck/packageinfo.py#L25)
88103

89104
Get package info from local files including version, author
90105
and the license.
@@ -117,7 +132,7 @@ def getPackageInfoLocal(requirement: ucstr) -> PackageInfo: ...
117132

118133
## getPackageInfoPypi
119134

120-
[Show source in packageinfo.py:54](../../../licensecheck/packageinfo.py#L54)
135+
[Show source in packageinfo.py:62](../../../licensecheck/packageinfo.py#L62)
121136

122137
Get package info from local files including version, author
123138
and the license.
@@ -150,7 +165,7 @@ def getPackageInfoPypi(requirement: ucstr) -> PackageInfo: ...
150165

151166
## getPackages
152167

153-
[Show source in packageinfo.py:111](../../../licensecheck/packageinfo.py#L111)
168+
[Show source in packageinfo.py:119](../../../licensecheck/packageinfo.py#L119)
154169

155170
Get dependency info.
156171

@@ -179,7 +194,7 @@ def getPackages(reqs: set[ucstr]) -> set[PackageInfo]: ...
179194

180195
## licenseFromClassifierlist
181196

182-
[Show source in packageinfo.py:87](../../../licensecheck/packageinfo.py#L87)
197+
[Show source in packageinfo.py:95](../../../licensecheck/packageinfo.py#L95)
183198

184199
Get license string from a list of project classifiers.
185200

documentation/reference/licensecheck/types.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __post_init__(self) -> None: ...
7777

7878
Return a filtered dictionary of the object.
7979

80-
:param list[str] hide_output_parameters: list of parameters to ignore
80+
:param list[ucstr] hide_output_parameters: list of parameters to ignore
8181

8282
#### Returns
8383

@@ -87,9 +87,13 @@ filtered dictionary
8787
#### Signature
8888

8989
```python
90-
def get_filtered_dict(self, hide_output_parameters: list[str]) -> dict: ...
90+
def get_filtered_dict(self, hide_output_parameters: list[ucstr]) -> dict: ...
9191
```
9292

93+
#### See also
94+
95+
- [ucstr](#ucstr)
96+
9397

9498

9599
## ucstr

licensecheck/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ def cli() -> None: # pragma: no cover
8787

8888

8989
def main(args: dict) -> int:
90-
"""Test entry point."""
90+
"""Test entry point.
91+
92+
Note: FHConfParser (Parses in the following order: `pyproject.toml`,
93+
`setup.cfg`, `licensecheck.toml`, `licensecheck.json`,
94+
`licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini`)
95+
"""
9196
exitCode = 0
9297

93-
# ConfigParser (Parses in the following order: `pyproject.toml`,
94-
# `setup.cfg`, `licensecheck.toml`, `licensecheck.json`,
95-
# `licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini`)
9698
configparser = FHConfParser()
9799
namespace = ["tool"]
98100
configparser.parseConfigList(

licensecheck/get_deps.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ def resolveReq(req: str, *, extra: bool = True) -> ucstr:
9494
canonicalName = name
9595
if len(extras) > 0:
9696
canonicalName = ucstr(f"{name}[{next(iter(extras))}]")
97-
# To avoid overwriting the initial mapping in extrasReqs
98-
# only overwrite when extra = True
97+
# Avoid overwriting the initial mapping in extrasReqs, only overwrite when extra is True
9998
if extra:
10099
extrasReqs[name] = extras
101100
return canonicalName if extra else name
@@ -121,7 +120,7 @@ def resolveExtraReq(extraReq: str) -> ucstr | None:
121120
for reqList in reqLists:
122121
for req in reqList:
123122
reqs.add(resolveReq(req))
124-
# PEP631 (hatch)
123+
# PEP631
125124
if using == "PEP631":
126125
try:
127126
project = pyproject["project"]
@@ -156,7 +155,7 @@ def resolveExtraReq(extraReq: str) -> ucstr | None:
156155
with contextlib.suppress(KeyError):
157156
reqs.remove(skipDependency)
158157

159-
# Get Dependencies (1 deep)
158+
# Get Dependencies, 1 deep
160159
requirementsWithDeps = reqs.copy()
161160

162161
def update_dependencies(dependency: str) -> None:
@@ -225,7 +224,7 @@ def getDepsWithLicenses(
225224
)
226225
failLicensesType = license_matrix.licenseType(ucstr(JOINS.join(failLicenses)), ignoreLicenses)
227226
onlyLicensesType = license_matrix.licenseType(ucstr(JOINS.join(onlyLicenses)), ignoreLicenses)
228-
# licenseType will always return NO_LICENSE for None
227+
# licenseType will always return NO_LICENSE when onlyLicenses is empty # noqa: ERA001
229228
if License.NO_LICENSE in onlyLicensesType:
230229
onlyLicensesType.remove(License.NO_LICENSE)
231230

@@ -241,7 +240,7 @@ def getDepsWithLicenses(
241240
pass # package.licenseCompat = False
242241
# Old behaviour
243242
else:
244-
package.licenseCompat = license_matrix.depCompatWMyLice( # type: ignore
243+
package.licenseCompat = license_matrix.depCompatWMyLice(
245244
myLice,
246245
license_matrix.licenseType(package.license, ignoreLicenses),
247246
ignoreLicensesType,

licensecheck/license_matrix.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,9 @@
5555
def licenseLookup(licenseStr: ucstr, ignoreLicenses: list[ucstr] | None = None) -> L:
5656
"""Identify a license from an uppercase string representation of a license.
5757
58-
Args:
59-
----
60-
licenseStr (ucstr): uppercase string representation of a license
61-
ignoreLicenses (list[ucstr] | None) licenses to ignore. Default=None
62-
63-
Returns:
64-
-------
65-
L: License represented by licenseStr
66-
58+
:param ucstr licenseStr: uppercase string representation of a license
59+
:param list[ucstr] | None ignoreLicenses: licenses to ignore, defaults to None
60+
:return L: License represented by licenseStr
6761
"""
6862
termToLicense = {
6963
"PUBLIC DOMAIN": L.PUBLIC,

licensecheck/packageinfo.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
from licensecheck.types import JOINS, UNKNOWN, PackageInfo, ucstr
1515

1616

17+
def _pkgMetadataGet(pkgMetadata: metadata.PackageMetadata, key: str) -> str:
18+
"""Get a string from a key from pkgMetadata."""
19+
value = pkgMetadata.json.get(key, UNKNOWN)
20+
if isinstance(value, str):
21+
return value
22+
return JOINS.join(value)
23+
24+
1725
def getPackageInfoLocal(requirement: ucstr) -> PackageInfo:
1826
"""Get package info from local files including version, author
1927
and the license.
@@ -23,15 +31,15 @@ def getPackageInfoLocal(requirement: ucstr) -> PackageInfo:
2331
:return PackageInfo: package information
2432
"""
2533
try:
26-
# Get pkg metadata: license, homepage + author
34+
# Get pkg metadata,, license, homepage, and author
2735
pkgMetadata = metadata.metadata(requirement)
2836
lice = licenseFromClassifierlist(pkgMetadata.get_all("Classifier"))
2937
if lice == UNKNOWN:
30-
lice = pkgMetadata.get("License", UNKNOWN)
38+
lice = _pkgMetadataGet(pkgMetadata, "license")
3139
homePage = pkgMetadata.get("Home-page", UNKNOWN)
32-
author = pkgMetadata.get("Author", UNKNOWN)
33-
name = pkgMetadata.get("Name", UNKNOWN)
34-
version = pkgMetadata.get("Version", UNKNOWN)
40+
author = _pkgMetadataGet(pkgMetadata, "author")
41+
name = _pkgMetadataGet(pkgMetadata, "name")
42+
version = _pkgMetadataGet(pkgMetadata, "version")
3543
size = 0
3644
packagePaths = metadata.Distribution.from_name(requirement).files
3745
if packagePaths is not None:
@@ -145,7 +153,10 @@ def getMyPackageMetadata() -> dict[str, Any]:
145153
config = configparser.ConfigParser()
146154
config.read("setup.cfg")
147155
if "metadata" in config.sections() and "license" in config["metadata"]:
148-
return config["metadata"].__dict__
156+
classifiers = config.get("metadata", "classifiers").strip().splitlines()
157+
licenseStr = ucstr(config.get("metadata", "license"))
158+
return {"classifiers": classifiers, "license": licenseStr}
159+
149160
if Path("pyproject.toml").exists():
150161
pyproject = tomli.loads(Path("pyproject.toml").read_text(encoding="utf-8"))
151162
tool = pyproject["tool"]

0 commit comments

Comments
 (0)