Skip to content

Commit

Permalink
2021.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Sep 7, 2021
1 parent 6ddf4eb commit 7539b06
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 28 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 18 additions & 21 deletions licensecheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -37,27 +37,28 @@ 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",
"-0",
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`,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion licensecheck/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_optional.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7539b06

Please sign in to comment.