Skip to content

Implementation of Module Dependency Visualization Enhancements #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 114 commits into
base: develop
Choose a base branch
from

Conversation

codegen-sh[bot]
Copy link

@codegen-sh codegen-sh bot commented May 17, 2025

This PR implements enhanced module dependency visualization features for the Codegen repository as specified in issue ZAM-424.

Features Implemented

  1. Enhanced Module Dependency Visualization

    • Created a new ModuleDependencyGraph class for detailed module dependency analysis
    • Added support for detecting and highlighting circular dependencies
    • Implemented filtering options by module path and dependency depth
    • Added metrics calculation for module analysis
  2. Interactive Features

    • Enhanced visualization with tooltips showing detailed module information
    • Added visual attributes for better understanding of dependencies
    • Implemented node sizing based on importance metrics
    • Added edge width based on dependency strength
  3. Improved Visual Representation

    • Highlighted circular dependencies in red
    • Sized nodes based on their connectivity
    • Added detailed tooltips with module metrics
    • Enhanced edge styling based on relationship type
  4. Documentation and Examples

    • Updated the codebase visualization documentation with detailed examples
    • Created a new enhanced module dependency visualization example
    • Added best practices for handling large dependency graphs
  5. Testing

    • Added comprehensive unit tests for the new module dependency visualization features

Files Modified

  • src/codegen/visualizations/module_dependency_viz.py (new file)
  • src/codegen/visualizations/visualization_manager.py
  • src/codegen/visualizations/viz_utils.py
  • codegen-examples/examples/modules_dependencies/enhanced_module_viz.py (new file)
  • docs/building-with-codegen/codebase-visualization.mdx
  • tests/codegen/visualizations/test_module_dependency_viz.py (new file)

Resolves ZAM-424


💻 View my workAbout Codegen

Summary by Sourcery

Implement enhanced module dependency visualization by introducing a dedicated graph class with analysis, filtering, and styling capabilities, integrating it into the visualization manager, and providing documentation, examples, and tests for interactive codebase visualization.

New Features:

  • Introduce ModuleDependencyGraph and build_module_dependency_graph for comprehensive module dependency analysis and visualization
  • Enable detection and highlighting of circular dependencies with path- and depth-based filtering

Enhancements:

  • Add apply_visual_attributes, add_tooltips, and filter_graph_by_node_attribute utilities for customizing graph styling and interactivity
  • Extend VisualizationManager to handle ModuleDependencyGraph instances alongside standard NetworkX graphs
  • Compute module metrics (degree, centrality, import counts) and convert graphs to JSON for visualization

Documentation:

  • Update codebase visualization guide with enhanced dependency visualization examples and best practices
  • Add usage sections for interactive visualization utilities and advanced examples in documentation

Tests:

  • Add unit tests for ModuleDependencyGraph functionality, build_module_dependency_graph, and visualization utilities

clee-codegen and others added 30 commits February 26, 2025 23:54
# Motivation

The **Codegen on OSS** package provides a pipeline that:

- **Collects repository URLs** from different sources (e.g., CSV files
or GitHub searches).
- **Parses repositories** using the codegen tool.
- **Profiles performance** and logs metrics for each parsing run.
- **Logs errors** to help pinpoint parsing failures or performance
bottlenecks.

<!-- Why is this change necessary? -->

# Content

<!-- Please include a summary of the change -->
see
[codegen-on-oss/README.md](https://github.com/codegen-sh/codegen-sdk/blob/acfe3dc07b65670af33b977fa1e7bc8627fd714e/codegen-on-oss/README.md)

# Testing

<!-- How was the change tested? -->
`uv run modal run modal_run.py`
No unit tests yet 😿 

# Please check the following before marking your PR as ready for review

- [ ] I have added tests for my changes
- [x] I have updated the documentation or added new documentation as
needed
Original commit by Tawsif Kamal: Revert "Revert "Adding Schema for Tool Outputs"" (codegen-sh#894)

Reverts codegen-sh#892

---------

Co-authored-by: Rushil Patel <[email protected]>
Co-authored-by: rushilpatel0 <[email protected]>
Original commit by Ellen Agarwal: fix: Workaround for relace not adding newlines (codegen-sh#907)
Copy link

sourcery-ai bot commented May 17, 2025

Reviewer's Guide

This PR introduces a comprehensive ModuleDependencyGraph implementation for detailed module dependency analysis and visualization, extends the existing viz_utils with new utilities, integrates the new graph type into the visualization manager, updates documentation and examples with enhanced visualization workflows, and adds end-to-end unit tests for the new features.

Sequence Diagram for Building Module Dependency Graph

sequenceDiagram
    actor User
    participant BMDG as build_module_dependency_graph
    participant MDG as ModuleDependencyGraph
    participant SF as SourceFile

    User->>BMDG: build_module_dependency_graph(files, include_external, path_filter)
    activate BMDG
    BMDG->>MDG: __init__()
    activate MDG
    deactivate MDG
    loop For each file in files
        BMDG->>MDG: add_module(file)
        activate MDG
        deactivate MDG
        BMDG->>SF: get import_statements
        loop For each import in file
            BMDG->>SF: get resolved_symbol
            alt Internal dependency
                BMDG->>MDG: add_dependency(file, target_file, import_obj)
                activate MDG
                deactivate MDG
            end
        end
    end
    BMDG->>MDG: detect_circular_dependencies()
    activate MDG
    MDG-->>BMDG: circular_dependencies_list
    deactivate MDG
    BMDG-->>User: module_dependency_graph_instance
    deactivate BMDG
Loading

Class Diagram for Module Dependency Visualization Enhancements

classDiagram
    class ModuleDependencyGraph {
        +graph: DiGraph
        +modules: Dict
        +dependencies: Dict
        +circular_dependencies: List
        +__init__()
        +add_module(module, attributes)
        +add_dependency(source_module, target_module, import_obj, attributes)
        +detect_circular_dependencies(): List[List[str]]
        +filter_by_module_path(path_prefix: str): ModuleDependencyGraph
        +filter_by_depth(root_module, max_depth: int): ModuleDependencyGraph
        +get_module_metrics(): Dict
        +to_visualization_graph(): DiGraph
        +to_json(root): str
    }
    note for ModuleDependencyGraph "Manages module dependencies and their visualization properties."

    class VisualizationManager {
        +write_graphviz_data(G: Union[Graph, go.Figure, ModuleDependencyGraph], root: Optional[Union[Editable, str, int]])
    }
    note for VisualizationManager "Handles writing graph data for visualization. write_graphviz_data now supports ModuleDependencyGraph."

    ModuleDependencyGraph ..> DiGraph : uses
    VisualizationManager ..> ModuleDependencyGraph : uses
Loading

File-Level Changes

Change Details Files
Implement ModuleDependencyGraph for enhanced dependency analysis
  • New class tracking modules, dependencies, and import weights
  • Circular dependency detection and marking on nodes/edges
  • Filtering by module path and by dependency depth
  • Metrics computation and conversion to visualization graph/json
src/codegen/visualizations/module_dependency_viz.py
Extend visualization utilities in viz_utils
  • apply_visual_attributes to set node/edge size, color, width defaults
  • add_tooltips to generate contextual tooltips from attributes
  • filter_graph_by_node_attribute to narrow graphs by node metadata
src/codegen/visualizations/viz_utils.py
Integrate ModuleDependencyGraph into visualization manager
  • Import ModuleDependencyGraph and builder function
  • Extend write_graphviz_data to recognize ModuleDependencyGraph and serialize via to_json
src/codegen/visualizations/visualization_manager.py
Update documentation and examples
  • Document enhanced module dependency visualization and utilities in codebase-visualization.mdx
  • Add best practices and advanced examples for filtering and interactivity
  • Provide a new example script for enhanced module visualization
docs/building-with-codegen/codebase-visualization.mdx
codegen-examples/examples/modules_dependencies/enhanced_module_viz.py
Add comprehensive unit tests
  • Test ModuleDependencyGraph methods (add, detect cycles, filter, metrics, to_visualization)
  • Test build_module_dependency_graph produces and configures graphs correctly
tests/codegen/visualizations/test_module_dependency_viz.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

Copy link

korbit-ai bot commented May 17, 2025

By default, I don't review pull requests opened by bots. If you would like me to review this pull request anyway, you can request a review via the /korbit-review command in a comment.

Copy link

coderabbitai bot commented May 17, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

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


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Author

codegen-sh bot commented May 17, 2025

I see a check failed - I'm on it! 🫡

💻 View my work

Copy link
Author

codegen-sh bot commented May 17, 2025

✅ Fixed the failing check in PR #134. The issue was a bare except: statement in the module_dependency_viz.py file, which is against the coding standards. I've replaced it with except Exception: to be more specific about the exception being caught.

The fix has been pushed to the PR branch in this commit.

💻 View my work • React 👍 or 👎

Copy link
Author

codegen-sh bot commented May 17, 2025

I see a check failed - I'm on it! 🫡

💻 View my work

Copy link
Author

codegen-sh bot commented May 17, 2025

✅ Fixed the failing check suite in PR #134. The issues were:

  1. Type handling in visualization_manager.py:
    • Added proper TYPE_CHECKING imports
    • Fixed circular import issue with ModuleDependencyGraph
    • Added proper Union and Optional type hints
    • Added runtime type checking for ModuleDependencyGraph

The fix has been pushed to the PR branch in this commit.

💻 View my work • React 👍 or 👎

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.

2 participants