Skip to content

Commit 5a7e256

Browse files
committed
Sort grep output to make it more deterministic
Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 437335a commit 5a7e256

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cookiecutter/hooks/post_gen_project.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,13 @@ def print_todos() -> None:
398398
"""Print all TODOs in the generated project."""
399399
todo_str = "TODO(cookiecutter):"
400400
repo = cookiecutter.github_repo_name
401-
cmd = ["grep", "-r", "--color", rf"\<{todo_str}.*", "."]
401+
cmd = rf"grep -r --color '\<{todo_str}.*' . | sort"
402402
try_run(
403403
cmd,
404404
warn_on_error=True,
405-
warn_on_bad_status=f"No `{todo_str}` found using `{' '.join(cmd)}`",
405+
warn_on_bad_status=f"No `{todo_str}` found using `{cmd}`",
406406
note_on_failure=f"Please search for `{todo_str}` in `{repo}/` manually.",
407+
shell=True,
407408
)
408409
print()
409410
note(
@@ -489,13 +490,14 @@ def finish_model_setup() -> None:
489490

490491

491492
def try_run(
492-
cmd: list[str],
493+
cmd: list[str] | str,
493494
/,
494495
*,
495496
warn_on_error: bool = False,
496497
warn_on_bad_status: str | None = None,
497498
note_on_failure: str | None = None,
498499
verbose: bool = False,
500+
shell: bool = False,
499501
) -> _subprocess.CompletedProcess[Any] | None:
500502
"""Try to run a command.
501503
@@ -516,12 +518,13 @@ def try_run(
516518
The result of the command or `None` if the command could not be run because
517519
of an error.
518520
"""
521+
assert isinstance(cmd, str) and shell or isinstance(cmd, list) and not shell
519522
result = None
520523
failed = False
521524
if verbose:
522525
print(f"Executing: {' '.join(cmd)}")
523526
try:
524-
result = _subprocess.run(cmd, check=False)
527+
result = _subprocess.run(cmd, check=False, shell=shell)
525528
except (OSError, _subprocess.CalledProcessError) as exc:
526529
if warn_on_error:
527530
warn(f"Failed to run the search command `{' '.join(cmd)}`: {exc}")

0 commit comments

Comments
 (0)