From 0c83218e1ad22a166082b0e2f95fe7eba57857f5 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Sun, 19 Sep 2021 17:54:24 +0300 Subject: [PATCH] A few fixes from the improved tests. - Add the hooks package. - Refactor and fix the bulk_check function. --- hooks/terraform_validate.py | 37 ++++++++++++++++++------------------- hooks/utils.py | 2 +- setup.py | 3 ++- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/hooks/terraform_validate.py b/hooks/terraform_validate.py index abf921e..2615728 100644 --- a/hooks/terraform_validate.py +++ b/hooks/terraform_validate.py @@ -7,24 +7,23 @@ import sys import hooks.utils -def checker(): - def check(directory): - if ( - hooks.utils.check( - ["terraform", "init", "-backend=false"], directory=directory - ) - > 0 - ): - return 1 - if ( - hooks.utils.check(["terraform", "validate"], directory=directory) - > 0 - ): - return 1 - - return 0 - - return check +def tf_validate(directory): + if ( + hooks.utils.check_directory( + ["terraform", "init", "-backend=false"], directory=directory + ) + > 0 + ): + return 1 + if ( + hooks.utils.check_directory( + ["terraform", "validate"], directory=directory + ) + > 0 + ): + return 1 + + return 0 def main(): @@ -36,7 +35,7 @@ def main(): os.putenv("TF_INPUT", "0") os.putenv("TF_IN_AUTOMATION", "1") return hooks.utils.bulk_check( - checker, hooks.utils.unique_directories(args.file) + tf_validate, hooks.utils.unique_directories(args.file) ) diff --git a/hooks/utils.py b/hooks/utils.py index b88db64..ef4a3f4 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -85,6 +85,6 @@ def bulk_check(checker, items): returncode = 0 for item in items: check = checker(item) - if check() > 0: + if check > 0: returncode = 1 return returncode diff --git a/setup.py b/setup.py index ae225c3..c8959d7 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import setup +from setuptools import setup, find_packages with open("VERSION", "r", encoding="utf-8") as fh: VERSION = fh.read().strip() @@ -23,4 +23,5 @@ setup( "poetry-check=hook.poetry_check:main", ] }, + packages=find_packages(), ) -- GitLab