Skip to content

Commit

Permalink
run_recipe: add the ability to run yamllint over a recipe
Browse files Browse the repository at this point in the history
This is a very rudimentary implementation and just runs yamllint in
a subprocess for a nicely colored and formatted output.

Right now this outputs a lot of indentation errors in the example
recipes, none of which are of consequence to the correctness of the
output.
  • Loading branch information
hagau committed Sep 20, 2024
1 parent d00dc34 commit 80368dc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions run_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import shutil
import argparse
import subprocess
import traceback
import threading

Expand Down Expand Up @@ -282,6 +283,11 @@ def process_recipe(options):

recipe = yaml.unsafe_load(f.read())

if options.lint_recipe:
# Just run yamllint in a subprocess for now. This also provides a nicely colored output.
subprocess.run(['yamllint', options.recipe])
exit()

if options.dump_recipe or options.dump_recipe_only:
output = dump(recipe, Dumper=Dumper)
terminal_size = shutil.get_terminal_size()
Expand Down Expand Up @@ -365,6 +371,7 @@ def parse_arguments(arguments):

parser.add_argument('--dump-recipe', action='store_true', default=False, help='Dump the loaded recipe; useful for finding errors in the recipe')
parser.add_argument('--dump-recipe-only', action='store_true', default=False, help='Dump the loaded recipe and exit; useful for finding errors in the recipe')
parser.add_argument('--lint-recipe', action='store_true', default=False, help='Run yamllint over the specified recipe; useful for finding errors in the recipe')

parser.add_argument('--debug', action='store_true', default=False, help='Enable debug mode. If an exception is encountered, drop into an ipdb debugger session')

Expand Down

0 comments on commit 80368dc

Please sign in to comment.