Skip to content

Commit fd87806

Browse files
added license output to github report
1 parent 99a1489 commit fd87806

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

.github/workflows/report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
run: |
5252
echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY
5353
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
54+
poetry run nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY
5455
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
5556
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
5657
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.lint.json
22
.lint.txt
33
.security.json
4-
.packages.json
54

65
odbcconfig/odbcinst.ini
76

doc/changes/unreleased.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@
88

99
## 🔩 Internal
1010
* Relocked dependencies
11-
* Update referenced github actions
11+
* Update referenced github actions
12+
13+
## ✨ Added
14+
* Added a Nox task for dependencies packages and their licenses with Markdown output

exasol/toolbox/nox/_dependencies.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import subprocess
4+
import tempfile
35
from collections import defaultdict
46
from dataclasses import dataclass
57
from inspect import cleandoc
@@ -47,23 +49,11 @@ def _dependencies(toml_str: str) -> dict[str, list]:
4749
return dependencies
4850

4951

50-
def _licenses(session: Session, filename: str) -> None:
51-
session.run(
52-
"poetry",
53-
"run",
54-
"pip-licenses",
55-
"--format=json",
56-
"--output-file=" + filename,
57-
"--with-system",
58-
"--with-urls",
59-
)
60-
61-
6252
def _normalize(_license: str) -> str:
6353
def is_multi_license(l):
6454
return ";" in l
6555

66-
def select_most_permissive(l: str) -> str:
56+
def select_most_restrictive(l: str) -> str:
6757
licenses = [_normalize(l.strip()) for l in l.split(";")]
6858
priority = defaultdict(
6959
lambda: 9999,
@@ -74,12 +64,13 @@ def select_most_permissive(l: str) -> str:
7464
"MPLv2": 3,
7565
"LGPLv2": 4,
7666
"GPLv2": 5,
67+
"GPLv3": 6,
7768
},
7869
)
7970
priority_to_license = defaultdict(
8071
lambda: "Unknown", {v: k for k, v in priority.items()}
8172
)
82-
selected = min(*[priority[lic] for lic in licenses])
73+
selected = max(*[priority[lic] for lic in licenses])
8374
return priority_to_license[int(selected)]
8475

8576
mapping = {
@@ -93,7 +84,7 @@ def select_most_permissive(l: str) -> str:
9384
}
9485

9586
if is_multi_license(_license):
96-
return select_most_permissive(_license)
87+
return select_most_restrictive(_license)
9788

9889
if _license not in mapping:
9990
return _license
@@ -117,6 +108,23 @@ def _packages_from_json(json: str) -> list[Package]:
117108
return packages_list
118109

119110

111+
def _licenses() -> list[Package]:
112+
file = tempfile.NamedTemporaryFile()
113+
subprocess.run(
114+
[
115+
"poetry",
116+
"run",
117+
"pip-licenses",
118+
"--format=json",
119+
"--output-file=" + file.name,
120+
"--with-system",
121+
"--with-urls",
122+
],
123+
capture_output=True,
124+
)
125+
return _packages_from_json(file.read().decode())
126+
127+
120128
def _packages_to_markdown(
121129
dependencies: dict[str, list], packages: list[Package]
122130
) -> str:
@@ -183,7 +191,5 @@ def dependency_licenses(session: Session) -> None:
183191
"""returns the packages and their licenses"""
184192
toml = Path("pyproject.toml")
185193
dependencies = _dependencies(toml.read_text())
186-
_licenses(session=session, filename=".packages.json")
187-
json = Path(".packages.json").read_text()
188-
package_infos = _packages_from_json(json)
194+
package_infos = _licenses()
189195
print(_packages_to_markdown(dependencies=dependencies, packages=package_infos))

exasol/toolbox/templates/github/workflows/report.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
run: |
4949
echo -e "# Summary\n" >> $GITHUB_STEP_SUMMARY
5050
poetry run nox -s project:report -- -- --format markdown >> $GITHUB_STEP_SUMMARY
51+
poetry run nox -s dependency:licenses >> $GITHUB_STEP_SUMMARY
5152
echo -e "\n\n# Coverage\n" >> $GITHUB_STEP_SUMMARY
5253
poetry run coverage report -- --format markdown >> $GITHUB_STEP_SUMMARY
5354
echo -e "\n\n# Static Code Analysis\n" >> $GITHUB_STEP_SUMMARY

test/unit/dependencies_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@ def test_dependencies(toml, expected):
4444
@pytest.mark.parametrize(
4545
"licenses,expected",
4646
[
47-
("BSD License; MIT License;", "BSD"),
48-
("MIT License; Mozilla Public License 2.0 (MPL 2.0)", "MIT"),
47+
("The Unlicensed (Unlicensed); BSD License", "BSD"),
48+
("BSD License; MIT License", "MIT"),
49+
("MIT License; Mozilla Public License 2.0 (MPL 2.0)", "MPLv2"),
4950
(
5051
"Mozilla Public License 2.0 (MPL 2.0); GNU Lesser General Public License v2 (LGPLv2)",
51-
"MPLv2",
52+
"LGPLv2",
5253
),
5354
(
5455
"GNU Lesser General Public License v2 (LGPLv2); GNU General Public License v2 (GPLv2)",
55-
"LGPLv2",
56+
"GPLv2",
5657
),
5758
(
5859
"GNU General Public License v2 (GPLv2); GNU General Public License v3 (GPLv3)",
59-
"GPLv2",
60+
"GPLv3",
6061
),
6162
],
6263
)

0 commit comments

Comments
 (0)