From c991ca9eaa1bff1711936899751d03231dd00b50 Mon Sep 17 00:00:00 2001 From: cytopia Date: Sun, 27 Nov 2022 16:28:40 +0100 Subject: [PATCH] Adjust code to linting --- .ansible/bin/Makefile | 2 ++ .ansible/bin/get-modules.py | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.ansible/bin/Makefile b/.ansible/bin/Makefile index 74c1a89..d3182a7 100644 --- a/.ansible/bin/Makefile +++ b/.ansible/bin/Makefile @@ -23,5 +23,7 @@ PYLINT_DIR = get-modules.py PYLINT_PIP_PKGS = yamllint PYLINT_ARGS = --disable=invalid-name get-modules.py +PYCODE_ARGS = --max-line-length=100 + BLACK_LINT_ARGS = -l 100 --check --diff BLACK_FIX_ARGS = -l 100 diff --git a/.ansible/bin/get-modules.py b/.ansible/bin/get-modules.py index 94d33b3..815f550 100755 --- a/.ansible/bin/get-modules.py +++ b/.ansible/bin/get-modules.py @@ -32,6 +32,13 @@ def get_el_by_name(items: List[Dict[str, Any]], name: str) -> Dict[str, Any]: sys.exit(1) +def load_yaml(path: str) -> Dict[str, Any]: + """Load yaml file and return its dict().""" + with open(path, encoding="utf8") as fp: + data = yaml.safe_load(fp) + return data + + # -------------------------------------------------------------------------------------------------- # MODULE FUNCTIONS # -------------------------------------------------------------------------------------------------- @@ -39,23 +46,17 @@ def get_el_by_name(items: List[Dict[str, Any]], name: str) -> Dict[str, Any]: def get_module_options(module_dirname: str) -> Dict[str, Any]: """Returns yaml dict options of a PHP module given by its absolute file path.""" - with open(os.path.join(PHP_MODULE_PATH, module_dirname, "options.yml"), encoding="utf8") as fp: - data = yaml.safe_load(fp) - return data + return load_yaml(os.path.join(PHP_MODULE_PATH, module_dirname, "options.yml")) def get_module_build(module_dirname: str) -> Dict[str, Any]: """Returns yaml dict build configuration of a PHP module given by its absolute file path.""" - with open(os.path.join(PHP_MODULE_PATH, module_dirname, "build.yml"), encoding="utf8") as fp: - data = yaml.safe_load(fp) - return data + return load_yaml(os.path.join(PHP_MODULE_PATH, module_dirname, "build.yml")) def get_module_test(module_dirname: str) -> Dict[str, Any]: """Returns yaml dict test configuration of a PHP module given by its absolute file path.""" - with open(os.path.join(PHP_MODULE_PATH, module_dirname, "test.yml"), encoding="utf8") as fp: - data = yaml.safe_load(fp) - return data + return load_yaml(os.path.join(PHP_MODULE_PATH, module_dirname, "test.yml")) def get_modules() -> List[Dict[str, Any]]: @@ -159,10 +160,8 @@ def write_group_vars(module_names: List[str]) -> None: def main() -> None: """Main entrypoint.""" - # Module directory names - modules = get_modules() - # Get modules in order of dependencies + modules = get_modules() module_tree = get_module_dependency_tree(modules) names = resolve_module_dependency_tree(module_tree)