Skip to content

Refactor: Clean codebase with strict Ruff linting and technical debt removal - #197

Draft
NITISH-R-G wants to merge 1 commit into
mainfrom
fix-lint-technical-debt-3513513473315160888
Draft

Refactor: Clean codebase with strict Ruff linting and technical debt removal#197
NITISH-R-G wants to merge 1 commit into
mainfrom
fix-lint-technical-debt-3513513473315160888

Conversation

@NITISH-R-G

@NITISH-R-G NITISH-R-G commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Enforces robust code standards through strict .ruff.toml linting and automated formatting. Technical debt such as test_script.py is removed, while dynamic typed component false positives are bypassed explicitly to guarantee future development conforms without disruption.


PR created automatically by Jules for task 3513513473315160888 started by @NITISH-R-G

Summary by Sourcery

Enforce stricter Ruff-based code quality standards while modernizing the codebase and removing unused technical debt.

Bug Fixes:

  • Preserve correct EV station occupancy when scenario slot limits are reduced.
  • Simplify and clarify baseline and oracle action handling in the Gradio demo.

Enhancements:

  • Modernize type annotations and clean up code across the application, visualization, routing, parsing, and training components.
  • Apply consistent formatting and automated lint-driven improvements throughout the codebase.
  • Add explicit type-checking exceptions for dynamically typed Gradio component methods.
  • Remove the unused test script and document repository health and technical-debt improvements.

Build:

  • Expand Ruff configuration to enforce a broad set of linting and code-quality rules.

Documentation:

  • Add a repository health report covering code quality, technical debt, linting, and improvement priorities.

- Configure strict Ruff linting categories in `.ruff.toml` and implement autofixes.
- Address false-positive MyPy `attr-defined` errors in `gradio` demo.
- Remove duplicate dead code `test_script.py`.
- Format python files with `ruff format .`.
- Add `CYCLE_8_REPORT.md` documenting these improvements.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6e856852-2458-4a0d-b4ce-3629b4d5244b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors the codebase to satisfy strict Ruff linting, applies minor logic simplifications and type-annotation modernizations, adds a cycle report, and removes an unused test script.

Sequence diagram for updated step_once mode handling in Gradio demo

sequenceDiagram
    actor User
    participant GradioUI
    participant step_once
    participant baseline_policy
    participant OracleAgent

    User->>GradioUI: click step
    GradioUI->>step_once: step_once(sess, mode, oracle_lora_repo)

    alt no_pending_evs
        step_once->>step_once: ActionType.load_shift
        step_once->>step_once: sess.last_action_text = "ACTION: load_shift (no pending EVs)"
    else mode_Untrained_Baseline
        step_once->>baseline_policy: baseline_policy(state, sess.env.city_graph)
        baseline_policy-->>step_once: EVGridAction
        step_once->>step_once: sess.last_action_text = f"Baseline picked ..."
    else mode_Oracle_Agent
        step_once->>OracleAgent: OracleAgent(lora_repo_id=oracle_lora_repo or None)
        step_once->>step_once: prompt = _build_prompt(state)
        step_once->>OracleAgent: OracleAgent.act(state, prompt, sess.env.city_graph)
        OracleAgent-->>step_once: EVGridAction
        step_once->>step_once: tag = "Oracle" or "Oracle (fallback)"
        step_once->>step_once: sess.last_action_text = f"{tag} picked ..."
    end

    step_once->>step_once: sess.env.step(action)
    step_once-->>GradioUI: updated sess, img, thought, kpi
Loading

File-Level Changes

Change Details Files
Simplify clamping helpers and related logic for readability and consistency.
  • Refactor normalization helpers to use min(...) patterns instead of nested conditional expressions.
  • Adjust score and clamp helpers to avoid duplicated conditional branches while keeping behavior equivalent.
  • Use hashlib.encode() without specifying utf-8 where feasible.
viz/gradio_demo.py
viz/city_map.py
ev_grid_oracle/grid_sim.py
ev_grid_oracle/traffic.py
ev_grid_oracle/world_model_verifier.py
ev_grid_oracle/bescom_feed.py
server/app.py
Modernize type hints and tidy control flow to satisfy strict Ruff and typing rules.
  • Replace Optional[...] and Tuple[...] with PEP 604 union syntax and built-in tuple type hints.
  • Tighten OrderedDict annotations and remove unused variables by renaming or prefixing with underscores.
  • Refactor branching in Gradio demo step_once to a simpler if/elif/else structure.
  • Simplify reward hack defer-streak reset logic using a single elif and membership check.
  • Use dict.fromkeys when initializing nested role metrics structures and iterate directly over dicts.
ev_grid_oracle/env.py
ev_grid_oracle/parsing.py
ev_grid_oracle/oracle_agent.py
server/app.py
server/road_router.py
viz/city_map.py
viz/record_two_phase.py
viz/record.py
server/role_metrics.py
training/train_grpo.ipynb
ev_grid_oracle/reward_hack.py
ev_grid_oracle/city_graph.py
ev_grid_oracle/road_models.py
ev_grid_oracle/scenarios.py
tools/road_reward_smoke.py
Reorganize imports and minor IO patterns to comply with Ruff style rules.
  • Normalize import ordering and grouping (standard library, third-party, local) in server and tools modules.
  • Remove unused typing imports such as Optional where no longer needed.
  • Drop unnecessary encoding arguments in open() calls and reformat with-context blocks.
  • Reorder subprocess import and nosec comments, and tidy exception handling in tools.
server/app.py
server/road_router.py
tools/generate_health_dashboard.py
tools/build_road_graph.py
tools/fetch_bangalore_roads_overpass.py
tools/build_roads_render.py
tools/fetch_osm_roads.py
tools/road_reward_smoke.py
training/train_grpo.ipynb
Tighten application logic around sessions and routing to reduce technical debt.
  • Ensure demo and multi-agent session maps use concrete OrderedDict type hints instead of string annotations.
  • Avoid unused local variables by renaming timestamp fields to underscored versions.
  • Use deterministic seed computation in demo_step and BESCOM feed snapshot with simpler encode calls.
  • Slightly adjust routing helpers (e.g., returning sorted connected components without wrapping in list) to meet lint suggestions.
server/app.py
ev_grid_oracle/city_graph.py
ev_grid_oracle/bescom_feed.py
server/app.py
Strengthen repository configuration and documentation for linting and technical-debt tracking.
  • Expand .ruff.toml to select a broad set of linting rule families and explicitly ignore known false positives.
  • Add CYCLE_8_REPORT.md documenting repository health, competitor analysis, and the linting/technical-debt cleanup plan.
  • Remove obsolete test_script.py to eliminate unused code and noise from the test suite.
.ruff.toml
CYCLE_8_REPORT.md
test_script.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant