Skip to content

Commit

Permalink
Extend module.for-each invoke task (#28186)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgimalac authored Aug 5, 2024
1 parent f14e85e commit 51213dc
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions tasks/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,40 @@ def go_work(_: Context):


@task
def for_each(ctx: Context, cmd: str, skip_untagged: bool = False):
def for_each(
ctx: Context,
cmd: str,
skip_untagged: bool = False,
ignore_errors: bool = False,
use_targets_path: bool = False,
use_lint_targets_path: bool = False,
skip_condition: bool = False,
):
"""
Run the given command in the directory of each module.
"""
assert not (
use_targets_path and use_lint_targets_path
), "Only one of use_targets_path and use_lint_targets_path can be set"

for mod in DEFAULT_MODULES.values():
if skip_untagged and not mod.should_tag:
continue
with ctx.cd(mod.full_path()):
ctx.run(cmd)
if skip_condition and not mod.condition():
continue

targets = [mod.full_path()]
if use_targets_path:
targets = [os.path.join(mod.full_path(), target) for target in mod.targets]
if use_lint_targets_path:
targets = [os.path.join(mod.full_path(), target) for target in mod.lint_targets]

for target in targets:
with ctx.cd(target):
res = ctx.run(cmd, warn=True)
assert res is not None
if res.failed and not ignore_errors:
raise Exit(f"Command failed in {target}")


@task
Expand Down

0 comments on commit 51213dc

Please sign in to comment.