Skip to content

internal_dependency_links / popularity count import statements in zero-dependency mode but distinct neighbours with networkx #3024

Closed

Description

@squid-protocol

Symptom

file_data.internal_dependency_links and file_data.popularity mean different things depending on whether networkx is installed.

  • Full precision (build_dependency_graph, DiGraph): these are the graph's out- and in-degree, i.e. distinct neighbours. Importing lib twice from app counts as 1.
  • Zero-dependency (_fallback_build_graph): these count every resolved import statement, so the same app → lib pair counts as 2.

So the same repo produces different values for both columns, and for dependency_density, producer_ratio and ecosystem_role downstream of them, depending only on which optional engines are installed. repo_data.is_zero_dependency_mode is the only thing that tells a reader which meaning they are looking at.

Evidence

tests/tools_recorders/test_edge_data.py (#2992) pins both behaviours on one fixture. src/app.py imports src/lib.py twice and src/util.py once. The DiGraph gives out_degree 2; the fallback gives 3. The self-scan has 2 such repeated pairs (SUM(import_statements) 499 vs 497 edges).

Why it wasn't fixed in #2992

The zero-dependency golden master (tests/golden_master_zero_dep_audit.json) records the statement-count values, so aligning the fallback to distinct neighbours needs a re-bless. #2992 kept both builders byte-identical and made the divergence visible instead: edge_data.import_statements reconciles the fallback's numbers.

Proposal

Make the fallback count distinct neighbours: += 1 per edge_data row instead of += import_statements. _resolve_edges() already gives it the collapsed pairs, so this is a one-line change plus a golden-master bless scoped to popularity / internal_dependency_links / dependency_density / producer_ratio / ecosystem_role (and the coordinate ripple).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions