Skip to content

Commit b3ce857

Browse files
dhellmannclaude
andcommitted
refactor(graph): rename suggest-base to find-common-dependencies
Rename the `graph suggest-base` subcommand to `graph find-common-dependencies` for clarity. Updates all internal helpers and tests to match. Co-Authored-By: Claude <claude@anthropic.com> Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
1 parent 3a92d04 commit b3ce857

2 files changed

Lines changed: 39 additions & 35 deletions

File tree

src/fromager/commands/graph.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ def _compute_collection_impact(
883883
return result
884884

885885

886-
def _suggest_base_table(
886+
def _find_common_dependencies_table(
887887
candidates: list[dict[str, typing.Any]],
888888
total_collections: int,
889889
collection_names: list[str],
@@ -893,7 +893,7 @@ def _suggest_base_table(
893893
impact: list[dict[str, typing.Any]],
894894
base_only_packages: set[NormalizedName],
895895
) -> None:
896-
"""Display suggest-base results as a rich table."""
896+
"""Display find-common-dependencies results as a rich table."""
897897
title = (
898898
f"Base collection candidates "
899899
f"(threshold: {min_collections}/{total_collections} collections)\n"
@@ -996,7 +996,7 @@ def _suggest_base_table(
996996
console.print(base_only_table)
997997

998998

999-
def _suggest_base_json(
999+
def _find_common_dependencies_json(
10001000
candidates: list[dict[str, typing.Any]],
10011001
total_collections: int,
10021002
collection_names: list[str],
@@ -1007,7 +1007,7 @@ def _suggest_base_json(
10071007
impact: list[dict[str, typing.Any]],
10081008
base_only_packages: set[NormalizedName],
10091009
) -> None:
1010-
"""Display suggest-base results as JSON."""
1010+
"""Display find-common-dependencies results as JSON."""
10111011
output: dict[str, typing.Any] = {
10121012
"metadata": {
10131013
"total_collections": total_collections,
@@ -1042,13 +1042,13 @@ def _suggest_base_json(
10421042
json.dump(output, sys.stdout, indent=2)
10431043

10441044

1045-
def _suggest_base_impl(
1045+
def _find_common_dependencies_impl(
10461046
collection_graphs: tuple[pathlib.Path, ...],
10471047
base_graph: pathlib.Path | None,
10481048
min_collections: int | None,
10491049
output_format: str,
10501050
) -> None:
1051-
"""Core implementation for suggest_base, testable without a click context."""
1051+
"""Core implementation for find_common_dependencies, testable without a click context."""
10521052
if len(collection_graphs) < 2:
10531053
raise click.UsageError("At least 2 collection graphs are required")
10541054
if min_collections is None:
@@ -1095,7 +1095,7 @@ def _suggest_base_impl(
10951095
impact = _compute_collection_impact(collections, proposed_base, display_names)
10961096

10971097
if output_format == "json":
1098-
_suggest_base_json(
1098+
_find_common_dependencies_json(
10991099
candidates,
11001100
total,
11011101
list(display_names.values()),
@@ -1107,7 +1107,7 @@ def _suggest_base_impl(
11071107
base_only_packages,
11081108
)
11091109
else:
1110-
_suggest_base_table(
1110+
_find_common_dependencies_table(
11111111
candidates,
11121112
total,
11131113
list(display_names.values()),
@@ -1143,7 +1143,7 @@ def _suggest_base_impl(
11431143
@click.argument(
11441144
"collection_graphs", nargs=-1, required=True, type=clickext.ClickPath(exists=True)
11451145
)
1146-
def suggest_base(
1146+
def find_common_dependencies(
11471147
collection_graphs: tuple[pathlib.Path, ...],
11481148
base_graph: pathlib.Path | None,
11491149
min_collections: int | None,
@@ -1155,4 +1155,6 @@ def suggest_base(
11551155
appearing across multiple collections. These are candidates for factoring
11561156
into a base collection built once and reused.
11571157
"""
1158-
_suggest_base_impl(collection_graphs, base_graph, min_collections, output_format)
1158+
_find_common_dependencies_impl(
1159+
collection_graphs, base_graph, min_collections, output_format
1160+
)

tests/test_graph_commands.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
from fromager import dependency_graph
1414
from fromager.commands.graph import (
1515
_compute_collection_impact,
16+
_find_common_dependencies_impl,
1617
_find_customized_dependencies_for_node,
1718
_find_shared_packages,
1819
_get_collection_packages,
19-
_suggest_base_impl,
2020
find_why,
2121
show_explain_duplicates,
2222
)
@@ -561,14 +561,14 @@ def test_find_shared_packages_sorting() -> None:
561561
# ---------------------------------------------------------------------------
562562

563563

564-
def test_suggest_base_table_output(
564+
def test_find_common_dependencies_table_output(
565565
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
566566
) -> None:
567-
"""suggest_base command produces table output with key strings."""
567+
"""find_common_dependencies command produces table output with key strings."""
568568
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-shared", "pkg-only-a"])
569569
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-only-b"])
570570

571-
_suggest_base_impl(
571+
_find_common_dependencies_impl(
572572
collection_graphs=(path_a, path_b),
573573
base_graph=None,
574574
min_collections=2,
@@ -584,7 +584,7 @@ def test_suggest_base_table_output(
584584
assert "pkg-only-b" in captured.out
585585

586586

587-
def test_suggest_base_dynamic_default_min_collections(
587+
def test_find_common_dependencies_dynamic_default_min_collections(
588588
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
589589
) -> None:
590590
"""Default --min-collections is 50% of provided graphs (rounded up)."""
@@ -595,7 +595,7 @@ def test_suggest_base_dynamic_default_min_collections(
595595
path_c = _make_graph_file(tmp_path, "coll-c", ["pkg-shared-abc"])
596596
path_d = _make_graph_file(tmp_path, "coll-d", ["pkg-only-d"])
597597

598-
_suggest_base_impl(
598+
_find_common_dependencies_impl(
599599
collection_graphs=(path_a, path_b, path_c, path_d),
600600
base_graph=None,
601601
min_collections=None, # dynamic default: ceil(4/2) = 2
@@ -611,14 +611,14 @@ def test_suggest_base_dynamic_default_min_collections(
611611
assert "pkg-only-d" not in packages
612612

613613

614-
def test_suggest_base_json_output(
614+
def test_find_common_dependencies_json_output(
615615
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
616616
) -> None:
617-
"""suggest_base command produces valid JSON output."""
617+
"""find_common_dependencies command produces valid JSON output."""
618618
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-shared", "pkg-only-a"])
619619
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-only-b"])
620620

621-
_suggest_base_impl(
621+
_find_common_dependencies_impl(
622622
collection_graphs=(path_a, path_b),
623623
base_graph=None,
624624
min_collections=2,
@@ -641,15 +641,15 @@ def test_suggest_base_json_output(
641641
assert "in_base" not in candidate
642642

643643

644-
def test_suggest_base_with_base_graph(
644+
def test_find_common_dependencies_with_base_graph(
645645
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
646646
) -> None:
647647
"""--base flag marks packages that are already in the base graph."""
648648
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-shared", "pkg-new"])
649649
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-new"])
650650
path_base = _make_graph_file(tmp_path, "base", ["pkg-shared"])
651651

652-
_suggest_base_impl(
652+
_find_common_dependencies_impl(
653653
collection_graphs=(path_a, path_b),
654654
base_graph=path_base,
655655
min_collections=2,
@@ -664,42 +664,44 @@ def test_suggest_base_with_base_graph(
664664
assert data["metadata"]["base_graph"] == str(path_base)
665665

666666

667-
def test_suggest_base_too_few_graphs(tmp_path: pathlib.Path) -> None:
667+
def test_find_common_dependencies_too_few_graphs(tmp_path: pathlib.Path) -> None:
668668
"""Error raised when fewer than 2 graphs are provided."""
669669
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-a"])
670670

671671
with pytest.raises(click.UsageError, match="At least 2 collection graphs"):
672-
_suggest_base_impl(
672+
_find_common_dependencies_impl(
673673
collection_graphs=(path_a,),
674674
base_graph=None,
675675
min_collections=2,
676676
output_format="table",
677677
)
678678

679679

680-
def test_suggest_base_invalid_min_collections(tmp_path: pathlib.Path) -> None:
680+
def test_find_common_dependencies_invalid_min_collections(
681+
tmp_path: pathlib.Path,
682+
) -> None:
681683
"""Error raised when --min-collections exceeds number of graphs."""
682684
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-a"])
683685
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-b"])
684686

685687
with pytest.raises(click.UsageError, match="cannot exceed number of graphs"):
686-
_suggest_base_impl(
688+
_find_common_dependencies_impl(
687689
collection_graphs=(path_a, path_b),
688690
base_graph=None,
689691
min_collections=3,
690692
output_format="table",
691693
)
692694

693695

694-
def test_suggest_base_all_but_one_empty(tmp_path: pathlib.Path) -> None:
696+
def test_find_common_dependencies_all_but_one_empty(tmp_path: pathlib.Path) -> None:
695697
"""Error raised when all but one graph are empty after filtering."""
696698
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-a"])
697699
path_b = _make_graph_file(tmp_path, "coll-b", [])
698700

699701
with pytest.raises(
700702
click.UsageError, match="At least 2 non-empty collection graphs"
701703
):
702-
_suggest_base_impl(
704+
_find_common_dependencies_impl(
703705
collection_graphs=(path_a, path_b),
704706
base_graph=None,
705707
min_collections=2,
@@ -776,14 +778,14 @@ def test_compute_collection_impact_sorting() -> None:
776778
assert result[2]["collection"] == "coll-m"
777779

778780

779-
def test_suggest_base_table_includes_impact(
781+
def test_find_common_dependencies_table_includes_impact(
780782
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
781783
) -> None:
782784
"""Table output includes Collection Impact section."""
783785
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-shared", "pkg-only-a"])
784786
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-only-b"])
785787

786-
_suggest_base_impl(
788+
_find_common_dependencies_impl(
787789
collection_graphs=(path_a, path_b),
788790
base_graph=None,
789791
min_collections=2,
@@ -800,14 +802,14 @@ def test_suggest_base_table_includes_impact(
800802
assert "Remaining Packages (not in proposed" in captured.out
801803

802804

803-
def test_suggest_base_json_includes_impact(
805+
def test_find_common_dependencies_json_includes_impact(
804806
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
805807
) -> None:
806808
"""JSON output includes collection_impact key with correct structure."""
807809
path_a = _make_graph_file(tmp_path, "coll-a", ["pkg-shared", "pkg-only-a"])
808810
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-only-b"])
809811

810-
_suggest_base_impl(
812+
_find_common_dependencies_impl(
811813
collection_graphs=(path_a, path_b),
812814
base_graph=None,
813815
min_collections=2,
@@ -831,7 +833,7 @@ def test_suggest_base_json_includes_impact(
831833
assert len(entry["remaining"]) == 1
832834

833835

834-
def test_suggest_base_json_base_only_packages(
836+
def test_find_common_dependencies_json_base_only_packages(
835837
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
836838
) -> None:
837839
"""Packages in --base that are not candidates appear in base_only_packages."""
@@ -840,7 +842,7 @@ def test_suggest_base_json_base_only_packages(
840842
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-only-b"])
841843
path_base = _make_graph_file(tmp_path, "base", ["pkg-shared", "pkg-base-only"])
842844

843-
_suggest_base_impl(
845+
_find_common_dependencies_impl(
844846
collection_graphs=(path_a, path_b),
845847
base_graph=path_base,
846848
min_collections=2,
@@ -857,7 +859,7 @@ def test_suggest_base_json_base_only_packages(
857859
assert "pkg-shared" not in data["base_only_packages"]
858860

859861

860-
def test_suggest_base_json_base_only_impacts_collection_impact(
862+
def test_find_common_dependencies_json_base_only_impacts_collection_impact(
861863
capsys: pytest.CaptureFixture[str], tmp_path: pathlib.Path
862864
) -> None:
863865
"""Base-only packages count toward collection impact when --base is provided."""
@@ -868,7 +870,7 @@ def test_suggest_base_json_base_only_impacts_collection_impact(
868870
path_b = _make_graph_file(tmp_path, "coll-b", ["pkg-shared", "pkg-only-b"])
869871
path_base = _make_graph_file(tmp_path, "base", ["pkg-shared", "pkg-base-only"])
870872

871-
_suggest_base_impl(
873+
_find_common_dependencies_impl(
872874
collection_graphs=(path_a, path_b),
873875
base_graph=path_base,
874876
min_collections=2,

0 commit comments

Comments
 (0)