Skip to content

Commit 626b638

Browse files
committed
update myLice logic to be less intertwined
1 parent cb0604d commit 626b638

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

licensecheck/cli.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from fhconfparser import FHConfParser, SimpleConf
1414

15-
from licensecheck import formatter, get_deps, license_matrix, types
15+
from licensecheck import formatter, get_deps, license_matrix, packageinfo, types
1616

1717
stdout.reconfigure(encoding="utf-8") # type: ignore[general-type-issues]
1818

@@ -116,9 +116,14 @@ def main(args: dict) -> int:
116116
else Path(simpleConf.get("file")).open("w", encoding="utf-8")
117117
)
118118

119+
# Get my license
120+
myLiceTxt = args["license"] if args.get("license") else packageinfo.getMyPackageLicense()
121+
myLice = license_matrix.licenseType(myLiceTxt)[0]
122+
119123
# Get list of licenses
120-
myLice, depsWithLicenses = get_deps.getDepsWithLicenses(
124+
depsWithLicenses = get_deps.getDepsWithLicenses(
121125
simpleConf.get("using", "poetry"),
126+
myLice,
122127
list(map(types.ucstr, simpleConf.get("ignore_packages", []))),
123128
list(map(types.ucstr, simpleConf.get("fail_packages", []))),
124129
list(map(types.ucstr, simpleConf.get("ignore_licenses", []))),
@@ -127,8 +132,6 @@ def main(args: dict) -> int:
127132
list(map(types.ucstr, simpleConf.get("skip_dependencies", []))),
128133
)
129134

130-
myLice = license_matrix.licenseType(args["license"])[0] if args.get("license") else myLice
131-
132135
# Are any licenses incompatible?
133136
incompatible = any(not lice.licenseCompat for lice in depsWithLicenses)
134137

licensecheck/get_deps.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,20 @@ def getReqs(using: str, skipDependencies: list[ucstr]) -> set[ucstr]:
7474

7575
def getDepsWithLicenses(
7676
using: str,
77+
myLice: License,
7778
ignorePackages: list[ucstr],
7879
failPackages: list[ucstr],
7980
ignoreLicenses: list[ucstr],
8081
failLicenses: list[ucstr],
8182
onlyLicenses: list[ucstr],
8283
skipDependencies: list[ucstr],
83-
) -> tuple[License, set[PackageInfo]]:
84+
) -> set[PackageInfo]:
8485
"""Get a set of dependencies with licenses and determine license compatibility.
8586
8687
Args:
8788
----
8889
using (str): use requirements or poetry
90+
myLice (License): user license
8991
ignorePackages (list[ucstr]): a list of packages to ignore (compat=True)
9092
failPackages (list[ucstr]): a list of packages to fail (compat=False)
9193
ignoreLicenses (list[ucstr]): a list of licenses to ignore (skipped, compat may still be
@@ -103,9 +105,6 @@ def getDepsWithLicenses(
103105
"""
104106
reqs = getReqs(using, skipDependencies)
105107

106-
# Get my license
107-
myLiceTxt = packageinfo.getMyPackageLicense()
108-
myLice = license_matrix.licenseType(myLiceTxt)[0]
109108
ignoreLicensesType = license_matrix.licenseType(
110109
ucstr(JOINS.join(ignoreLicenses)), ignoreLicenses
111110
)
@@ -125,7 +124,7 @@ def getDepsWithLicenses(
125124
package.licenseCompat = True
126125
elif packageName in failPackages:
127126
pass # package.licenseCompat = False
128-
# Old behaviour
127+
# Else get compat with myLice
129128
else:
130129
package.licenseCompat = license_matrix.depCompatWMyLice(
131130
myLice,
@@ -134,4 +133,4 @@ def getDepsWithLicenses(
134133
failLicensesType,
135134
onlyLicensesType,
136135
)
137-
return myLice, packages
136+
return packages

tests/data/test_main_tc4_expected.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
"homePage": "https://requests.readthedocs.io",
132132
"author": "Kenneth Reitz",
133133
"license": "APACHE SOFTWARE LICENSE",
134-
"licenseCompat": true,
134+
"licenseCompat": false,
135135
"errorCode": 0
136136
},
137137
{
@@ -147,7 +147,7 @@
147147
"homePage": "https://github.com/madpah/requirements-parser/#readme",
148148
"author": "Paul Horton",
149149
"license": "APACHE SOFTWARE LICENSE",
150-
"licenseCompat": true,
150+
"licenseCompat": false,
151151
"errorCode": 0
152152
},
153153
{
@@ -179,7 +179,7 @@
179179
"homePage": "https://github.com/python/typeshed",
180180
"author": "UNKNOWN",
181181
"license": "APACHE SOFTWARE LICENSE",
182-
"licenseCompat": true,
182+
"licenseCompat": false,
183183
"errorCode": 0
184184
},
185185
{

0 commit comments

Comments
 (0)