Browse Source

Improved CLI output

pull/8/head
Daniel Gyulai 3 years ago
parent
commit
3295cc2395
  1. 6
      alice-ci/src/alice/cli.py
  2. 16
      alice-ci/src/alice/runners/pythonrunner.py
  3. 7
      ci-examples/full.yaml

6
alice-ci/src/alice/cli.py

@ -3,7 +3,7 @@ import argparse
from utils import ConfigParser
from runnerfactory import Factory
from exceptions import ConfigException, NonZeroRetcode
from exceptions import ConfigException, NonZeroRetcode, RunnerError
def gen_env(self, param_list):
@ -33,11 +33,13 @@ def parse_jobs(args):
print(f"Step {step} not found in {args.input}")
exit(1)
except ConfigException as e:
print(f"Configuration error: {e}")
print(f"Configuration error-> {e}")
exit(1)
except NonZeroRetcode:
print("FAILED")
exit(1)
except RunnerError as e:
print(f"RunnerError-> {e}")
def main():

16
alice-ci/src/alice/runners/pythonrunner.py

@ -25,19 +25,27 @@ class PythonRunner():
self.vpython = os.path.join(self.virtual_dir, "bin", "python3")
if not os.path.exists(self.vpython):
# TODO: Use Popen, hide output if successful
subprocess.call([sys.executable, "-m", "virtualenv", self.virtual_dir])
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())
raise RunnerError("PythonRunner: Could not create virtualenv")
else:
print(f"PythonRunner: Virtualenv initialized at {self.virtual_dir}")
else:
print(f"PythonRunner: Found virtualenv at {self.virtual_dir}")
# Stores common defaults for all jobs - all types!
# Also - dependency install by config is only allowed in this step
def update_config(self, config):
if "dependencies" in config:
for dependency in config["dependencies"]:
# TODO: Hide output - but only if successful!
# TODO: Check what happens with fixed version
with subprocess.Popen([self.vpython, "-m", "pip", "install", dependency, "--upgrade"]) as p:
with subprocess.Popen([self.vpython, "-m", "pip", "install", dependency, "--upgrade"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) as p:
p.wait()
if p.returncode != 0:
sys.stdout.buffer.write(p.stderr.read())
raise(RunnerError(f"PythonRunner: Could not install dependency: {dependency} ({p.returncode})"))
for env_var in config["env"]:
self.env_vars[env_var["name"]] = env_var["value"]

7
ci-examples/full.yaml

@ -16,11 +16,14 @@ runners:
- flake8
- build
jobs:
- name: lint
- name: env
type: python
workdir: alice-ci
env:
- name: B
value: E
commands:
- "-c \"import os; print(os.environ)\""
- name: lint
workdir: alice-ci
commands:
- "-m flake8 --ignore E501"
Loading…
Cancel
Save