remove-pythonpath-requirement (#11)

Before, recipes_dir had to be present in the importable paths of the python interpreter. This was solved by adding it to the PYTHONPATH env var. Now, abratest handles this by itself.

Reviewed-on: local-it-infrastructure/e2e_tests#11
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
Daniel 2023-12-07 17:21:19 +01:00 committed by dan
parent d2cfc089c3
commit 0b4e0a0c16
3 changed files with 81 additions and 8 deletions

View file

@ -1,5 +1,6 @@
import importlib
import re
import sys
from pathlib import Path
from loguru import logger
@ -90,11 +91,17 @@ class Coordinator:
"wordpress": RunnerWordpress,
"nextcloud": RunnerNextcloud,
}
The Runner classes are automatically imported with importlib. The imports are successful
because recipes_dir is added to sys.path.
"""
RUNNER_DICT: dict[str, type["Runner"]] = dict()
runner_discovery_pattern = re.compile("Runner.+")
# make it possible to import modules from recipes_dir
sys.path.append(recipes_dir.as_posix())
for module_path in recipes_dir.rglob("*/runner*.py"):
rel_path = module_path.relative_to(recipes_dir).as_posix().replace("/", ".").replace(".py", "")
module = importlib.import_module(rel_path)