From 073195f96d84a5f6c8d40484524c129d9a43be8f Mon Sep 17 00:00:00 2001 From: Yoav Kleinberger Date: Mon, 25 Nov 2024 20:14:19 +0200 Subject: [PATCH] fix loggingcase --- .pre-commit-config.yaml | 10 +++++++++- .pre-commit-hooks.yaml | 8 +++++++- foxylint/main.py | 41 ++++++++++++++++++++++++++++++++++------- pyproject.toml | 4 ++-- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13425c8..844feb2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,13 +32,21 @@ repos: - id: foxylint-imports name: Import Modules not Names description: disallows the from_x_import_y import statement - entry: foxylint-imports + entry: foxylint-main imports language: python types: [python] args: - "--exclude=tests/fixtures/*.py" - "--exclude=pre-commit-sentinels/**/*.py" - "--accept=/from mylogging/" + - id: foxylint-loggingcase + name: Enforce lowercase logging + description: do not capitalize sentences in log messages like you would in ordinary English + entry: foxylint-main loggingcase + language: python + types: [python] + args: + - "--exclude=tests/fixtures/*.py" - id: yaml-not-yml name: YAML files must end with .yaml description: disallows the .yml suffix, allows only .yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 2f993d2..fcd48dc 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,7 +1,13 @@ - id: foxylint-imports name: Import Modules not Names description: disallows the from_x_import_y import statement - entry: foxylint-imports + entry: foxylint-main imports + language: python + types: [python] +- id: foxylint-loggingcase + name: Enforce lowercase logging + description: do not capitalize sentences in log messages like you would in ordinary English + entry: foxylint-main loggingcase language: python types: [python] - id: yaml-not-yml diff --git a/foxylint/main.py b/foxylint/main.py index c05d57e..2972707 100644 --- a/foxylint/main.py +++ b/foxylint/main.py @@ -2,6 +2,7 @@ import os import glob import foxylint.imports +import foxylint.loggingcase def red(text): @@ -12,11 +13,7 @@ def bold(text): return click.secho(text, fg='white', bold=True) -@click.command() -@click.argument('files', nargs=-1, type=click.Path()) -@click.option('--exclude', '-e', multiple=True) -@click.option('--accept', multiple=True) -def main(files, exclude, accept): +def _find_files(files, exclude): excluded = [] for pattern in exclude: excluded.extend(glob.glob(pattern, recursive=True)) @@ -29,8 +26,10 @@ def main(files, exclude, accept): if os.path.abspath(file) not in excluded: files.append(file) - accept = [pattern.strip('/') for pattern in accept] - findings = foxylint.imports.analyze(files, acceptable_patterns=accept) + return files + + +def _show_findings(findings): bad_files = 0 for file, analysis in findings.items(): if analysis['ok']: @@ -45,3 +44,31 @@ def main(files, exclude, accept): quit(1) else: quit(0) + + +@click.group() +@click.pass_context +def main(context): + pass + + +@main.command() +@click.pass_context +@click.argument('files', nargs=-1, type=click.Path()) +@click.option('--exclude', '-e', multiple=True) +@click.option('--accept', multiple=True) +def imports(context, files, exclude, accept): + files = _find_files(files, exclude) + accept = [pattern.strip('/') for pattern in accept] + findings = foxylint.imports.analyze(files, acceptable_patterns=accept) + _show_findings(findings) + + +@main.command() +@click.pass_context +@click.argument('files', nargs=-1, type=click.Path()) +@click.option('--exclude', '-e', multiple=True) +def loggingcase(context, files, exclude): + files = _find_files(files, exclude=exclude) + findings = foxylint.loggingcase.analyze(files) + _show_findings(findings) diff --git a/pyproject.toml b/pyproject.toml index 2589838..dcfb312 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "foxylint" -version = "1.2.0" +version = "1.3.0" description = "" authors = ["Yoav Kleinberger "] license = "MIT" @@ -23,5 +23,5 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.scripts] -foxylint-imports = 'foxylint.main:main' +foxylint-main = 'foxylint.main:main' foxylint-noyml = 'foxylint.noyml:main'