Skip to content

Commit 604c466

Browse files
committed
add --show-only-failing and --pypi-api, refactor fmt packageinfo
1 parent 56577f1 commit 604c466

File tree

17 files changed

+545
-571
lines changed

17 files changed

+545
-571
lines changed

licensecheck/cli.py

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

1313
from fhconfparser import FHConfParser, SimpleConf
1414

15-
from licensecheck import formatter, get_deps, license_matrix, packageinfo, types
15+
from licensecheck import fmt, get_deps, packageinfo, types
16+
from licensecheck import license_matrix
1617

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

@@ -23,12 +24,13 @@ def cli() -> None: # pragma: no cover
2324
parser.add_argument(
2425
"--license",
2526
"-l",
26-
help="",
27+
help="Specify the project license explicitly, rather than rely on "
28+
"licensecheck interpreting this from pyproject.toml",
2729
)
2830
parser.add_argument(
2931
"--format",
3032
"-f",
31-
help=f"Output format. one of: {', '.join(list(formatter.formatMap))}. default=simple",
33+
help=f"Output format. one of: {', '.join(list(fmt.formatMap))}. default=simple",
3234
)
3335
parser.add_argument(
3436
"--requirements-paths",
@@ -45,47 +47,57 @@ def cli() -> None: # pragma: no cover
4547
parser.add_argument(
4648
"--file",
4749
"-o",
48-
help="Filename to write to (omit for stdout)",
50+
help="Filename to write output to (omit this for stdout)",
4951
)
5052
parser.add_argument(
5153
"--ignore-packages",
52-
help="a list of packages to ignore (compat=True)",
54+
help="List of packages/dependencies to ignore (compat=True)",
5355
nargs="+",
5456
)
5557
parser.add_argument(
5658
"--fail-packages",
57-
help="a list of packages to fail (compat=False)",
59+
help="List of packages/dependencies to fail (compat=False)",
5860
nargs="+",
5961
)
6062
parser.add_argument(
6163
"--ignore-licenses",
62-
help="a list of licenses to ignore (skipped, compat may still be False)",
64+
help="List of licenses to ignore (skipped, compat may still be False)",
6365
nargs="+",
6466
)
6567
parser.add_argument(
6668
"--fail-licenses",
67-
help="a list of licenses to fail (compat=False)",
69+
help="List of licenses to fail (compat=False)",
6870
nargs="+",
6971
)
7072
parser.add_argument(
7173
"--only-licenses",
72-
help="a list of allowed licenses (any other license will fail)",
74+
help="List of allowed licenses (packages/dependencies with any other license will fail)",
7375
nargs="+",
7476
)
7577
parser.add_argument(
7678
"--skip-dependencies",
77-
help="a list of packages to skip (compat=True)",
79+
help="List of packages/dependencies to skip (this sets the 'compatability' to True)",
7880
nargs="+",
7981
)
8082
parser.add_argument(
8183
"--hide-output-parameters",
82-
help="a list of parameters to hide from the produced output",
84+
help="List of parameters to hide from the produced output",
8385
nargs="+",
8486
)
87+
parser.add_argument(
88+
"--show-only-failing",
89+
help="Only output a list of incompatible/ failing packages from this lib",
90+
action="store_true",
91+
)
92+
parser.add_argument(
93+
"--pypi-api",
94+
help="Specify a custom pypi api endpoint, for example if using a custom pypi server",
95+
default="https://pypi.org/pypi/",
96+
)
8597
parser.add_argument(
8698
"--zero",
8799
"-0",
88-
help="Return non zero exit code if an incompatible license is found",
100+
help="Return non zero exit code if an incompatible license is found, ideal for CI/CD",
89101
action="store_true",
90102
)
91103
args = vars(parser.parse_args())
@@ -98,7 +110,7 @@ def cli() -> None: # pragma: no cover
98110
sysexit(ec)
99111

100112

101-
def main(args: dict) -> int:
113+
def main(args: dict| argparse.Namespace) -> int:
102114
"""Test entry point.
103115
104116
Note: FHConfParser (Parses in the following order: `pyproject.toml`,
@@ -138,10 +150,13 @@ def main(args: dict) -> int:
138150
def getFromConfig(key: str) -> list[types.ucstr]:
139151
return list(map(types.ucstr, simpleConf.get(key, [])))
140152

153+
package_info_manager = packageinfo.PackageInfoManager(simpleConf.get("pypi_api"))
154+
141155
incompatible, depsWithLicenses = get_deps.check(
142156
requirements_paths=requirements_paths,
143157
groups=simpleConf.get("groups", []),
144158
this_license=this_license,
159+
package_info_manager=package_info_manager,
145160
ignore_packages=getFromConfig("ignore_packages"),
146161
fail_packages=getFromConfig("fail_packages"),
147162
ignore_licenses=getFromConfig("ignore_licenses"),
@@ -159,12 +174,14 @@ def getFromConfig(key: str) -> list[types.ucstr]:
159174
f"Valid parameters are: {', '.join(available_params)}"
160175
)
161176
raise ValueError(msg)
162-
if simpleConf.get("format", "simple") in formatter.formatMap:
177+
if simpleConf.get("format", "simple") in fmt.formatMap:
163178
print(
164-
formatter.formatMap[simpleConf.get("format", "simple")](
179+
fmt.fmt(
180+
simpleConf.get("format", "simple"),
165181
this_license,
166182
sorted(depsWithLicenses),
167183
hide_output_parameters,
184+
show_only_failing=args.get("show_only_failing", False),
168185
),
169186
file=output_file,
170187
)

0 commit comments

Comments
 (0)