diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c813a3..5b45aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,10 @@ All major and minor version changes will be documented in this file. Details of patch-level version changes can be found in [commit messages](../../commits/master). -## 2021.4 +## 2021.4.1 - 2021/09/07 +- Command-line options take precedent over config options as expected + +## 2021.4 - 2021/09/07 - Add config file functionality per https://github.com/FHPythonUtils/LicenseCheck/issues/11 - Parsed in the following order: `pyproject.toml`, `setup.cfg`, `licensecheck.toml`, `licensecheck.json`, `licensecheck.ini`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini` - Note that the config takes precedent over command-line options diff --git a/README.md b/README.md index 47f7f18..293b58d 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,6 @@ Configuration files are parsed in the following order: `pyproject.toml`, `~/licensecheck.toml`, `~/licensecheck.json`, `~/licensecheck.ini` - ⚠ All config files are parsed, however configuration defined in previous files takes precedent -- ⚠ Note, however, that the config takes precedent over command-line options Add optional path to requirements.txt as outlined in https://github.com/FHPythonUtils/LicenseCheck/issues/9#issuecomment-898878228 diff --git a/licensecheck/__init__.py b/licensecheck/__init__.py index dd05d19..6b97d8c 100644 --- a/licensecheck/__init__.py +++ b/licensecheck/__init__.py @@ -7,7 +7,7 @@ from pathlib import Path from sys import exit as sysexit, stdout -from fhconfparser import FHConfParser +from fhconfparser import FHConfParser, SimpleConf from licensecheck import formatter, get_deps @@ -17,7 +17,7 @@ def cli() -> None: """Cli entry point.""" exitCode = 0 - parser = argparse.ArgumentParser(description=__doc__) + parser = argparse.ArgumentParser(description=__doc__, argument_default=argparse.SUPPRESS) parser.add_argument( "--format", "-f", @@ -37,19 +37,21 @@ def cli() -> None: "--ignore-packages", help="a list of packages to ignore (compat=True)", nargs="+", - default=[], ) parser.add_argument( - "--fail-packages", help="a list of packages to fail (compat=False)", nargs="+", default=[] + "--fail-packages", + help="a list of packages to fail (compat=False)", + nargs="+", ) parser.add_argument( "--ignore-licenses", help="a list of licenses to ignore (skipped, compat may still be False)", nargs="+", - default=[], ) parser.add_argument( - "--fail-licenses", help="a list of licenses to fail (compat=False)", nargs="+", default=[] + "--fail-licenses", + help="a list of licenses to fail (compat=False)", + nargs="+", ) parser.add_argument( "--zero", @@ -57,7 +59,6 @@ def cli() -> None: help="Return non zero exit code if an incompatible license is found", action="store_true", ) - # yapf: enable args = vars(parser.parse_args()) # ConfigParser (Parses in the following order: `pyproject.toml`, @@ -74,35 +75,31 @@ def cli() -> None: ["tool"], ["tool"], ) - - # Function to read the config and fall back the the command-line - conf = lambda option: configparser.get("licensecheck", option) or args[option] + sc = SimpleConf(configparser, "licensecheck", args) # File - filename = stdout if conf("file") is None else open(conf("file"), "w") + filename = stdout if sc.get("file") is None else open(sc.get("file"), "w") # Get list of licenses dependenciesWLicenses = get_deps.getDepsWLicenses( - conf("using"), - conf("ignore_packages"), - conf("fail_packages"), - conf("ignore_licenses"), - conf("fail_licenses"), + sc.get("using", "poetry"), + sc.get("ignore_packages", []), + sc.get("fail_packages", []), + sc.get("ignore_licenses", []), + sc.get("fail_licenses", []), ) # Are any licenses incompatible? incompatible = any(not lice["license_compat"] for lice in dependenciesWLicenses) # Format the results - if conf("format") is None: - print(formatter.simple(dependenciesWLicenses), file=filename) - elif conf("format") in formatter.formatMap: - print(formatter.formatMap[conf("format")](dependenciesWLicenses), file=filename) + if sc.get("format", "simple") in formatter.formatMap: + print(formatter.formatMap[sc.get("format", "simple")](dependenciesWLicenses), file=filename) else: exitCode = 2 # Exit code of 1 if args.zero - if conf("zero") and incompatible: + if sc.get("zero", False) and incompatible: exitCode = 1 # Cleanup + exit diff --git a/licensecheck/get_deps.py b/licensecheck/get_deps.py index 84fefbb..da64bce 100644 --- a/licensecheck/get_deps.py +++ b/licensecheck/get_deps.py @@ -47,7 +47,7 @@ def getReqs(using: str) -> list[str]: Returns: list[str]: list of requirement packages """ - _ = str(using).split(":", 1) + _ = using.split(":", 1) using, reqsTxts = _[0], _[1] if len(_) > 1 else "requirements.txt" if using not in usings: using = "poetry" diff --git a/pyproject.toml b/pyproject.toml index 2988dfb..bacdd15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "licensecheck" -version = "2021.4" +version = "2021.4.1" description = "Output the licenses used by dependencies and check if these are compatible with the project license" authors = ["FredHappyface"] classifiers = [ @@ -37,7 +37,7 @@ requests = "<4,>=2.24.0" metprint = "<2022,>=2020.7.1" pip = "<22,>=20.2.3" tomlkit = "<2,>=0.7.0" -fhconfparser = "<2023,>=2021" +fhconfparser = "<2023,>=2021.1.1" [tool.poetry.extras] full = ["metprint"] diff --git a/requirements.txt b/requirements.txt index fe73a31..069b398 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -fhconfparser<2023,>=2021 +fhconfparser<2023,>=2021.1.1 metprint<2022,>=2020.7.1 pip<22,>=20.2.3 requests<4,>=2.24.0 diff --git a/requirements_optional.txt b/requirements_optional.txt index fe73a31..069b398 100644 --- a/requirements_optional.txt +++ b/requirements_optional.txt @@ -1,4 +1,4 @@ -fhconfparser<2023,>=2021 +fhconfparser<2023,>=2021.1.1 metprint<2022,>=2020.7.1 pip<22,>=20.2.3 requests<4,>=2.24.0