Fix a missing dependency, and fix an issue when a Popen object has no return code

This commit is contained in:
Raoul Snyman 2021-07-14 22:04:43 -07:00
parent a2de18c7c2
commit 6021561b52
Signed by: raoul
GPG Key ID: F55BCED79626AE9C
2 changed files with 33 additions and 20 deletions

18
bou.py
View File

@ -12,6 +12,10 @@ BUILD_FILES = ['build.yaml', 'build.yml', 'bou.yaml', 'bou.yml']
ENV_VAR = re.compile(r'(\$([A-Za-z0-9_]+))') ENV_VAR = re.compile(r'(\$([A-Za-z0-9_]+))')
class StepFailedError(Exception):
pass
def parse_args(): def parse_args():
""" """
Parse command line arguments, and return an object with all the arguments Parse command line arguments, and return an object with all the arguments
@ -55,6 +59,7 @@ def setup_step(config, step_name):
""" """
step = config['steps'][step_name] step = config['steps'][step_name]
step['environment'] = config.get('environment', []) + step.get('environment', []) step['environment'] = config.get('environment', []) + step.get('environment', [])
step['name'] = step_name
return step return step
@ -91,7 +96,9 @@ def run_step(step, base_path):
for output in iter(lambda: proc.stdout.read(1), b''): for output in iter(lambda: proc.stdout.read(1), b''):
sys.stdout.buffer.write(output) sys.stdout.buffer.write(output)
sys.stdout.buffer.flush() sys.stdout.buffer.flush()
return proc.returncode == 0 proc.stdout.close()
proc.wait()
return not proc.returncode
def run_stage(config, stage_name, base_path): def run_stage(config, stage_name, base_path):
@ -102,10 +109,11 @@ def run_stage(config, stage_name, base_path):
:param stage_name: The stage to run :param stage_name: The stage to run
:param base_path: The base path of the build :param base_path: The base path of the build
""" """
for step in get_steps_for_stage(config, stage_name): steps = get_steps_for_stage(config, stage_name)
for step in steps:
result = run_step(step, base_path) result = run_step(step, base_path)
if not result: if not result:
break raise StepFailedError('Error running step "{name}"'.format(name=step['name']))
def get_all_stages(config): def get_all_stages(config):
@ -161,6 +169,7 @@ def main():
config = yaml.full_load(build_file.open()) config = yaml.full_load(build_file.open())
all_stages = get_all_stages(config) all_stages = get_all_stages(config)
all_steps = get_all_steps(config) all_steps = get_all_steps(config)
try:
if args.stage_or_step: if args.stage_or_step:
if args.stage_or_step in all_stages: if args.stage_or_step in all_stages:
run_stage(config, args.stage_or_step, base_path) run_stage(config, args.stage_or_step, base_path)
@ -179,6 +188,9 @@ def main():
for step_name in all_steps: for step_name in all_steps:
step = setup_step(config, step_name) step = setup_step(config, step_name)
run_step(config, step, base_path) run_step(config, step, base_path)
except StepFailedError as e:
print(str(e))
return 3
return 0 return 0

View File

@ -24,6 +24,7 @@ keywords = build, task
[options] [options]
py_modules = bou py_modules = bou
python_requires = >=3.7 python_requires = >=3.7
install_requires = PyYAML
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =