diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 59c5845..0000000 --- a/.coveragerc +++ /dev/null @@ -1,8 +0,0 @@ -[run] -source = fillname - tests -omit = */fillname/__main__.py -[report] -exclude_lines = - assert - nocoverage diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5accb48..7442528 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -23,10 +23,10 @@ jobs: - name: "checkout repository" uses: actions/checkout@v3 - - name: "setup python 3.7" + - name: "setup python 3.9" uses: actions/setup-python@v4 with: - python-version: 3.7 + python-version: 3.9 - name: "setup python 3.11" uses: actions/setup-python@v4 diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index f238bf7..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[settings] -profile = black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dce9820..f7b3229 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,6 @@ repos: rev: 5.11.5 hooks: - id: isort - args: ["--profile", "black"] exclude: ^.github/ - repo: https://github.com/psf/black diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index 82e3aa7..0000000 --- a/.pylintrc +++ /dev/null @@ -1,31 +0,0 @@ -[FORMAT] - -max-line-length=120 - -[DESIGN] - -max-args=10 -max-attributes=7 -max-bool-expr=5 -max-branches=12 -max-locals=30 -max-parents=7 -max-public-methods=20 -max-returns=10 -max-statements=50 -min-public-methods=1 - -[SIMILARITIES] - -ignore-comments=yes -ignore-docstrings=yes -ignore-imports=yes -ignore-signatures=yes - -[BASIC] - -argument-rgx=^[a-z][a-z0-9]*((_[a-z0-9]+)*_?)?$ -variable-rgx=^[a-z][a-z0-9]*((_[a-z0-9]+)*_?)?$ - -# Good variable names which should always be accepted, separated by a comma. -good-names=_,M,N,B,A,Nn,Bn,An diff --git a/init.py b/init.py index 005bc2a..cdcd0bb 100755 --- a/init.py +++ b/init.py @@ -45,14 +45,14 @@ def replace(filepath): dirs = [os.path.join("src", "fillname"), "tests", "doc"] files = [ - "setup.cfg", + ".pre-commit-config.yaml", "noxfile.py", + "pyproject.toml", + "setup.cfg", "CONTRIBUTING.md", - "README.md", "DEVELOPMENT.md", "LICENSE", - ".pre-commit-config.yaml", - ".coveragerc", + "README.md", ] for rootpath in dirs: diff --git a/noxfile.py b/noxfile.py index 22ee944..4d28f0c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,12 +2,12 @@ import nox -nox.options.sessions = "lint_flake8", "lint_pylint", "typecheck", "test" +nox.options.sessions = "lint_pylint", "typecheck", "test" EDITABLE_TESTS = True PYTHON_VERSIONS = None if "GITHUB_ACTIONS" in os.environ: - PYTHON_VERSIONS = ["3.7", "3.11"] + PYTHON_VERSIONS = ["3.9", "3.11"] EDITABLE_TESTS = False @@ -90,15 +90,6 @@ def dev(session): session.install("-e", ".[dev]") -@nox.session -def lint_flake8(session): - """ - Run flake8 linter. - """ - session.install("-e", ".[lint_flake8]") - session.run("flake8", "src", "tests") - - @nox.session def lint_pylint(session): """ @@ -114,7 +105,7 @@ def typecheck(session): Typecheck the code using mypy. """ session.install("-e", ".[typecheck]") - session.run("mypy", "-p", "fillname", "-p", "tests") + session.run("mypy", "--strict", "-p", "fillname", "-p", "tests") @nox.session(python=PYTHON_VERSIONS) diff --git a/pyproject.toml b/pyproject.toml index d214b53..74e9cab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,43 @@ requires = [ "setuptools-scm", ] build-backend = "setuptools.build_meta" + +[tool.isort] +profile = "black" +line_length = 120 + +[tool.black] +line-length = 120 + +[tool.pylint.format] +max-line-length = 120 + +[tool.pylint.design] +max-args = 10 +max-attributes = 7 +max-bool-expr = 5 +max-branches = 12 +max-locals = 30 +max-parents = 7 +max-public-methods = 20 +max-returns = 10 +max-statements = 50 +min-public-methods = 1 + +[tool.pylint.similarities] +ignore-comments = true +ignore-docstrings = true +ignore-imports = true +ignore-signatures = true + +[tool.pylint.basic] +argument-rgx = "^[a-z][a-z0-9]*((_[a-z0-9]+)*_?)?$" +variable-rgx = "^[a-z][a-z0-9]*((_[a-z0-9]+)*_?)?$" +good-names = ["_"] + +[tool.coverage.run] +source = ["fillname", "tests"] +omit = ["*/fillname/__main__.py"] + +[tool.coverage.report] +exclude_lines = ["assert", "nocoverage"] diff --git a/setup.cfg b/setup.cfg index b80a8bf..4b10be2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,9 +13,8 @@ url = https://potassco.org/ packages = find: package_dir = =src +python_requires = >=3.9 include_package_data = True -install_requires = - importlib_metadata;python_version<'3.8' [options.packages.find] where = src @@ -25,17 +24,13 @@ format = black isort autoflake -lint_flake8 = - flake8 - flake8-black - flake8-isort lint_pylint = pylint typecheck = types-setuptools mypy test = - coverage + coverage[toml] doc = sphinx furo @@ -43,7 +38,7 @@ doc = sphinx_copybutton myst-parser dev = - fillname[test,typecheck,lint_pylint,lint_flake8] + fillname[test,typecheck,lint_pylint] [options.entry_points] console_scripts = diff --git a/src/fillname/__main__.py b/src/fillname/__main__.py index 13ea26c..5f48055 100644 --- a/src/fillname/__main__.py +++ b/src/fillname/__main__.py @@ -6,7 +6,7 @@ from .utils.parser import get_parser -def main(): +def main() -> None: """ Run the main function. """ diff --git a/src/fillname/utils/logger.py b/src/fillname/utils/logger.py index 5861879..a729a72 100644 --- a/src/fillname/utils/logger.py +++ b/src/fillname/utils/logger.py @@ -20,19 +20,22 @@ class SingleLevelFilter(logging.Filter): Filter levels. """ - def __init__(self, passlevel, reject): + passlevel: int + reject: bool + + def __init__(self, passlevel: int, reject: bool): # pylint: disable=super-init-not-called self.passlevel = passlevel self.reject = reject - def filter(self, record): + def filter(self, record: logging.LogRecord) -> bool: if self.reject: return record.levelno != self.passlevel # nocoverage return record.levelno == self.passlevel -def setup_logger(name, level): +def setup_logger(name: str, level: int) -> logging.Logger: """ Setup logger. """ @@ -42,13 +45,11 @@ def setup_logger(name, level): logger.setLevel(level) log_message_str = "{}%(levelname)s:{} - %(message)s{}" - def set_handler(level, color): + def set_handler(level: int, color: str) -> None: handler = logging.StreamHandler(sys.stderr) handler.addFilter(SingleLevelFilter(level, False)) handler.setLevel(level) - formatter = logging.Formatter( - log_message_str.format(COLORS[color], COLORS["GREY"], COLORS["NORMAL"]) - ) + formatter = logging.Formatter(log_message_str.format(COLORS[color], COLORS["GREY"], COLORS["NORMAL"])) handler.setFormatter(formatter) logger.addHandler(handler) diff --git a/src/fillname/utils/parser.py b/src/fillname/utils/parser.py index 8cde3d8..ad8e215 100644 --- a/src/fillname/utils/parser.py +++ b/src/fillname/utils/parser.py @@ -6,7 +6,7 @@ import sys from argparse import ArgumentParser from textwrap import dedent -from typing import Any, cast +from typing import Any, Optional, cast __all__ = ["get_parser"] @@ -39,7 +39,7 @@ def get_parser() -> ArgumentParser: ("debug", logging.DEBUG), ] - def get(levels, name): + def get(levels: list[tuple[str, int]], name: str) -> Optional[int]: for key, val in levels: if key == name: return val @@ -54,7 +54,5 @@ def get(levels, name): type=cast(Any, lambda name: get(levels, name)), ) - parser.add_argument( - "--version", "-v", action="version", version=f"%(prog)s {VERSION}" - ) + parser.add_argument("--version", "-v", action="version", version=f"%(prog)s {VERSION}") return parser diff --git a/tests/test_main.py b/tests/test_main.py index b1e7f19..c9dca4d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -15,18 +15,19 @@ class TestMain(TestCase): Test cases for main application functionality. """ - def test_logger(self): + def test_logger(self) -> None: """ Test the logger. """ log = setup_logger("global", logging.INFO) sio = StringIO() for handler in log.handlers: + assert isinstance(handler, logging.StreamHandler) handler.setStream(sio) log.info("test123") self.assertRegex(sio.getvalue(), "test123") - def test_parser(self): + def test_parser(self) -> None: """ Test the parser. """