mypy compliant

This commit is contained in:
brb
2023-07-13 12:11:49 +02:00
parent 2f69f49690
commit 7a965e5dfc
4 changed files with 24 additions and 38 deletions
+18 -29
View File
@@ -5,7 +5,7 @@ from dotenv import load_dotenv
import logging
import os
from utils import clone_repository, load_runner_script
from utils import clone_repository, execute_runner_script
from setup_logging import setup_logging
from gitea_request import GiteaRequest
@@ -60,34 +60,23 @@ def handle_event(request: GiteaRequest):
status_code=200,
detail="no runner_script.yml in repository root"
)
# load runner script
runner_script = load_runner_script(path=runner_script_path)
# determine pipeline to run
if branch_name not in runner_script.pipelines.keys():
# get default pipeline
if 'default' not in runner_script.pipelines.keys():
raise HTTPException(
status_code=404,
detail='no pipelines defined in runner_script.yml'
)
pipeline = runner_script.pipelines['default']
else:
# get custom pipeline
pipeline = runner_script.pipelines[branch_name]
logging.info(f'running pipeline {pipeline.name}')
# TODO: create virtualenv?
# install requirements
assert pipeline.requirements is not None
requirements_path = local_repo_dir / pipeline.requirements
os.system(f'pip install -r {requirements_path}')
for cmd in pipeline.script:
try:
os.system(cmd)
except Exception as e:
raise HTTPException(
status_code=503,
detail=f'failed running {cmd}: {e}'
)
# execute runner script
logging.info('rexecuting runner script')
execute_runner_script(path=runner_script_path)
# # TODO: create virtualenv?
# # install requirements
# assert pipeline.requirements is not None
# requirements_path = local_repo_dir / pipeline.requirements
# os.system(f'pip install -r {requirements_path}')
# for cmd in pipeline.script:
# try:
# os.system(cmd)
# except Exception as e:
# raise HTTPException(
# status_code=503,
# detail=f'failed running {cmd}: {e}'
# )
# send response
raise HTTPException(
+1 -1
View File
@@ -15,7 +15,7 @@ class RunnerScript(BaseModel):
content_dict = yaml.safe_load(fh)
script_list = content_dict['script'].split('\n')
logging.debug('finished')
return RunnerScript.model_validate({'script': script_list})
return RunnerScript.model_validate({'script': script_list}) # type: ignore
if __name__ == '__main__':
+1 -1
View File
@@ -12,7 +12,7 @@ LOGGER_LEVEL = config.get('main', 'logger_level')
def setup_logging(
logger_level: Literal['debug', 'info', 'warning', 'error'] = LOGGER_LEVEL
logger_level: str = LOGGER_LEVEL
):
fmt = (
'%(asctime)s | '
+4 -7
View File
@@ -4,7 +4,6 @@ from git import Repo
import logging
import shutil
import os
import yaml
from runner_script import RunnerScript
@@ -24,10 +23,8 @@ def clone_repository(repo_url: AnyHttpUrl) -> Path:
return dst_dir
def load_runner_script(path: Path) -> RunnerScript:
assert path.exists()
with open(path, 'r') as fh:
script = yaml.safe_load(fh)
runner_script = RunnerScript.parse_obj(script)
def execute_runner_script(path: Path) -> None:
script_list = RunnerScript.from_file(path)
for cmd in script_list:
os.system(cmd)
logging.debug('finished')
return runner_script