From 7e6c1fa786d57caec552346ed5fa1926b533cf46 Mon Sep 17 00:00:00 2001
From: Daniel Gyulai <gyulaid@gyulai.cloud>
Date: Tue, 29 Mar 2022 15:33:55 +0000
Subject: [PATCH] 9-hotfix - Fix #9 (#10)

Co-authored-by: gyulaid <gyulaid@gyulai.cloud>
Reviewed-on: https://git.gyulai.cloud/gyulaid/alice/pulls/10
Co-authored-by: Daniel Gyulai <gyulaid@gyulai.cloud>
Co-committed-by: Daniel Gyulai <gyulaid@gyulai.cloud>
---
 alice-ci/setup.cfg                         |  2 +-
 alice-ci/src/alice/__init__.py             | 14 +++++---
 alice-ci/src/alice/__main__.py             |  2 +-
 alice-ci/src/alice/cli.py                  |  6 ++--
 alice-ci/src/alice/runnerfactory.py        |  9 ++++--
 alice-ci/src/alice/runners/__init__.py     |  3 ++
 alice-ci/src/alice/runners/pythonrunner.py |  2 +-
 alice-ci/src/alice/utils.py                | 37 +---------------------
 8 files changed, 27 insertions(+), 48 deletions(-)
 create mode 100644 alice-ci/src/alice/runners/__init__.py

diff --git a/alice-ci/setup.cfg b/alice-ci/setup.cfg
index 39eeec0..58768c0 100644
--- a/alice-ci/setup.cfg
+++ b/alice-ci/setup.cfg
@@ -1,6 +1,6 @@
 [metadata]
 name = alice-ci
-version = 0.0.2
+version = 0.0.3
 author = Daniel Gyulai
 description = Alice CI framework
 long_description = file: README.md
diff --git a/alice-ci/src/alice/__init__.py b/alice-ci/src/alice/__init__.py
index 39328d3..1181dd0 100644
--- a/alice-ci/src/alice/__init__.py
+++ b/alice-ci/src/alice/__init__.py
@@ -1,5 +1,11 @@
 # flake8: noqa F401
-from .cli import App
-from .jobparser import Job, JobParser
-from .exceptions import NonZeroRetcode
-from .pythonrunner import PythonRunner
\ No newline at end of file
+from alice.utils import ConfigParser
+from alice.exceptions import NonZeroRetcode
+from alice.runnerfactory import Factory
+from alice.runners.pythonrunner import PythonRunner
+from alice.exceptions import NonZeroRetcode
+from alice.exceptions import RunnerError
+from alice.exceptions import ConfigException
+from alice.__main__ import main
+
+name = "alice"
\ No newline at end of file
diff --git a/alice-ci/src/alice/__main__.py b/alice-ci/src/alice/__main__.py
index d92dc90..41aa9b8 100644
--- a/alice-ci/src/alice/__main__.py
+++ b/alice-ci/src/alice/__main__.py
@@ -1,3 +1,3 @@
-from cli import main
+from alice.cli import main
 
 main()
diff --git a/alice-ci/src/alice/cli.py b/alice-ci/src/alice/cli.py
index ed9cf3f..24308b4 100644
--- a/alice-ci/src/alice/cli.py
+++ b/alice-ci/src/alice/cli.py
@@ -1,9 +1,9 @@
 import os
 import argparse
 
-from utils import ConfigParser
-from runnerfactory import Factory
-from exceptions import ConfigException, NonZeroRetcode, RunnerError
+from alice.utils import ConfigParser
+from alice.runnerfactory import Factory
+from alice.exceptions import ConfigException, NonZeroRetcode, RunnerError
 
 
 def gen_env(self, param_list):
diff --git a/alice-ci/src/alice/runnerfactory.py b/alice-ci/src/alice/runnerfactory.py
index 834139e..a9290e2 100644
--- a/alice-ci/src/alice/runnerfactory.py
+++ b/alice-ci/src/alice/runnerfactory.py
@@ -1,6 +1,8 @@
-from runners.pythonrunner import PythonRunner
 from os import getcwd
 
+from alice.runners.pythonrunner import PythonRunner
+from alice.exceptions import ConfigException
+
 
 class Factory():
     def __init__(self) -> None:
@@ -30,5 +32,8 @@ class Factory():
 
     def get_runner(self, runnertype):
         if runnertype not in self.runners:
-            self.runners[runnertype] = self.runnertypes[runnertype](self.workdir, self.globals)
+            if runnertype in self.runnertypes:
+                self.runners[runnertype] = self.runnertypes[runnertype](self.workdir, self.globals)
+            else:
+                raise ConfigException(f"Invalid runner type: {runnertype}")
         return self.runners[runnertype]
diff --git a/alice-ci/src/alice/runners/__init__.py b/alice-ci/src/alice/runners/__init__.py
new file mode 100644
index 0000000..e6df5ea
--- /dev/null
+++ b/alice-ci/src/alice/runners/__init__.py
@@ -0,0 +1,3 @@
+from alice.runners.pythonrunner import PythonRunner
+
+__all__ = ["PythonRunner"]
diff --git a/alice-ci/src/alice/runners/pythonrunner.py b/alice-ci/src/alice/runners/pythonrunner.py
index 498298a..776094b 100644
--- a/alice-ci/src/alice/runners/pythonrunner.py
+++ b/alice-ci/src/alice/runners/pythonrunner.py
@@ -3,7 +3,7 @@ import os
 import sys
 import shlex
 
-from exceptions import NonZeroRetcode, RunnerError, ConfigException
+from alice.exceptions import NonZeroRetcode, RunnerError, ConfigException
 
 
 # same venv across all runs!
diff --git a/alice-ci/src/alice/utils.py b/alice-ci/src/alice/utils.py
index b99dc05..b9cd351 100644
--- a/alice-ci/src/alice/utils.py
+++ b/alice-ci/src/alice/utils.py
@@ -1,41 +1,6 @@
 import yaml
-from runners.pythonrunner import PythonRunner
-from exceptions import NonZeroRetcode, ConfigException
 
-
-class DummyRunner():
-    def __init__(self, type) -> None:
-        self.type = type
-
-    def run(self, command, workdir=None, env=None):
-        raise Exception(f"Invalid runner type in config: {self.type}")
-
-
-class Job():
-    def __init__(self, type, repoDir, vpython, workspace, env={}) -> None:
-        self.runner = self.__get_runner(type, repoDir, vpython)
-        self.commands = []
-        self.workspace = workspace
-        self.env = env
-
-    def __get_runner(self, type, repoDir, vpython):
-        if type == "python":
-            return PythonRunner(repoDir, vpython)
-        else:
-            return DummyRunner(type)
-
-    def run_commands(self, _env={}):
-        try:
-            if self.env is None:
-                env = _env.copy()
-            else:
-                env = self.env.copy()
-                env.update(_env)
-            for command in self.commands:
-                self.runner.run(command, self.workspace, env)
-        except NonZeroRetcode as n:
-            print(n)
-            exit(1)
+from alice.exceptions import ConfigException
 
 
 class ConfigParser:
-- 
GitLab