Skip to content

Commit

Permalink
rel 2024.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Mar 20, 2024
1 parent 1e37a9d commit 288ace8
Show file tree
Hide file tree
Showing 22 changed files with 141 additions and 61 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All major and minor version changes will be documented in this file. Details of
patch-level version changes can be found in [commit messages](../../commits/master).

## 2024.1.3 - 2024/03/20

- fix https://github.com/FHPythonUtils/LicenseCheck/issues/74
- update tests (as env has changed, ideally we'd mock more than we do atm)
- linting fixes

## 2024.1.2 - 2024/03/20

- fix: use `appdirs` for storing the db for `requests_cache`
Expand Down
4 changes: 4 additions & 0 deletions documentation/reference/licensecheck/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def cli() -> None: ...

Test entry point.

Note: FHConfParser (Parses in the following order: `pyproject.toml`,
`setup.cfg`, `licensecheck.toml`, `licensecheck.json`,
`licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini`)

#### Signature

```python
Expand Down
2 changes: 1 addition & 1 deletion documentation/reference/licensecheck/get_deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def do_get_reqs(

## getDepsWithLicenses

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

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

Expand Down
15 changes: 7 additions & 8 deletions documentation/reference/licensecheck/license_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## depCompatWMyLice

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

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

Expand Down Expand Up @@ -50,7 +50,7 @@ def depCompatWMyLice(

## liceCompat

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

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

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

#### Arguments

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

#### Returns

-------
- `L` - License represented by licenseStr
Type: *L*
License represented by licenseStr

#### Signature

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

## licenseType

[Show source in license_matrix.py:117](../../../licensecheck/license_matrix.py#L117)
[Show source in license_matrix.py:111](../../../licensecheck/license_matrix.py#L111)

Return a list of license types from a license string.

Expand Down
29 changes: 22 additions & 7 deletions documentation/reference/licensecheck/packageinfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
> Auto-generated documentation for [licensecheck.packageinfo](../../../licensecheck/packageinfo.py) module.
- [Packageinfo](#packageinfo)
- [_pkgMetadataGet](#_pkgmetadataget)
- [getModuleSize](#getmodulesize)
- [getMyPackageLicense](#getmypackagelicense)
- [getMyPackageMetadata](#getmypackagemetadata)
Expand All @@ -13,9 +14,23 @@
- [getPackages](#getpackages)
- [licenseFromClassifierlist](#licensefromclassifierlist)

## _pkgMetadataGet

[Show source in packageinfo.py:17](../../../licensecheck/packageinfo.py#L17)

Get a string from a key from pkgMetadata.

#### Signature

```python
def _pkgMetadataGet(pkgMetadata: metadata.PackageMetadata, key: str) -> str: ...
```



## getModuleSize

[Show source in packageinfo.py:181](../../../licensecheck/packageinfo.py#L181)
[Show source in packageinfo.py:192](../../../licensecheck/packageinfo.py#L192)

Get the size of a given module as an int.

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

## getMyPackageLicense

[Show source in packageinfo.py:162](../../../licensecheck/packageinfo.py#L162)
[Show source in packageinfo.py:173](../../../licensecheck/packageinfo.py#L173)

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

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

## getMyPackageMetadata

[Show source in packageinfo.py:136](../../../licensecheck/packageinfo.py#L136)
[Show source in packageinfo.py:144](../../../licensecheck/packageinfo.py#L144)

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

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

## getPackageInfoLocal

[Show source in packageinfo.py:17](../../../licensecheck/packageinfo.py#L17)
[Show source in packageinfo.py:25](../../../licensecheck/packageinfo.py#L25)

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

## getPackageInfoPypi

[Show source in packageinfo.py:54](../../../licensecheck/packageinfo.py#L54)
[Show source in packageinfo.py:62](../../../licensecheck/packageinfo.py#L62)

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

## getPackages

[Show source in packageinfo.py:111](../../../licensecheck/packageinfo.py#L111)
[Show source in packageinfo.py:119](../../../licensecheck/packageinfo.py#L119)

Get dependency info.

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

## licenseFromClassifierlist

[Show source in packageinfo.py:87](../../../licensecheck/packageinfo.py#L87)
[Show source in packageinfo.py:95](../../../licensecheck/packageinfo.py#L95)

Get license string from a list of project classifiers.

Expand Down
8 changes: 6 additions & 2 deletions documentation/reference/licensecheck/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __post_init__(self) -> None: ...

Return a filtered dictionary of the object.

:param list[str] hide_output_parameters: list of parameters to ignore
:param list[ucstr] hide_output_parameters: list of parameters to ignore

#### Returns

Expand All @@ -87,9 +87,13 @@ filtered dictionary
#### Signature

```python
def get_filtered_dict(self, hide_output_parameters: list[str]) -> dict: ...
def get_filtered_dict(self, hide_output_parameters: list[ucstr]) -> dict: ...
```

#### See also

- [ucstr](#ucstr)



## ucstr
Expand Down
10 changes: 6 additions & 4 deletions licensecheck/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ def cli() -> None: # pragma: no cover


def main(args: dict) -> int:
"""Test entry point."""
"""Test entry point.
Note: FHConfParser (Parses in the following order: `pyproject.toml`,
`setup.cfg`, `licensecheck.toml`, `licensecheck.json`,
`licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini`)
"""
exitCode = 0

# ConfigParser (Parses in the following order: `pyproject.toml`,
# `setup.cfg`, `licensecheck.toml`, `licensecheck.json`,
# `licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini`)
configparser = FHConfParser()
namespace = ["tool"]
configparser.parseConfigList(
Expand Down
11 changes: 5 additions & 6 deletions licensecheck/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ def resolveReq(req: str, *, extra: bool = True) -> ucstr:
canonicalName = name
if len(extras) > 0:
canonicalName = ucstr(f"{name}[{next(iter(extras))}]")
# To avoid overwriting the initial mapping in extrasReqs
# only overwrite when extra = True
# Avoid overwriting the initial mapping in extrasReqs, only overwrite when extra is True
if extra:
extrasReqs[name] = extras
return canonicalName if extra else name
Expand All @@ -121,7 +120,7 @@ def resolveExtraReq(extraReq: str) -> ucstr | None:
for reqList in reqLists:
for req in reqList:
reqs.add(resolveReq(req))
# PEP631 (hatch)
# PEP631
if using == "PEP631":
try:
project = pyproject["project"]
Expand Down Expand Up @@ -156,7 +155,7 @@ def resolveExtraReq(extraReq: str) -> ucstr | None:
with contextlib.suppress(KeyError):
reqs.remove(skipDependency)

# Get Dependencies (1 deep)
# Get Dependencies, 1 deep
requirementsWithDeps = reqs.copy()

def update_dependencies(dependency: str) -> None:
Expand Down Expand Up @@ -225,7 +224,7 @@ def getDepsWithLicenses(
)
failLicensesType = license_matrix.licenseType(ucstr(JOINS.join(failLicenses)), ignoreLicenses)
onlyLicensesType = license_matrix.licenseType(ucstr(JOINS.join(onlyLicenses)), ignoreLicenses)
# licenseType will always return NO_LICENSE for None
# licenseType will always return NO_LICENSE when onlyLicenses is empty # noqa: ERA001
if License.NO_LICENSE in onlyLicensesType:
onlyLicensesType.remove(License.NO_LICENSE)

Expand All @@ -241,7 +240,7 @@ def getDepsWithLicenses(
pass # package.licenseCompat = False
# Old behaviour
else:
package.licenseCompat = license_matrix.depCompatWMyLice( # type: ignore
package.licenseCompat = license_matrix.depCompatWMyLice(
myLice,
license_matrix.licenseType(package.license, ignoreLicenses),
ignoreLicensesType,
Expand Down
12 changes: 3 additions & 9 deletions licensecheck/license_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,9 @@
def licenseLookup(licenseStr: ucstr, ignoreLicenses: list[ucstr] | None = None) -> L:
"""Identify a license from an uppercase string representation of a license.
Args:
----
licenseStr (ucstr): uppercase string representation of a license
ignoreLicenses (list[ucstr] | None) licenses to ignore. Default=None
Returns:
-------
L: License represented by licenseStr
:param ucstr licenseStr: uppercase string representation of a license
:param list[ucstr] | None ignoreLicenses: licenses to ignore, defaults to None
:return L: License represented by licenseStr
"""
termToLicense = {
"PUBLIC DOMAIN": L.PUBLIC,
Expand Down
23 changes: 17 additions & 6 deletions licensecheck/packageinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
from licensecheck.types import JOINS, UNKNOWN, PackageInfo, ucstr


def _pkgMetadataGet(pkgMetadata: metadata.PackageMetadata, key: str) -> str:
"""Get a string from a key from pkgMetadata."""
value = pkgMetadata.json.get(key, UNKNOWN)
if isinstance(value, str):
return value
return JOINS.join(value)


def getPackageInfoLocal(requirement: ucstr) -> PackageInfo:
"""Get package info from local files including version, author
and the license.
Expand All @@ -23,15 +31,15 @@ def getPackageInfoLocal(requirement: ucstr) -> PackageInfo:
:return PackageInfo: package information
"""
try:
# Get pkg metadata: license, homepage + author
# Get pkg metadata,, license, homepage, and author
pkgMetadata = metadata.metadata(requirement)
lice = licenseFromClassifierlist(pkgMetadata.get_all("Classifier"))
if lice == UNKNOWN:
lice = pkgMetadata.get("License", UNKNOWN)
lice = _pkgMetadataGet(pkgMetadata, "license")
homePage = pkgMetadata.get("Home-page", UNKNOWN)
author = pkgMetadata.get("Author", UNKNOWN)
name = pkgMetadata.get("Name", UNKNOWN)
version = pkgMetadata.get("Version", UNKNOWN)
author = _pkgMetadataGet(pkgMetadata, "author")
name = _pkgMetadataGet(pkgMetadata, "name")
version = _pkgMetadataGet(pkgMetadata, "version")
size = 0
packagePaths = metadata.Distribution.from_name(requirement).files
if packagePaths is not None:
Expand Down Expand Up @@ -145,7 +153,10 @@ def getMyPackageMetadata() -> dict[str, Any]:
config = configparser.ConfigParser()
config.read("setup.cfg")
if "metadata" in config.sections() and "license" in config["metadata"]:
return config["metadata"].__dict__
classifiers = config.get("metadata", "classifiers").strip().splitlines()
licenseStr = ucstr(config.get("metadata", "license"))
return {"classifiers": classifiers, "license": licenseStr}

if Path("pyproject.toml").exists():
pyproject = tomli.loads(Path("pyproject.toml").read_text(encoding="utf-8"))
tool = pyproject["tool"]
Expand Down
4 changes: 2 additions & 2 deletions licensecheck/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def __post_init__(self) -> None:
"""Set the namever once the object is initialised."""
self.namever = f"{self.name}-{self.version}"

def get_filtered_dict(self, hide_output_parameters: list[str]) -> dict:
def get_filtered_dict(self, hide_output_parameters: list[ucstr]) -> dict:
"""Return a filtered dictionary of the object.
:param list[str] hide_output_parameters: list of parameters to ignore
:param list[ucstr] hide_output_parameters: list of parameters to ignore
:return dict: filtered dictionary
"""
return {k: v for k, v in self.__dict__.items() if k.upper() not in hide_output_parameters}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "licensecheck"
version = "2024.1.2"
version = "2024.1.3"
license = "mit"
description = "Output the licenses used by dependencies and check if these are compatible with the project license"
authors = ["FredHappyface"]
Expand Down
1 change: 1 addition & 0 deletions tests/data/test_main_tc1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ ✔ │ Pygments │ BSD LICENSE │
│ ✔ │ aiocontextvars │ BSD LICENSE │
│ ✔ │ appdirs │ MIT LICENSE │
│ ✔ │ attrs │ MIT LICENSE │
│ ✔ │ cattrs │ MIT LICENSE │
│ ✔ │ certifi │ MOZILLA PUBLIC LICENSE 2.0 (MPL 2.0) │
Expand Down
1 change: 1 addition & 0 deletions tests/data/test_main_tc1_expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ ✔ │ Pygments │ BSD LICENSE │
│ ✔ │ aiocontextvars │ BSD LICENSE │
│ ✔ │ appdirs │ MIT LICENSE │
│ ✔ │ attrs │ MIT LICENSE │
│ ✔ │ cattrs │ MIT LICENSE │
│ ✔ │ certifi │ MOZILLA PUBLIC LICENSE 2.0 (MPL 2.0) │
Expand Down
17 changes: 14 additions & 3 deletions tests/data/test_main_tc2.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
"errorCode": 0,
"namever": "aiocontextvars-0.2.2"
},
{
"name": "appdirs",
"version": "1.4.4",
"size": 34928,
"homePage": "http://github.com/ActiveState/appdirs",
"author": "Trent Mick",
"license": "MIT LICENSE",
"licenseCompat": true,
"errorCode": 0,
"namever": "appdirs-1.4.4"
},
{
"name": "attrs",
"version": "23.2.0",
Expand Down Expand Up @@ -195,14 +206,14 @@
},
{
"name": "typing-extensions",
"version": "4.9.0",
"size": 74918,
"version": "4.10.0",
"size": 77558,
"homePage": "",
"author": "",
"license": "PYTHON SOFTWARE FOUNDATION LICENSE",
"licenseCompat": true,
"errorCode": 0,
"namever": "typing-extensions-4.9.0"
"namever": "typing-extensions-4.10.0"
},
{
"name": "url-normalize",
Expand Down
Loading

0 comments on commit 288ace8

Please sign in to comment.