Add comprehensive code quality reporting script and CI workflow#73
Merged
Conversation
Ports the code-quality CI pipeline from Expert_op4grid_recommender to ExpertOp4Grid. The workflow installs radon, vulture, interrogate and ruff (no heavy grid2op install needed) then runs scripts/code_quality_report.py in two passes: a non-strict pass that always uploads a markdown artifact and populates the GitHub step summary, and a strict pass that fails the job on critical regressions (bare TODOs, hardcoded /home/… paths, duplicate config definitions). https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
Two issues caused the CI strict gate to fail on the existing codebase:
1. XXX was included in _TODO_RE but is used throughout alphaDeesp as a
sentinel string value ("XXX" comparisons and assignments), not as a
TODO marker. Drop it from the pattern to eliminate ~6 false positives.
2. bare_todos was treated as a critical/blocking regression gate, but
the codebase already has pre-existing TODO comments not yet linked to
issues. Demote it to informational so it appears in the report without
blocking PRs. The two remaining strict gates (hardcoded /home/... paths
and duplicate config definitions) are real portability/config issues
worth enforcing.
https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
alphaDeesp/core/alphadeesp.py
- Remove 7 dead/stub methods (load2, simulate_network_change,
get_loop_paths, isAntenna, write_g, read_g, compute_meaningful_structures)
and the trivial get_adjacency_matrix logger helper.
- Strip ~25 commented-out print-debug lines from the hot paths
(compute_best_topologies, compute_all_combinations, rank_topologies,
sort_hubs, identify_routing_buses, rank_red_loops).
- Split rank_loop_buses into three focused helpers (_bus_loop_strength,
_local_production_at_bus, _initial_inflow_between) so the outer loop
becomes a readable "for each loop, for each intermediate bus" iteration
instead of 50 lines of quadruple-nested logic.
- Tighten to_DiGraph and rank_red_loops; all 35 functions now grade A in
cyclomatic complexity (was: several B).
alphaDeesp/core/graphs/overflow_graph.py
- Drop ~120 lines of commented-out dead code inside
consolidate_constrained_path (old reasoning-flawed alternatives left
behind from a prior iteration).
- Extract build_edges_from_df into a color-dispatch helper (_edge_color)
and a single add-edge helper (_add_overflow_edge); module-level
_TARGET_MAX_PENWIDTH / _MIN_PENWIDTH constants replace the inline magic
numbers.
- Extract _recolor_ambiguous_as_blue so consolidate_constrained_path
reads as two symmetric amont/aval passes.
- Condense highlight_swapped_flows, plot, and _setup_null_flow_styles.
Tests
- Split the 1390-line test_graphs_and_paths_unit.py (C 0.00) into 5
focused A-grade modules + a shared graphs_test_helpers.py:
test_graph_utils.py (delete_color_edges, nodepath_to_edgepath,
incident_edges, from_edges_get_nodes,
find_multidigraph_edges_by_name,
all_simple_edge_paths_multi)
test_shortest_paths.py (shortest_path_with_promoted_edges,
shortest_path_min_weight_then_hops)
test_constrained_path.py (ConstrainedPath)
test_null_flow.py (add/remove_double_edges_null_redispatch,
_setup_null_flow_styles, null-flow helpers)
test_overflow_graph.py (keep_overloads_components,
collapse_red_loops, scaling,
detect_edges_to_keep + helpers)
- Add new unit tests for the extracted helpers: _bus_loop_strength,
_local_production_at_bus, _initial_inflow_between, to_DiGraph,
_edge_color, _recolor_ambiguous_as_blue.
Tests: 184 passing (was 165; +19). No module is C-grade anymore;
only alphadeesp.py and overflow_graph.py remain B, every other module
is A.
https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
Extract four mixin modules to bring every file to MI grade A (was B): - core/topology_scorer.py — scoring helpers for AlphaDeesp - core/topo_applicator.py — busbar-split graph-mutation helpers - core/graphs/null_flow_graph.py — null-flow redispatch logic (refactored _prepare_detect_edges_inputs into _preprocess_gc_edges + _preprocess_gc_nodes; _detect_edges_for_target_path split into four static strategy helpers) - core/graphs/graph_consolidation.py — consolidation/disambiguation methods (_run_consolidation_loop, _is_ambiguous_component extracted) All 76 modules now grade A (was: 2×B, 0 A for the two target files). 233 tests pass (+49 over previous 184). New test files: - tests/test_topology_scorer.py (get_prod_conso_sum, get_bus_id_from_edge, is_connected_to_cpath, _collect_flows_on_bus, _score_not_connected_to_cpath) - tests/test_topo_applicator.py (_compute_prod_load_per_bus, _classify_bus) Extended tests/test_alphadeesp_unit.py with: - TestLegalComb, TestComputeAllCombinations, TestFilterConstrainedPath, TestCleanAndSortBestTopologies https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
Drop Tuple, ExtremityLine, OriginLine — all moved to the mixin modules. https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
…e Pypownet - Extract D-grade monolith into four focused helpers: _compute_overload_counts (A/5), _compute_line_flags (B/10), _compute_cut_load_percent (A/1), _resolve_score (C/15). Main function drops to A(1); module MI improves to A (24.69). - Reorder main.py so Grid2OP is the first (default) branch. - Add DeprecationWarning + logger.warning when Pypownet is selected. - Update config.ini comment to mark Pypownet as deprecated/unmaintained. https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
Move the four pure-numpy helpers (_compute_overload_counts, _compute_line_flags, _compute_cut_load_percent, _resolve_score) from Grid2opSimulation.py into a new grid2op/scoring.py module that has no grid2op dependency, making them unit-testable without the full grid2op package installed. Add alphaDeesp/tests/test_score_helpers.py with 42 tests covering every branch of all four helpers (8 overload-count cases, 15 flag-logic cases, 6 cut-load cases, 13 resolve-score cases including every scoring branch). https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces an automated code quality reporting system that aggregates multiple static analysis tools into a single markdown report, along with a GitHub Actions workflow to run it on every push and pull request.
Key Changes
New Script:
scripts/code_quality_report.pyA comprehensive code quality analysis tool that:
Aggregates 10 different metrics into a single markdown report:
Implements critical regression gates (strict mode):
/home/<user>/...absolute pathsconfig*.pyfilesProvides flexible output options:
--output--github-summary--strictmode when critical issues are foundNew Workflow:
.github/workflows/code-quality.ymlA GitHub Actions workflow that:
Notable Implementation Details
https://claude.ai/code/session_01Mjev1wwsV1drJ219tGThWi