Skip to content

Commit c3beead

Browse files
committed
2021.5
1 parent 0784b2b commit c3beead

File tree

9 files changed

+110
-67
lines changed

9 files changed

+110
-67
lines changed

.pre-commit-hooks.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- id: licensecheck
2+
name: licensecheck
3+
description: "Output the licenses used by dependencies and check if these are compatible with the project license"
4+
entry: licensecheck --zero
5+
language: python
6+
minimum_pre_commit_version: 2.9.2
7+
pass_filenames: false

CHANGELOG.md

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

5-
## 2021.5 - 2021/09/xx
5+
## 2021.5 - 2021/09/14
66
- Add `-u poetry:dev` to command-line to include dev packages (excluded by default) per https://github.com/FHPythonUtils/LicenseCheck/issues/16
77
- Add support for proprietary license per https://github.com/FHPythonUtils/LicenseCheck/issues/15
88
- Raise RuntimeError if missing license and classifier https://github.com/FHPythonUtils/LicenseCheck/issues/14
99
- Quality improvements to license_matrix.py
1010
- Add additional examples to readme
11+
- Support pre-commit-hooks https://github.com/FHPythonUtils/LicenseCheck/issues/8
1112

1213

1314
## 2021.4.1 - 2021/09/07

DOCS/licensecheck/license_matrix.md

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Define a foss compatability license_matrix.
66

77
- [Licensecheck](../README.md#licensecheck-index) / [Modules](../README.md#licensecheck-modules) / [licensecheck](index.md#licensecheck) / license_matrix
88
- [depCompatWMyLice](#depcompatwmylice)
9+
- [licenseLookup](#licenselookup)
910
- [licenseType](#licensetype)
1011

1112
Standard disclaimer:: I am not a lawyer and there is no guarantee that the
@@ -43,36 +44,36 @@ EU -> gpl -> agpl (3 only)
4344

4445
#### Attributes
4546

46-
- `PERMISSIVE` - Permissive licenses compatible with GPL: `[License.MIT, License.BOOST, License.BSD, Licen...`
47-
- `PERMISSIVE_OTHER` - Permissive licenses NOT compatible with GPL: `[License.APACHE, License.ECLIPSE, License.ACADEMIC_FREE]`
48-
- `LGPL` - LGPL licenses: `[License.LGPL_2, License.LGPL_3, License.LGPL_2...`
49-
- `GPL` - GPL licenses (including AGPL): `[License.GPL_2, License.GPL_3, License.GPL_2_PL...`
50-
- `OTHER_COPYLEFT` - Other Copyleft licenses: `[License.MPL, License.EU]`
47+
- `PERMISSIVE` - Permissive licenses compatible with GPL: `[L.MIT, L.BOOST, L.BSD, L.ISC, L.NCSA, L.PSFL]`
48+
- `PERMISSIVE_OTHER` - Permissive licenses NOT compatible with GPL: `[L.APACHE, L.ECLIPSE, L.ACADEMIC_FREE]`
49+
- `LGPL` - LGPL licenses: `[L.LGPL_2, L.LGPL_3, L.LGPL_2_PLUS, L.LGPL_3_PLUS, L.LGPL_X]`
50+
- `GPL` - GPL licenses (including AGPL): `[L.GPL_2, L.GPL_3, L.GPL_2_PLUS, L.GPL_3_PLUS, L.GPL_X, L.AGPL_3_PLUS]`
51+
- `OTHER_COPYLEFT` - Other Copyleft licenses: `[L.MPL, L.EU]`
5152
- `UNLICENSE_INCOMPATIBLE` - Basic compat matrix: `PERMISSIVE + PERMISSIVE_OTHER + GPL + LGPL + OT...`
5253
- `GPL_2_INCOMPATIBLE` - GPL compat matrix
53-
https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility: `[License.GPL_3, License.GPL_3_PLUS, License.LGPL_3, License.LGPL_3_PLUS]`
54+
https://www.gnu.org/licenses/gpl-faq.html#AllCompatibility: `[L.GPL_3, L.GPL_3_PLUS, L.LGPL_3, L.LGPL_3_PLUS]`
5455

5556
## depCompatWMyLice
5657

57-
[[find in source code]](../../licensecheck/license_matrix.py#L168)
58+
[[find in source code]](../../licensecheck/license_matrix.py#L153)
5859

5960
```python
6061
def depCompatWMyLice(
61-
myLicense: License,
62-
depLice: list[License],
63-
ignoreLicenses: list[License] = None,
64-
failLicenses: list[License] = None,
62+
myLicense: L,
63+
depLice: list[L],
64+
ignoreLicenses: list[L] = None,
65+
failLicenses: list[L] = None,
6566
) -> bool:
6667
```
6768

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

7071
#### Arguments
7172

72-
- `myLicense` *License* - end user license to check
73-
- `depLice` *list[License]* - dependency license
74-
- `ignoreLicenses` *list[License], optional* - list of licenses to ignore. Defaults to None.
75-
- `failLicenses` *list[License], optional* - list of licenses to fail on. Defaults to None.
73+
- `myLicense` *L* - end user license to check
74+
- `depLice` *list[L]* - dependency license
75+
- `ignoreLicenses` *list[L], optional* - list of licenses to ignore. Defaults to None.
76+
- `failLicenses` *list[L], optional* - list of licenses to fail on. Defaults to None.
7677

7778
#### Returns
7879

@@ -82,12 +83,34 @@ Identify if the end user license is compatible with the dependency license(s).
8283

8384
- [License](types.md#license)
8485

85-
## licenseType
86+
## licenseLookup
8687

8788
[[find in source code]](../../licensecheck/license_matrix.py#L43)
8889

8990
```python
90-
def licenseType(lice: str) -> list[License]:
91+
def licenseLookup(licenseStr: str) -> L:
92+
```
93+
94+
Identify a license from an uppercase string representation of a license.
95+
96+
#### Arguments
97+
98+
- `licenseStr` *str* - uppercase string representation of a license
99+
100+
#### Returns
101+
102+
- `L` - License represented by licenseStr
103+
104+
#### See also
105+
106+
- [License](types.md#license)
107+
108+
## licenseType
109+
110+
[[find in source code]](../../licensecheck/license_matrix.py#L86)
111+
112+
```python
113+
def licenseType(lice: str) -> list[L]:
91114
```
92115

93116
Return a list of license types from a license string.
@@ -98,4 +121,4 @@ Return a list of license types from a license string.
98121

99122
#### Returns
100123

101-
- `list[License]` - the license
124+
- `list[L]` - the license

DOCS/licensecheck/packageinfo.md

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Get information for installed and online packages.
66

77
- [Licensecheck](../README.md#licensecheck-index) / [Modules](../README.md#licensecheck-modules) / [licensecheck](index.md#licensecheck) / packageinfo
8-
- [PackageInfo](#packageinfo)
98
- [calcContainer](#calccontainer)
109
- [getModuleSize](#getmodulesize)
1110
- [getMyPackageLicense](#getmypackagelicense)
@@ -15,19 +14,9 @@ Get information for installed and online packages.
1514
- [licenseFromClassifierMessage](#licensefromclassifiermessage)
1615
- [licenseFromClassifierlist](#licensefromclassifierlist)
1716

18-
## PackageInfo
19-
20-
[[find in source code]](../../licensecheck/packageinfo.py#L21)
21-
22-
```python
23-
class PackageInfo(typing.TypedDict):
24-
```
25-
26-
PackageInfo type.
27-
2817
## calcContainer
2918

30-
[[find in source code]](../../licensecheck/packageinfo.py#L207)
19+
[[find in source code]](../../licensecheck/packageinfo.py#L204)
3120

3221
```python
3322
def calcContainer(path: str) -> int:
@@ -45,7 +34,7 @@ Get size of installed module from path.
4534

4635
## getModuleSize
4736

48-
[[find in source code]](../../licensecheck/packageinfo.py#L224)
37+
[[find in source code]](../../licensecheck/packageinfo.py#L221)
4938

5039
```python
5140
def getModuleSize(pkg: Distribution) -> int:
@@ -63,7 +52,7 @@ Get the size of a given module as an int.
6352

6453
## getMyPackageLicense
6554

66-
[[find in source code]](../../licensecheck/packageinfo.py#L178)
55+
[[find in source code]](../../licensecheck/packageinfo.py#L168)
6756

6857
```python
6958
def getMyPackageLicense() -> str:
@@ -75,9 +64,13 @@ Get the pyproject data.
7564

7665
- `str` - license name
7766

67+
#### Raises
68+
69+
- `RuntimeError` - Must specify a license using license spdx or classifier (tool.poetry or tool.flit)
70+
7871
## getPackages
7972

80-
[[find in source code]](../../licensecheck/packageinfo.py#L162)
73+
[[find in source code]](../../licensecheck/packageinfo.py#L152)
8174

8275
```python
8376
def getPackages(reqs: list[str]) -> list[PackageInfo]:
@@ -95,7 +88,7 @@ Get dependency info.
9588

9689
## getPackagesFromLocal
9790

98-
[[find in source code]](../../licensecheck/packageinfo.py#L33)
91+
[[find in source code]](../../licensecheck/packageinfo.py#L23)
9992

10093
```python
10194
def getPackagesFromLocal(requirements: list[str]) -> list[PackageInfo]:
@@ -115,7 +108,7 @@ and the license.
115108

116109
## getPackagesFromOnline
117110

118-
[[find in source code]](../../licensecheck/packageinfo.py#L107)
111+
[[find in source code]](../../licensecheck/packageinfo.py#L97)
119112

120113
```python
121114
def getPackagesFromOnline(requirements: list[str]) -> list[PackageInfo]:
@@ -135,7 +128,7 @@ and the license.
135128

136129
## licenseFromClassifierMessage
137130

138-
[[find in source code]](../../licensecheck/packageinfo.py#L85)
131+
[[find in source code]](../../licensecheck/packageinfo.py#L75)
139132

140133
```python
141134
def licenseFromClassifierMessage(message: Message) -> str:
@@ -153,7 +146,7 @@ Get license string from a Message of project classifiers.
153146

154147
## licenseFromClassifierlist
155148

156-
[[find in source code]](../../licensecheck/packageinfo.py#L140)
149+
[[find in source code]](../../licensecheck/packageinfo.py#L130)
157150

158151
```python
159152
def licenseFromClassifierlist(classifiers: list[str]) -> str:

DOCS/licensecheck/types.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ PackageCompat type.
77
- [Licensecheck](../README.md#licensecheck-index) / [Modules](../README.md#licensecheck-modules) / [licensecheck](index.md#licensecheck) / types
88
- [License](#license)
99
- [PackageCompat](#packagecompat)
10+
- [PackageInfo](#packageinfo)
1011

1112
## License
1213

13-
[[find in source code]](../../licensecheck/types.py#L20)
14+
[[find in source code]](../../licensecheck/types.py#L25)
1415

1516
```python
1617
class License(Enum):
@@ -27,14 +28,29 @@ License Enum to hold a set of potential licenses.
2728
- `GPL_X` - GPL: `40`
2829
- `AGPL_3_PLUS` - AGPL: `50`
2930
- `MPL` - Other copyleft: `60`
31+
- `PROPRIETARY` - PROPRIETARY: `190`
3032
- `NO_LICENSE` - No License: `200`
3133

3234
## PackageCompat
3335

34-
[[find in source code]](../../licensecheck/types.py#L7)
36+
[[find in source code]](../../licensecheck/types.py#L19)
3537

3638
```python
37-
class PackageCompat(typing.TypedDict):
39+
class PackageCompat(PackageInfo):
3840
```
3941

4042
PackageCompat type.
43+
44+
#### See also
45+
46+
- [PackageInfo](#packageinfo)
47+
48+
## PackageInfo
49+
50+
[[find in source code]](../../licensecheck/types.py#L7)
51+
52+
```python
53+
class PackageInfo(typing.TypedDict):
54+
```
55+
56+
PackageInfo type.

licensecheck/__init__.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def cli() -> None:
3131
parser.add_argument(
3232
"--using",
3333
"-u",
34-
help=f"Environment to use e.g. requirements.txt. one of: {', '.join(get_deps.USINGS)}. default=poetry",
34+
help="Environment to use e.g. requirements.txt. one of: "
35+
f"{', '.join(get_deps.USINGS)}. default=poetry",
3536
)
3637
parser.add_argument(
3738
"--ignore-packages",
@@ -75,31 +76,38 @@ def cli() -> None:
7576
["tool"],
7677
["tool"],
7778
)
78-
sc = SimpleConf(configparser, "licensecheck", args)
79+
simpleConf = SimpleConf(configparser, "licensecheck", args)
7980

8081
# File
81-
filename = stdout if sc.get("file") is None else open(sc.get("file"), "w")
82+
filename = (
83+
stdout
84+
if simpleConf.get("file") is None
85+
else open(simpleConf.get("file"), "w", encoding="utf-8")
86+
)
8287

8388
# Get list of licenses
8489
dependenciesWLicenses = get_deps.getDepsWLicenses(
85-
sc.get("using", "poetry"),
86-
sc.get("ignore_packages", []),
87-
sc.get("fail_packages", []),
88-
sc.get("ignore_licenses", []),
89-
sc.get("fail_licenses", []),
90+
simpleConf.get("using", "poetry"),
91+
simpleConf.get("ignore_packages", []),
92+
simpleConf.get("fail_packages", []),
93+
simpleConf.get("ignore_licenses", []),
94+
simpleConf.get("fail_licenses", []),
9095
)
9196

9297
# Are any licenses incompatible?
9398
incompatible = any(not lice["license_compat"] for lice in dependenciesWLicenses)
9499

95100
# Format the results
96-
if sc.get("format", "simple") in formatter.formatMap:
97-
print(formatter.formatMap[sc.get("format", "simple")](dependenciesWLicenses), file=filename)
101+
if simpleConf.get("format", "simple") in formatter.formatMap:
102+
print(
103+
formatter.formatMap[simpleConf.get("format", "simple")](dependenciesWLicenses),
104+
file=filename,
105+
)
98106
else:
99107
exitCode = 2
100108

101109
# Exit code of 1 if args.zero
102-
if sc.get("zero", False) and incompatible:
110+
if simpleConf.get("zero", False) and incompatible:
103111
exitCode = 1
104112

105113
# Cleanup + exit

licensecheck/packageinfo.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,9 @@
1515
from pip._internal.utils.misc import get_installed_distributions
1616
from pip._vendor.pkg_resources import Distribution
1717

18-
UNKNOWN = "UNKNOWN"
19-
18+
from licensecheck.types import PackageInfo
2019

21-
class PackageInfo(typing.TypedDict):
22-
"""PackageInfo type."""
23-
24-
name: str
25-
version: str
26-
namever: str
27-
size: int
28-
home_page: str
29-
author: str
30-
license: str
20+
UNKNOWN = "UNKNOWN"
3121

3222

3323
def getPackagesFromLocal(requirements: list[str]) -> list[PackageInfo]:

licensecheck/types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from enum import Enum
55

66

7-
class PackageCompat(typing.TypedDict):
8-
"""PackageCompat type."""
7+
class PackageInfo(typing.TypedDict):
8+
"""PackageInfo type."""
99

1010
name: str
1111
version: str
@@ -14,6 +14,11 @@ class PackageCompat(typing.TypedDict):
1414
home_page: str
1515
author: str
1616
license: str
17+
18+
19+
class PackageCompat(PackageInfo):
20+
"""PackageCompat type."""
21+
1722
license_compat: bool
1823

1924

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "licensecheck"
3-
version = "2021.4.1"
3+
version = "2021.5"
44
description = "Output the licenses used by dependencies and check if these are compatible with the project license"
55
authors = ["FredHappyface"]
66
classifiers = [

0 commit comments

Comments
 (0)