From fec9263f5e6305c2866295a18c2f36548bf323d5 Mon Sep 17 00:00:00 2001
From: gyulaid <gyulaid@gyulai.cloud>
Date: Mon, 18 Apr 2022 19:24:29 +0200
Subject: [PATCH] Added install test

---
 .drone.yml                                 | 11 ++++++++++-
 alice-ci/src/alice/__main__.py             |  4 ++--
 alice-ci/src/alice/runners/pythonrunner.py |  6 ++++--
 alice-ci/src/alice/runners/pyutils.py      |  4 ++++
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/.drone.yml b/.drone.yml
index 7fe5a67..a4ed841 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -6,7 +6,7 @@ steps:
 - name: static-test
   image: alpine/flake8
   commands:
-  - python3 -m flake8 --ignore E501,W503
+  - python3 -m flake8 --ignore E501,W503 alice-ci/src
 
 - name: build
   image: python
@@ -14,6 +14,15 @@ steps:
   - python3 -m pip install build
   - python3 -m build alice-ci
 
+- name: test
+  image: python
+  environment:
+    PYPIUSER: USER
+    PYPIPASS: PASS
+  commands:
+  - python3 -m pip install alice-ci/dist/alice_ci*.whl
+  - alice -i ci-examples/full.yaml -vv
+
 - name: publish
   image: python
   environment:
diff --git a/alice-ci/src/alice/__main__.py b/alice-ci/src/alice/__main__.py
index d5cb563..ef588d4 100644
--- a/alice-ci/src/alice/__main__.py
+++ b/alice-ci/src/alice/__main__.py
@@ -1,4 +1,4 @@
-import alice
+from .cli import main
 
 if __name__ == '__main__':
-    alice.cli.main()
+    main()
diff --git a/alice-ci/src/alice/runners/pythonrunner.py b/alice-ci/src/alice/runners/pythonrunner.py
index ea1351a..c2854bd 100644
--- a/alice-ci/src/alice/runners/pythonrunner.py
+++ b/alice-ci/src/alice/runners/pythonrunner.py
@@ -15,22 +15,24 @@ class PythonRunner:
         self.workdir = config["workdir"]
         self.virtual_dir = os.path.abspath(os.path.join(self.workdir, "venv"))
         self.config = config
-        PackageManager.getInstance().ensure("build")
+        PackageManager.getInstance().ensure("virtualenv")
         self.__init_venv()
 
     def __init_venv(self):
         if os.name == "nt":  # Windows
             self.vpython = os.path.join(self.virtual_dir, "Scripts", "python.exe")
         else:  # Linux & Mac
-            self.vpython = os.path.join(self.virtual_dir, "bin", "python3")
+            self.vpython = os.path.join(self.virtual_dir, "bin", "python")
 
         if not os.path.exists(self.vpython):
+            logging.debug(f"[PythonRunner] Venv not found at {self.vpython}")
             logging.info("[PythonRunner] Initializing venv")
             with subprocess.Popen([sys.executable, "-m", "virtualenv", self.virtual_dir],
                                   stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
                 p.wait()
                 if p.returncode != 0:
                     sys.stdout.buffer.write(p.stderr.read())
+                    sys.stdout.buffer.write(p.stdout.read())
                     raise RunnerError("[PythonRunner] Could not create virtualenv")
                 else:
                     logging.info(f"[PythonRunner] Virtualenv initialized at {self.virtual_dir}")
diff --git a/alice-ci/src/alice/runners/pyutils.py b/alice-ci/src/alice/runners/pyutils.py
index e37fb60..d8bb685 100644
--- a/alice-ci/src/alice/runners/pyutils.py
+++ b/alice-ci/src/alice/runners/pyutils.py
@@ -35,6 +35,7 @@ class PackageManager:
             installed = list(map(lambda x: x.decode("UTF-8").split("=="), filter(lambda x: b'==' in x, p.stdout.read().splitlines())))
         for name, version in installed:
             packages[name] = parse_version(version)
+        logging.debug(f"[PackageManager] Picked up packages: {packages}")
         return packages
 
     def ensure_more(self, package_list, executable=sys.executable):
@@ -51,6 +52,7 @@ class PackageManager:
     # Assumption: there are more hits in the long run, than misses
     def ensure(self, package_string, executable=sys.executable):
         if not self.__has_package(package_string):
+            logging.info(f"[PackageManager] Installing {package_string}")
             command = [executable, "-m", "pip", "install", package_string]
             with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
                 p.wait()
@@ -58,6 +60,8 @@ class PackageManager:
                     sys.stdout.buffer.write(p.stderr.read())
                     raise(RunnerError(f"[PackageManager] Could not install dependencies ({p.returncode})"))
             self.package_list = self.__get_packages()
+        else:
+            logging.info(f"[PackageManager] {package_string} already installed")
 
     def __has_package(self, package_string):
         package_data = re.split("==|>|>=|<|<=", package_string)
-- 
GitLab