Skip to content

Commit

Permalink
chantal: add line conditions step skips
Browse files Browse the repository at this point in the history
  • Loading branch information
mic-e committed Apr 15, 2017
1 parent 3f21528 commit 603193b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
1 change: 1 addition & 0 deletions chantal/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def main():
cmd.add_argument("clone_url")
cmd.add_argument("commit_sha")
cmd.add_argument("desc_file")
cmd.add_argument("job")
cmd.add_argument("--shallow", type=int, default=0)
cmd.add_argument("--folder", default="repo")

Expand Down
16 changes: 12 additions & 4 deletions chantal/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def build_job(args):

try:
with open(args.desc_file) as controlfile:
steps = parse_control_file(controlfile.read())
steps = parse_control_file(controlfile.read(), args)
except FileNotFoundError:
raise FatalBuildError(
"no kevin config file named '%s' was found" % (args.desc_file))
Expand All @@ -50,16 +50,24 @@ def build_job(args):
exc.args[1]))

for step in steps:
step_state(step, "waiting", "waiting")
if not step.skip:
step_state(step, "waiting", "waiting")

errors = []
success = set()
for step in steps:
depend_issues = set(step.depends) - success

if step.skip:
# the step has been marked to be skipped in the control file.
# do not run it or produce any output.
if not depend_issues:
success.add(step.name)
continue

if not errors:
job_state("running", "running (" + step.name + ")")

depend_issues = set(step.depends) - success

if depend_issues:
text = "depends failed: " + ", ".join(depend_issues)
step_state(step, "error", text)
Expand Down
34 changes: 30 additions & 4 deletions chantal/controlfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_indent(line):
return line[:-len(line.lstrip())]


def preprocess_lines(data):
def preprocess_lines(data, args):
"""
Preprocesses the raw text in data,
Expand All @@ -28,6 +28,8 @@ def preprocess_lines(data):
Yields tuples of lineno, line, isindented
"""
condition_env = args.__dict__.copy()

file_indent = None
for lineno, line in enumerate(data.split('\n')):
indent = get_indent(line)
Expand All @@ -42,6 +44,29 @@ def preprocess_lines(data):
"Illegal indent; expected %r" % file_indent
)

# check the condition at the end of the line
if line.endswith(" ?)"):
try:
line, condition = line[:-3].rsplit("(? if ", maxsplit=1)
except ValueError:
raise ParseError(
lineno,
"Expected '(? if ' to match ' ?)' at end of line"
) from None

try:
condition_env["lineno"] = lineno
condition_result = eval(condition, condition_env)
except Exception as exc:
raise ParseError(
lineno,
"Could not eval() condition: %r" % exc
) from None

if not condition_result:
# the line is disabled.
continue

# remove comments at the end of the line
line = line.partition('#')[0].strip()
# skip empty lines
Expand All @@ -51,7 +76,7 @@ def preprocess_lines(data):
yield lineno, line, bool(indent)


def parse_control_file(data):
def parse_control_file(data, args):
"""
Parses control file contents, yields a list of steps.
"""
Expand All @@ -60,7 +85,7 @@ def parse_control_file(data):

result = []

for lineno, line, isindented in preprocess_lines(data):
for lineno, line, isindented in preprocess_lines(data, args):
if isindented:
# step content
try:
Expand Down Expand Up @@ -112,6 +137,7 @@ def __init__(self, line, lineno, existing):

# the various attributes that may be set in header lines.
self.hidden = False
self.skip = False
self.outputs = []
self.env = {}

Expand Down Expand Up @@ -147,7 +173,7 @@ def process_header(self, key, val, lineno, all_outputs):
key: what does this header do?
val: definition of the specific header action
"""
if key in {"hidden"}:
if key in {"hidden", "skip"}:
# boolean flags
if val is not None:
raise ParseError(lineno, key + " is just a flag, nothing more.")
Expand Down
3 changes: 2 additions & 1 deletion kevin/chantal.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def run(self, job):
("python3", "-u", "-m", "chantal",
job.build.clone_url,
job.build.commit_hash,
job.build.project.cfg.job_desc_file),
job.build.project.cfg.job_desc_file,
job.name),
timeout=job.build.project.cfg.job_timeout,
silence_timeout=job.build.project.cfg.job_silence_timeout,
)

0 comments on commit 603193b

Please sign in to comment.