Skip to content

Commit 5ddf881

Browse files
changed multi package licenses output
1 parent d5bbc76 commit 5ddf881

File tree

2 files changed

+42
-35
lines changed

2 files changed

+42
-35
lines changed

exasol/toolbox/nox/_dependencies.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,47 @@ def _normalize(_license: str) -> str:
5353
def is_multi_license(l):
5454
return ";" in l
5555

56-
def select_most_restrictive(l: str) -> str:
57-
licenses = [_normalize(l.strip()) for l in l.split(";")]
58-
priority = defaultdict(
59-
lambda: 9999,
60-
{
61-
"Unlicensed": 0,
62-
"BSD": 1,
63-
"MIT": 2,
64-
"MPLv2": 3,
65-
"LGPLv2": 4,
66-
"GPLv2": 5,
67-
"GPLv3": 6,
68-
},
69-
)
70-
priority_to_license = defaultdict(
71-
lambda: "Unknown", {v: k for k, v in priority.items()}
72-
)
73-
selected = max(*[priority[lic] for lic in licenses])
74-
return priority_to_license[int(selected)]
56+
def select_most_restrictive(licenses: list) -> str:
57+
_max = 0
58+
_mapping = {
59+
"Unlicensed": 0,
60+
"BSD": 1,
61+
"MIT": 2,
62+
"MPLv2": 3,
63+
"LGPLv2": 4,
64+
"GPLv2": 5,
65+
"GPLv3": 6,
66+
}
67+
for l in licenses:
68+
if l in _mapping:
69+
if _mapping[l] > _max:
70+
_max = _mapping[l]
71+
else:
72+
return "<br>".join(licenses)
73+
return _mapping[_max]
7574

7675
mapping = {
7776
"BSD License": "BSD",
7877
"MIT License": "MIT",
7978
"The Unlicensed (Unlicensed)": "Unlicensed",
8079
"Mozilla Public License 2.0 (MPL 2.0)": "MPLv2",
80+
"GNU General Public License (GPL)": "GPL",
8181
"GNU Lesser General Public License v2 (LGPLv2)": "LGPLv2",
8282
"GNU General Public License v2 (GPLv2)": "GPLv2",
83-
"GNU General Public License v2 or later(GPLv2+)": "GPLv2+",
83+
"GNU General Public License v2 or later (GPLv2+)": "GPLv2+",
8484
"GNU General Public License v3 (GPLv3)": "GPLv3",
8585
"Apache Software License": "Apache",
8686
}
8787

8888
if is_multi_license(_license):
89-
return select_most_restrictive(_license)
89+
items = []
90+
for item in _license.split(";"):
91+
item = str(item).strip()
92+
if item in mapping:
93+
items.append(mapping[item])
94+
else:
95+
items.append(item)
96+
return select_most_restrictive(items)
9097

9198
if _license not in mapping:
9299
return _license

poetry.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)