aboutsummaryrefslogtreecommitdiff
path: root/pw_presubmit
diff options
context:
space:
mode:
authorRob Mohr <mohrr@google.com>2021-08-31 07:09:38 -0700
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2021-08-31 16:51:22 +0000
commit284b51470fe5bf288b6a4e095a62acbe0d504fe9 (patch)
tree85af0185e8e435d948abb3be27a73a427ebb8f41 /pw_presubmit
parentd464911581b2fcab90da60cdc33a5b123f65d699 (diff)
downloadpigweed-284b51470fe5bf288b6a4e095a62acbe0d504fe9.tar.gz
pw_presubmit: Skip filtered steps when listing
Skip filtered steps when running 'pw presubmit' with '--only-list-steps'. LUCI uses '--only-list-steps' to expand programs so individual steps in a program show as separate steps in MILO. This change makes it clearer that some steps didn't actually run because there were no files for them to run on. Change-Id: Ifb1b768c97312a255c0281a1b0d97d022df6a096 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/58983 Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com> Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
Diffstat (limited to 'pw_presubmit')
-rw-r--r--pw_presubmit/py/pw_presubmit/cli.py6
-rw-r--r--pw_presubmit/py/pw_presubmit/presubmit.py11
2 files changed, 10 insertions, 7 deletions
diff --git a/pw_presubmit/py/pw_presubmit/cli.py b/pw_presubmit/py/pw_presubmit/cli.py
index 746984298..7f7ce053e 100644
--- a/pw_presubmit/py/pw_presubmit/cli.py
+++ b/pw_presubmit/py/pw_presubmit/cli.py
@@ -188,14 +188,10 @@ def run(
return 0
- if only_list_steps:
- for step in program:
- print(step.__name__)
- return 0
-
if presubmit.run(program,
root,
repositories,
+ only_list_steps=only_list_steps,
output_directory=output_directory,
package_root=package_root,
**other_args):
diff --git a/pw_presubmit/py/pw_presubmit/presubmit.py b/pw_presubmit/py/pw_presubmit/presubmit.py
index dffd3d2b4..dc82110f8 100644
--- a/pw_presubmit/py/pw_presubmit/presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/presubmit.py
@@ -226,7 +226,7 @@ class Presubmit:
def run(self, program: Program, keep_going: bool = False) -> bool:
"""Executes a series of presubmit checks on the paths."""
- checks = self._apply_filters(program)
+ checks = self.apply_filters(program)
_LOG.debug('Running %s for %s', program.title(), self._root.name)
_print_ui(_title(f'{self._root.name}: {program.title()}'))
@@ -250,7 +250,7 @@ class Presubmit:
return not failed and not skipped
- def _apply_filters(
+ def apply_filters(
self, program: Sequence[Callable]
) -> List[Tuple['_Check', Sequence[Path]]]:
"""Returns list of (check, paths) for checks that should run."""
@@ -395,6 +395,7 @@ def run(program: Sequence[Callable],
exclude: Sequence[Pattern] = (),
output_directory: Optional[Path] = None,
package_root: Path = None,
+ only_list_steps: bool = False,
keep_going: bool = False) -> bool:
"""Lists files in the current Git repo and runs a Presubmit with them.
@@ -418,6 +419,7 @@ def run(program: Sequence[Callable],
exclude: regular expressions for Posix-style paths to exclude
output_directory: where to place output files
package_root: where to place package files
+ only_list_steps: print step names instead of running them
keep_going: whether to continue running checks if an error occurs
Returns:
@@ -456,6 +458,11 @@ def run(program: Sequence[Callable],
package_root=package_root,
)
+ if only_list_steps:
+ for check, _ in presubmit.apply_filters(program):
+ print(check.name)
+ return True
+
if not isinstance(program, Program):
program = Program('', program)