From 0d5ea9d40789d617478f3f8f8733c8107aef3738 Mon Sep 17 00:00:00 2001 From: Rob Mohr Date: Fri, 13 Dec 2019 09:05:59 -0800 Subject: [PATCH] Allow running single steps in presubmit. Add ability to run individual presubmit checks using --step. Bug: 3 Change-Id: Ibcea8e54de2deb2e8159ae1389b86a5c82da0d14 --- .../py/pw_presubmit/pigweed_presubmit.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py index f3bbc4423..a0c4ded1a 100755 --- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py +++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py @@ -347,6 +347,8 @@ PROGRAMS: Dict[str, Sequence] = { def argument_parser(parser=None) -> argparse.ArgumentParser: + """Create argument parser.""" + if parser is None: parser = argparse.ArgumentParser(description=__doc__) @@ -370,6 +372,14 @@ def argument_parser(parser=None) -> argparse.ArgumentParser: choices=PROGRAMS, default='full', help='Which presubmit program to run') + + exclusive.add_argument( + '--step', + choices=[x.__name__ for x in PROGRAMS['full']], + action='append', + help='Provide explicit steps instead of running a predefined program.', + ) + pw_presubmit.add_arguments(parser) return parser @@ -381,8 +391,11 @@ def main( clean_py: bool, install: bool, repository: str, + step: Sequence[str], **presubmit_args, ) -> int: + """Entry point for presubmit.""" + environment = pw_presubmit.git_repo_path(PRESUBMIT_PREFIX, repo=repository) _LOG.debug('Using environment at %s', environment) @@ -396,7 +409,11 @@ def main( presubmit_args['repository']) return 0 - if pw_presubmit.run_presubmit(PROGRAMS[program], + program = PROGRAMS[program] + if step: + program = [x for x in PROGRAMS['full'] if x.__name__ in step] + + if pw_presubmit.run_presubmit(program, repository=repository, **presubmit_args): return 0