def _maybe_check_step_run(step, run): if not step.checks: return if _run_skipped(run): log.info("skipping checks for %s", step.name) return checks_passed = _check_step_run(step, run) if not checks_passed: _error("stopping because a check failed", exit_code.TEST_FAILED)
def write_sourcecode_digest(run, opdef): if opdef.sourcecode.digest is False: log.info("sourcecode digest disabled for operation '%s' - skipping", opdef.fullname) return if (opdef.sourcecode.digest is not True and opdef.modeldef.sourcecode.digest is False): log.info("sourcecode digest disabled for model '%s' - skipping", opdef.modeldef.name) return digest = file_util.files_digest(run.guild_path("sourcecode")) run.write_attr("sourcecode_digest", digest)
def _run_step(step, parent_run): step_run = _init_step_run(parent_run) cmd = _init_step_cmd(step, step_run.path) _link_to_step_run(step, step_run.path, parent_run.path) env = dict(os.environ) env["NO_WARN_RUNDIR"] = "1" log.info("running %s: %s", step, _format_step_cmd(cmd)) log.debug("cmd for %s: %s", step, cmd) returncode = subprocess.call(cmd, env=env, cwd=os.getenv("CMD_DIR")) if returncode != 0: sys.exit(returncode) return step_run
def _check_step_run(step, run): if not step.checks: return True passed = 0 failed = 0 for check in step.checks: try: check.check_run(run) except run_check.Failed as e: log.error("check failed: %s", e) failed += 1 else: passed += 1 log.info("%i of %i checks passed", passed, passed + failed) if failed > 0: log.error("%i check(s) failed - see above for details", failed) return failed == 0
def _run_step(step, parent_run): step_run = _init_step_run(parent_run) cmd = _init_step_cmd(step, step_run.path, parent_run) _link_to_step_run(step, step_run.path, parent_run.path) env = dict(os.environ) env["NO_WARN_RUNDIR"] = "1" if step.isolate_runs: env["GUILD_RUNS_PARENT"] = parent_run.id cwd = os.getenv("PROJECT_DIR") or os.getenv("CMD_DIR") log.info("running %s: %s", step, _format_step_cmd(cmd)) log.debug("step cwd %s", cwd) log.debug("step command: %s", cmd) log.debug("step env: %s", env) returncode = subprocess.call(cmd, env=env, cwd=cwd) if returncode != 0: sys.exit(returncode) return step_run
sys.stderr.write("guild: %s\n" % msg) sys.exit(exit_code.DEFAULT) if __name__ == "__main__": try: main() except Exception as e: if log is None or log.getEffectiveLevel() <= logging.DEBUG: raise import traceback exc_lines = traceback.format_exception(*sys.exc_info()) if len(exc_lines) < 3 or len(__argv0) < 2: # Assertion failure, but we want to be defensive in # deference to the actual error. raise # Print exception start with mod (argv[0]) filtered_exc_lines = [] mod_path = __argv0[1] for line in exc_lines[1:]: if filtered_exc_lines or mod_path in line: filtered_exc_lines.append(line) if not filtered_exc_lines: raise log.info("Limiting traceback below to user code. Use " "'guild --debug run ...' for full stack.") sys.stderr.write(exc_lines[0]) for line in filtered_exc_lines: sys.stderr.write(line) sys.exit(1)