Skip to content

Commit ed0887f

Browse files
committed
rel 2023.1.4
1 parent fd4acef commit ed0887f

File tree

19 files changed

+277
-98
lines changed

19 files changed

+277
-98
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
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+
## 2023.1.4 - 2023/06/26
7+
8+
- Update format to output info and detected package license
9+
- Bump dep versions
10+
611
## 2023.1.2 - 2023/06/24
712

813
- Merge PR https://github.com/FHPythonUtils/LicenseCheck/pull/39 (Fixes #38)

documentation/reference/licensecheck/formatter.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Format to ansi
2222

2323
#### Arguments
2424

25+
- `myLice` *License* - project license
2526
- `packages` *list[PackageInfo]* - list of PackageCompats to format.
2627

2728
#### Returns
@@ -31,24 +32,26 @@ Format to ansi
3132
#### Signature
3233

3334
```python
34-
def ansi(packages: list[PackageInfo]) -> str:
35+
def ansi(myLice: License, packages: list[PackageInfo]) -> str:
3536
...
3637
```
3738

3839
#### See also
3940

41+
- [License](./types.md#license)
4042
- [PackageInfo](./types.md#packageinfo)
4143

4244

4345

4446
## markdown
4547

46-
[Show source in formatter.py:99](../../../licensecheck/formatter.py#L99)
48+
[Show source in formatter.py:109](../../../licensecheck/formatter.py#L109)
4749

4850
Format to markdown
4951

5052
#### Arguments
5153

54+
- `myLice` *License* - project license
5255
- `packages` *list[PackageInfo]* - list of PackageCompats to format.
5356

5457
#### Returns
@@ -58,24 +61,26 @@ Format to markdown
5861
#### Signature
5962

6063
```python
61-
def markdown(packages: list[PackageInfo]) -> str:
64+
def markdown(myLice: License, packages: list[PackageInfo]) -> str:
6265
...
6366
```
6467

6568
#### See also
6669

70+
- [License](./types.md#license)
6771
- [PackageInfo](./types.md#packageinfo)
6872

6973

7074

7175
## plainText
7276

73-
[Show source in formatter.py:87](../../../licensecheck/formatter.py#L87)
77+
[Show source in formatter.py:96](../../../licensecheck/formatter.py#L96)
7478

75-
Format to plain text
79+
Format to ansi
7680

7781
#### Arguments
7882

83+
- `myLice` *License* - project license
7984
- `packages` *list[PackageInfo]* - list of PackageCompats to format.
8085

8186
#### Returns
@@ -85,24 +90,26 @@ Format to plain text
8590
#### Signature
8691

8792
```python
88-
def plainText(packages: list[PackageInfo]) -> str:
93+
def plainText(myLice: License, packages: list[PackageInfo]) -> str:
8994
...
9095
```
9196

9297
#### See also
9398

99+
- [License](./types.md#license)
94100
- [PackageInfo](./types.md#packageinfo)
95101

96102

97103

98104
## raw
99105

100-
[Show source in formatter.py:134](../../../licensecheck/formatter.py#L134)
106+
[Show source in formatter.py:148](../../../licensecheck/formatter.py#L148)
101107

102-
Format to raw json
108+
Format to json
103109

104110
#### Arguments
105111

112+
- `myLice` *License* - project license
106113
- `packages` *list[PackageInfo]* - list of PackageCompats to format.
107114

108115
#### Returns
@@ -112,24 +119,26 @@ Format to raw json
112119
#### Signature
113120

114121
```python
115-
def raw(packages: list[PackageInfo]) -> str:
122+
def raw(myLice: License, packages: list[PackageInfo]) -> str:
116123
...
117124
```
118125

119126
#### See also
120127

128+
- [License](./types.md#license)
121129
- [PackageInfo](./types.md#packageinfo)
122130

123131

124132

125133
## rawCsv
126134

127-
[Show source in formatter.py:146](../../../licensecheck/formatter.py#L146)
135+
[Show source in formatter.py:168](../../../licensecheck/formatter.py#L168)
128136

129-
Format to raw csv
137+
Format to csv
130138

131139
#### Arguments
132140

141+
- `myLice` *License* - project license
133142
- `packages` *list[PackageInfo]* - list of PackageCompats to format.
134143

135144
#### Returns
@@ -139,12 +148,13 @@ Format to raw csv
139148
#### Signature
140149

141150
```python
142-
def rawCsv(packages: list[PackageInfo]) -> str:
151+
def rawCsv(myLice: License, packages: list[PackageInfo]) -> str:
143152
...
144153
```
145154

146155
#### See also
147156

157+
- [License](./types.md#license)
148158
- [PackageInfo](./types.md#packageinfo)
149159

150160

documentation/reference/licensecheck/get_deps.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ Get a set of dependencies with licenses and determine license compatibility.
2626

2727
#### Returns
2828

29-
- `set[PackageInfo]` - set of updated dependencies with licenseCompat set
29+
- `tuple[License,` *set[PackageInfo]]* - tuple of
30+
my package license
31+
set of updated dependencies with licenseCompat set
3032

3133
#### Signature
3234

@@ -37,12 +39,13 @@ def getDepsWithLicenses(
3739
failPackages: list[str],
3840
ignoreLicenses: list[str],
3941
failLicenses: list[str],
40-
) -> set[PackageInfo]:
42+
) -> tuple[License, set[PackageInfo]]:
4143
...
4244
```
4345

4446
#### See also
4547

48+
- [License](./types.md#license)
4649
- [PackageInfo](./types.md#packageinfo)
4750

4851

documentation/reference/licensecheck/types.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Types
99
- [Types](#types)
1010
- [License](#license)
1111
- [PackageInfo](#packageinfo)
12+
- [printLicense](#printlicense)
1213

1314
## License
1415

@@ -60,3 +61,31 @@ class PackageInfo:
6061
```
6162

6263

64+
65+
## printLicense
66+
67+
[Show source in types.py:73](../../../licensecheck/types.py#L73)
68+
69+
Output a license as plain text
70+
71+
#### Arguments
72+
73+
- `licenseEnum` *L* - License
74+
75+
#### Returns
76+
77+
Type: *str*
78+
license of plain text
79+
80+
#### Signature
81+
82+
```python
83+
def printLicense(licenseEnum: L) -> str:
84+
...
85+
```
86+
87+
#### See also
88+
89+
- [L](#l)
90+
91+

licensecheck/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def cli() -> None:
8787
)
8888

8989
# Get list of licenses
90-
depsWithLicenses = get_deps.getDepsWithLicenses(
90+
myLice, depsWithLicenses = get_deps.getDepsWithLicenses(
9191
simpleConf.get("using", "poetry"),
9292
simpleConf.get("ignore_packages", []),
9393
simpleConf.get("fail_packages", []),
@@ -101,7 +101,7 @@ def cli() -> None:
101101
# Format the results
102102
if simpleConf.get("format", "simple") in formatter.formatMap:
103103
print(
104-
formatter.formatMap[simpleConf.get("format", "simple")](sorted(depsWithLicenses)),
104+
formatter.formatMap[simpleConf.get("format", "simple")](myLice, sorted(depsWithLicenses)),
105105
file=filename,
106106
)
107107
else:

licensecheck/formatter.py

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
from rich.console import Console
3232
from rich.table import Table
3333

34-
from licensecheck.types import PackageInfo
34+
from licensecheck.types import License, PackageInfo, printLicense
3535

36-
INFO = {"program": "licensecheck", "version": "2022.2.0"}
36+
INFO = {"program": "licensecheck", "version": "2023.1.3", "license": "mit"}
3737

3838

3939
def stripAnsi(string: str) -> str:
@@ -48,30 +48,39 @@ def stripAnsi(string: str) -> str:
4848
return re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])").sub("", string)
4949

5050

51-
def ansi(packages: list[PackageInfo]) -> str:
51+
def ansi(myLice: License, packages: list[PackageInfo]) -> str:
5252
"""Format to ansi
5353
5454
Args:
55+
myLice (License): project license
5556
packages (list[PackageInfo]): list of PackageCompats to format.
5657
5758
Returns:
5859
str: string to send to specified output in ansi format
5960
"""
60-
if len(packages) == 0:
61-
return "No packages"
62-
6361
string = StringIO()
6462

6563
console = Console(file=string, color_system="truecolor")
6664

65+
table = Table(title="\nInfo")
66+
table.add_column("Item", style="cyan")
67+
table.add_column("Value", style="magenta")
68+
_ = [table.add_row(k, v) for k, v in INFO.items()]
69+
table.add_row("project_license", printLicense(myLice))
70+
71+
console.print(table)
72+
73+
if len(packages) == 0:
74+
return f"{string.getvalue()}\nNo packages"
75+
6776
errors = [x for x in packages if x.errorCode > 0]
6877
if len(errors) > 0:
69-
table = Table(title="\nlist of errors")
78+
table = Table(title="\nList Of Errors")
7079
table.add_column("Package", style="magenta")
7180
_ = [table.add_row(x.name) for x in errors]
7281
console.print(table)
7382

74-
table = Table(title="\nlist of packages")
83+
table = Table(title="\nList Of Packages")
7584
table.add_column("Compatible", style="cyan")
7685
table.add_column("Package", style="magenta")
7786
table.add_column("License(s)", style="magenta")
@@ -84,43 +93,48 @@ def ansi(packages: list[PackageInfo]) -> str:
8493
return string.getvalue()
8594

8695

87-
def plainText(packages: list[PackageInfo]) -> str:
88-
"""Format to plain text
96+
def plainText(myLice: License, packages: list[PackageInfo]) -> str:
97+
"""Format to ansi
8998
9099
Args:
100+
myLice (License): project license
91101
packages (list[PackageInfo]): list of PackageCompats to format.
92102
93103
Returns:
94104
str: string to send to specified output in plain text format
95105
"""
96-
return stripAnsi(ansi(packages))
106+
return stripAnsi(ansi(myLice, packages))
97107

98108

99-
def markdown(packages: list[PackageInfo]) -> str:
109+
def markdown(myLice: License, packages: list[PackageInfo]) -> str:
100110
"""Format to markdown
101111
102112
Args:
113+
myLice (License): project license
103114
packages (list[PackageInfo]): list of PackageCompats to format.
104115
105116
Returns:
106117
str: string to send to specified output in markdown format
107118
"""
119+
info = "\n".join(f"- **{k}**: {v}" for k, v in INFO.items())
120+
strBuf = [f"## Info\n\n{info}\n\n## Project License\n\n{printLicense(myLice)}\n"]
121+
108122
if len(packages) == 0:
109-
return "No packages"
123+
return f"{strBuf[0]}\nNo packages"
110124

111-
strBuf = ["\n# Packages\nFind a list of packages below\n"]
125+
strBuf.append("## Packages\n\nFind a list of packages below\n")
112126
packages = sorted(packages, key=lambda i: i.name)
113127

114128
# Summary Table
115129
strBuf.append("|Compatible|Package|\n|:--|:--|")
116130
for pkg in packages:
117-
strBuf.append(f"|{pkg.licenseCompat}|{pkg.name}|")
131+
strBuf.append(f"|{'✔' if pkg.licenseCompat else '✖'}|{pkg.name}|")
118132

119133
# Details
120134
for pkg in packages:
121135
strBuf.extend(
122136
[
123-
f"\n## {pkg.namever}",
137+
f"\n### {pkg.namever}",
124138
f"\n- HomePage: {pkg.homePage}",
125139
f"- Author: {pkg.author}",
126140
f"- License: {pkg.license}",
@@ -131,27 +145,37 @@ def markdown(packages: list[PackageInfo]) -> str:
131145
return "\n".join(strBuf) + "\n"
132146

133147

134-
def raw(packages: list[PackageInfo]) -> str:
135-
"""Format to raw json
148+
def raw(myLice: License, packages: list[PackageInfo]) -> str:
149+
"""Format to json
136150
137151
Args:
152+
myLice (License): project license
138153
packages (list[PackageInfo]): list of PackageCompats to format.
139154
140155
Returns:
141156
str: string to send to specified output in raw json format
142157
"""
143-
return json.dumps({"info": INFO, "packages": [x.__dict__ for x in packages]}, indent="\t")
158+
return json.dumps(
159+
{
160+
"info": INFO,
161+
"project_license": printLicense(myLice),
162+
"packages": [x.__dict__ for x in packages],
163+
},
164+
indent="\t",
165+
)
144166

145167

146-
def rawCsv(packages: list[PackageInfo]) -> str:
147-
"""Format to raw csv
168+
def rawCsv(myLice: License, packages: list[PackageInfo]) -> str:
169+
"""Format to csv
148170
149171
Args:
172+
myLice (License): project license
150173
packages (list[PackageInfo]): list of PackageCompats to format.
151174
152175
Returns:
153176
str: string to send to specified output in raw csv format
154177
"""
178+
_ = myLice
155179
string = StringIO()
156180
writer = csv.DictWriter(string, fieldnames=list(packages[0].__dict__), lineterminator="\n")
157181
writer.writeheader()

0 commit comments

Comments
 (0)