Skip to content

chore: add ruff linting and formatting#80

Closed
tarun-etikala wants to merge 9 commits into
red-hat-data-services:mainfrom
tarun-etikala:feat/ruff-linting
Closed

chore: add ruff linting and formatting#80
tarun-etikala wants to merge 9 commits into
red-hat-data-services:mainfrom
tarun-etikala:feat/ruff-linting

Conversation

@tarun-etikala
Copy link
Copy Markdown
Contributor

@tarun-etikala tarun-etikala commented Apr 24, 2026

Description

Add ruff linting/formatting and pre-commit hooks to enforce consistent Python code style across the repo.

  • Add ruff.toml with Python 3.12 target, E/F/I rule set, and per-file-ignores for intentional E402 patterns
  • Add .pre-commit-config.yaml with SHA-pinned ruff hooks and pre-commit-hooks bundle (trailing-whitespace, end-of-file-fixer, check-yaml, check-added-large-files)
  • Add .github/workflows/ruff.yml — blocking CI check with inline PR annotations, SHA-pinned actions, concurrency groups, minimal permissions, 10-min timeout
  • Apply ruff auto-fixes (import sorting) and formatting across 87 Python files
  • Fix 3 bugs caught by ruff: F821 (undefined getenv), F841 (unused variable), E721 (incorrect type comparison)
  • Add pre-commit setup instructions to CONTRIBUTING.md

Jira Ticket

RHAIENG-4067

Testing

  • make test passes (run from the affected agent directory)

  • Manual testing performed (describe steps below)

  • No testing required (documentation/config change only)

  • CI workflow Ruff passes on this PR (ruff check + ruff format --check)

  • ruff check . locally — all checks pass

  • ruff format --check . locally — no formatting changes needed

  • pre-commit run --all-files locally — all hooks pass

Checklist

  • I have read CONTRIBUTING.md
  • No .env or secret files are included in this PR
  • All changes are within scope of the linked Jira ticket (if not, explain in Description)

Review Guidance

  • The bulk of the diff (87 files) is mechanical ruff auto-formatting and import sorting — safe to skim
  • Focus review on ruff.toml (rule selection, per-file-ignores), .pre-commit-config.yaml (hook config), and .github/workflows/ruff.yml (CI workflow)
  • Three real bug fixes worth verifying: search the diff for F821, F841, E721 comments or check the commit style: apply ruff auto-fixes and formatting

Related PRs

None

tarun-etikala and others added 8 commits April 23, 2026 09:44
feat: add PR labeler workflow with path and size labels
- Fix image exclusion to match nested directories at any depth
  (agents/*/images/*, etc.) instead of only top-level images/*
- Only catch 404 in ensure_label_exists, re-raise 403/429/500
- Pin PyGithub==2.6.0 to avoid supply-chain risk in pull_request_target
- Add warning step when size labeling fails for better observability

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Avoids noisy "removed size/xl, added size/xl" timeline entries
when a push doesn't change the PR's size bucket.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: skip label remove/add cycle when size bucket unchanged
- SHA-pin all actions to match repo convention (agent-deployment-test.yaml)
- Add concurrency group to prevent parallel runs on the same PR
- Collect-then-act pattern in update_size_label to handle stale labels
  that appear after the matching label in iteration order

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: address CodeRabbit review — SHA-pin, concurrency, defensive labels
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

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: CHILL

Plan: Enterprise

Run ID: 7e0aefd5-5ea7-4550-b761-eafd409e729e

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
📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive code linting and formatting infrastructure using Ruff. A GitHub Actions workflow, pre-commit configuration, and Ruff configuration file are added. Across ~100 agent and test files, import statements are reordered, function signatures reformatted for readability, and unnecessary blank lines removed to enforce consistent code style.

Changes

Cohort / File(s) Summary
Linting & CI Configuration
.github/workflows/ruff.yml, .pre-commit-config.yaml, ruff.toml
Introduces Ruff linting and formatting infrastructure: GitHub Actions workflow for CI, pre-commit hooks configuration with automatic fixes, and Ruff linting rules targeting Python 3.12 with line length 88 and per-path exceptions for import ordering.
Documentation
CONTRIBUTING.md
Adds "Local development setup" section documenting pre-commit installation and usage for contributors.
A2A LangGraph CrewAI Agent
agents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/*.py
Import reordering and blank-line removal; SSE tool-call list comprehension reformatted to multi-line form without behavioral changes.
AutoGen MCP Agent
agents/autogen/mcp_agent/main.py, agents/autogen/mcp_agent/mcp_automl_template/*.py, agents/autogen/mcp_agent/src/autogen_agent_base/*.py
Import reordering, import deduplication, and formatting adjustments to function signatures and logging statements; no functional logic altered.
CrewAI WebSearch Agent
agents/crewai/websearch_agent/examples/*.py, agents/crewai/websearch_agent/main.py, agents/crewai/websearch_agent/playground/app.py, agents/crewai/websearch_agent/src/crewai_web_search/*.py
Import reordering, multi-line import and function signature formatting, logger statement reformatting; MLflow tracing wrapper call reformatted without behavior change.
Google ADK Agent
agents/google/adk/examples/*.py, agents/google/adk/main.py, agents/google/adk/src/adk_agent/agent.py
Import reordering and consolidation, multi-line import/ternary/dict formatting for improved readability without functional changes.
LangGraph Agentic RAG
agents/langgraph/agentic_rag/data/*.py, agents/langgraph/agentic_rag/examples/*.py, agents/langgraph/agentic_rag/main.py, agents/langgraph/agentic_rag/playground/app.py, agents/langgraph/agentic_rag/src/agentic_rag/*.py, agents/langgraph/agentic_rag/tests/test_tools.py
Import reordering, deduplication, and removal of blank lines; conditional expression reformatting; one test file changes getenv() to os.getenv() for consistency.
LangGraph Human in the Loop
agents/langgraph/human_in_the_loop/examples/*.py, agents/langgraph/human_in_the_loop/main.py, agents/langgraph/human_in_the_loop/src/human_in_the_loop/tracing.py
Import reordering and deduplication, multi-line import/function signature/dict formatting, logger call reformatting, and removal of blank lines.
LangGraph React Agent
agents/langgraph/react_agent/examples/*.py, agents/langgraph/react_agent/main.py, agents/langgraph/react_agent/playground/app.py, agents/langgraph/react_agent/src/react_agent/tracing.py, agents/langgraph/react_agent/tests/behavioral/*.py, agents/langgraph/react_agent/tests/test_tools.py
Import reordering, blank-line removal, and multi-line formatting of imports/signatures/dicts; test assertion messages simplified from multi-line f-strings to single-line equivalents.
LangGraph React with Database Memory
agents/langgraph/react_with_database_memory/examples/*.py, agents/langgraph/react_with_database_memory/main.py, agents/langgraph/react_with_database_memory/playground/app.py, agents/langgraph/react_with_database_memory/src/react_with_database_memory/*.py, agents/langgraph/react_with_database_memory/tests/test_memory_fifo.ipynb
Import reordering, blank-line adjustments, multi-line import/dict formatting, unused variable removal, and isinstance-check refactoring; notebook cell source fields reformatted from multi-line strings to arrays.
LLamaIndex WebSearch Agent
agents/llamaindex/websearch_agent/examples/*.py, agents/llamaindex/websearch_agent/main.py, agents/llamaindex/websearch_agent/playground/app.py, agents/llamaindex/websearch_agent/src/websearch_agent/*.py, agents/llamaindex/websearch_agent/tests/test_tools.py
Import reordering and consolidation, whitespace adjustments around blank lines, multi-line import/dict formatting; test import ordering updated.
Vanilla Python OpenAI Responses Agent
agents/vanilla_python/openai_responses_agent/examples/*.py, agents/vanilla_python/openai_responses_agent/main.py, agents/vanilla_python/openai_responses_agent/playground/app.py, agents/vanilla_python/openai_responses_agent/src/openai_responses_agent/*.py, agents/vanilla_python/openai_responses_agent/tests/behavioral/*.py
Import reordering, multi-line formatting of imports/function signatures/ternary expressions, test function signature condensing, and assertion message simplification.
Behavioral Test Infrastructure
tests/behavioral/adversarial/*.py, tests/behavioral/api_contract/test_api_contract.py, tests/behavioral/conftest.py, tests/behavioral/harness/*.py
Import reordering, blank-line removal, multi-line function signature/logger/regex formatting, assertion message simplification, and test parametrization string quoting adjustments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and concisely summarizes the main change: adding ruff linting and formatting configuration to the repository.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly articulates the purpose, scope, and technical details of adding ruff linting/formatting configuration and applying consistent code style.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@github-actions
Copy link
Copy Markdown

Large PR detected (1450 lines changed)

This PR exceeds 1200 lines of code changes (excluding lock files, generated content, and images). Large PRs are harder to review thoroughly and are more likely to introduce bugs.

Consider splitting this PR into smaller, focused changes.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py (1)

16-26: ⚠️ Potential issue | 🔴 Critical

Add validation for missing environment variables.

The function will raise TypeError if any required environment variables are not set, because getenv() returns None by default, and quote_plus(None) fails. This is a pre-existing reliability issue unrelated to this PR's formatting changes, but should be addressed to prevent runtime crashes.

🛡️ Proposed fix to add validation
 def get_database_uri() -> str:
     """
     Construct PostgresSQL database URI from environment variables.
 
     Expected env vars:
     - POSTGRES_HOST
     - POSTGRES_PORT
     - POSTGRES_DB
     - POSTGRES_USER
     - POSTGRES_PASSWORD
     """
     host = getenv("POSTGRES_HOST")
     user = getenv("POSTGRES_USER")
     password = getenv("POSTGRES_PASSWORD")
     database = getenv("POSTGRES_DB")
     port = getenv("POSTGRES_PORT")
+
+    missing = [
+        name for name, value in [
+            ("POSTGRES_HOST", host),
+            ("POSTGRES_USER", user),
+            ("POSTGRES_PASSWORD", password),
+            ("POSTGRES_DB", database),
+            ("POSTGRES_PORT", port),
+        ] if value is None
+    ]
+    if missing:
+        raise ValueError(f"Missing required environment variables: {', '.join(missing)}")
 
     safe_host = quote_plus(host)
     safe_user = quote_plus(user)
     safe_password = quote_plus(password)
 
     return f"postgresql://{safe_user}:{safe_password}@{safe_host}:{port}/{database}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py`
around lines 16 - 26, The code constructs a PostgreSQL URL from environment vars
(host, user, password, database, port) but calls quote_plus on values that may
be None; update the function to validate these env vars before encoding: read
host, user, password, database, port via getenv, collect any that are missing,
and if any are missing raise a clear ValueError listing the missing names; only
after validation call quote_plus to create safe_host/safe_user/safe_password and
then return the formatted connection string as before (ensure you reference the
existing identifiers host, user, password, database, port, quote_plus,
safe_host/safe_user/safe_password, and the final return string).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py`:
- Around line 16-26: The code constructs a PostgreSQL URL from environment vars
(host, user, password, database, port) but calls quote_plus on values that may
be None; update the function to validate these env vars before encoding: read
host, user, password, database, port via getenv, collect any that are missing,
and if any are missing raise a clear ValueError listing the missing names; only
after validation call quote_plus to create safe_host/safe_user/safe_password and
then return the formatted connection string as before (ensure you reference the
existing identifiers host, user, password, database, port, quote_plus,
safe_host/safe_user/safe_password, and the final return string).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: b19dc3d9-4ae8-4ac4-a261-22cd3bc606af

📥 Commits

Reviewing files that changed from the base of the PR and between 3893a2b and be4f70e.

📒 Files selected for processing (91)
  • .github/workflows/ruff.yml
  • .pre-commit-config.yaml
  • CONTRIBUTING.md
  • agents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/a2a_reply.py
  • agents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/crew_a2a_server.py
  • agents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/langgraph_a2a_server.py
  • agents/autogen/mcp_agent/main.py
  • agents/autogen/mcp_agent/mcp_automl_template/interact_with_mcp.py
  • agents/autogen/mcp_agent/mcp_automl_template/mcp_server.py
  • agents/autogen/mcp_agent/mcp_automl_template/register_tools.py
  • agents/autogen/mcp_agent/mcp_automl_template/utils.py
  • agents/autogen/mcp_agent/src/autogen_agent_base/agent.py
  • agents/autogen/mcp_agent/src/autogen_agent_base/tracing.py
  • agents/crewai/websearch_agent/examples/_interactive_chat.py
  • agents/crewai/websearch_agent/examples/ai_service.py
  • agents/crewai/websearch_agent/main.py
  • agents/crewai/websearch_agent/playground/app.py
  • agents/crewai/websearch_agent/src/crewai_web_search/crew.py
  • agents/crewai/websearch_agent/src/crewai_web_search/tools/__init__.py
  • agents/crewai/websearch_agent/src/crewai_web_search/tracing.py
  • agents/google/adk/examples/_interactive_chat.py
  • agents/google/adk/examples/ai_service.py
  • agents/google/adk/main.py
  • agents/google/adk/src/adk_agent/agent.py
  • agents/langgraph/agentic_rag/data/load_documents.py
  • agents/langgraph/agentic_rag/examples/_interactive_chat.py
  • agents/langgraph/agentic_rag/examples/ai_service.py
  • agents/langgraph/agentic_rag/main.py
  • agents/langgraph/agentic_rag/playground/app.py
  • agents/langgraph/agentic_rag/src/agentic_rag/agent.py
  • agents/langgraph/agentic_rag/src/agentic_rag/tools.py
  • agents/langgraph/agentic_rag/src/agentic_rag/tracing.py
  • agents/langgraph/agentic_rag/tests/test_tools.py
  • agents/langgraph/human_in_the_loop/examples/_interactive_chat.py
  • agents/langgraph/human_in_the_loop/examples/ai_service.py
  • agents/langgraph/human_in_the_loop/examples/execute_ai_service_locally.py
  • agents/langgraph/human_in_the_loop/main.py
  • agents/langgraph/human_in_the_loop/src/human_in_the_loop/tracing.py
  • agents/langgraph/react_agent/examples/_interactive_chat.py
  • agents/langgraph/react_agent/examples/ai_service.py
  • agents/langgraph/react_agent/main.py
  • agents/langgraph/react_agent/playground/app.py
  • agents/langgraph/react_agent/src/react_agent/tracing.py
  • agents/langgraph/react_agent/tests/behavioral/conftest.py
  • agents/langgraph/react_agent/tests/behavioral/test_response_quality.py
  • agents/langgraph/react_agent/tests/behavioral/test_tool_usage.py
  • agents/langgraph/react_agent/tests/test_tools.py
  • agents/langgraph/react_with_database_memory/examples/_interactive_chat.py
  • agents/langgraph/react_with_database_memory/examples/ai_service.py
  • agents/langgraph/react_with_database_memory/examples/clear_thread_history.py
  • agents/langgraph/react_with_database_memory/examples/execute_ai_service_locally.py
  • agents/langgraph/react_with_database_memory/examples/query_existing_deployment.py
  • agents/langgraph/react_with_database_memory/examples/test_memory_fifo.ipynb
  • agents/langgraph/react_with_database_memory/main.py
  • agents/langgraph/react_with_database_memory/playground/app.py
  • agents/langgraph/react_with_database_memory/src/react_with_database_memory/agent.py
  • agents/langgraph/react_with_database_memory/src/react_with_database_memory/tracing.py
  • agents/langgraph/react_with_database_memory/src/react_with_database_memory/utils.py
  • agents/llamaindex/websearch_agent/examples/_interactive_chat.py
  • agents/llamaindex/websearch_agent/examples/ai_service.py
  • agents/llamaindex/websearch_agent/main.py
  • agents/llamaindex/websearch_agent/playground/app.py
  • agents/llamaindex/websearch_agent/src/websearch_agent/__init__.py
  • agents/llamaindex/websearch_agent/src/websearch_agent/tracing.py
  • agents/llamaindex/websearch_agent/src/websearch_agent/workflow.py
  • agents/llamaindex/websearch_agent/tests/test_tools.py
  • agents/vanilla_python/openai_responses_agent/examples/_interactive_chat.py
  • agents/vanilla_python/openai_responses_agent/examples/ai_service.py
  • agents/vanilla_python/openai_responses_agent/main.py
  • agents/vanilla_python/openai_responses_agent/playground/app.py
  • agents/vanilla_python/openai_responses_agent/src/openai_responses_agent/__init__.py
  • agents/vanilla_python/openai_responses_agent/src/openai_responses_agent/agent.py
  • agents/vanilla_python/openai_responses_agent/src/openai_responses_agent/tracing.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/conftest.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/test_cost_latency.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/test_reliability.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/test_response_quality.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/test_tool_usage.py
  • ruff.toml
  • tests/behavioral/adversarial/conftest.py
  • tests/behavioral/adversarial/test_boundary_conditions.py
  • tests/behavioral/adversarial/test_prompt_injection.py
  • tests/behavioral/adversarial/test_safety.py
  • tests/behavioral/api_contract/test_api_contract.py
  • tests/behavioral/conftest.py
  • tests/behavioral/harness/__init__.py
  • tests/behavioral/harness/mlflow_client.py
  • tests/behavioral/harness/runner.py
  • tests/behavioral/harness/scorers/plan_coherence.py
  • tests/behavioral/harness/scorers/safety.py
  • tests/behavioral/harness/scorers/tool_sequence.py
💤 Files with no reviewable changes (7)
  • agents/autogen/mcp_agent/mcp_automl_template/register_tools.py
  • agents/a2a/langgraph_crewai_agent/src/a2a_langgraph_crewai/a2a_reply.py
  • agents/langgraph/react_with_database_memory/src/react_with_database_memory/agent.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/test_cost_latency.py
  • agents/autogen/mcp_agent/mcp_automl_template/mcp_server.py
  • agents/vanilla_python/openai_responses_agent/tests/behavioral/test_reliability.py
  • agents/crewai/websearch_agent/src/crewai_web_search/tools/init.py

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant