Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,48 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest matplotlib networkx click
- name: Run tests
pip install pytest pytest-cov matplotlib networkx click
- name: Run tests with coverage
run: |
pytest tests/ -v --cov=codegraph --cov-report=term-missing --cov-report=xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false

package-test:
runs-on: ubuntu-latest
needs: [lint]
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Build package
run: |
python -m pip install --upgrade pip build
python -m build --wheel
- name: Test package without matplotlib
run: |
pip install dist/codegraph-*.whl
pip install pytest
pytest tests/test_package_install.py -v
- name: Test package with matplotlib
run: |
pip install --force-reinstall dist/codegraph-*.whl
pip install matplotlib networkx
pytest tests/ -v

deploy-demo:
runs-on: ubuntu-latest
needs: [tests]
needs: [tests, package-test]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: github-pages
Expand All @@ -65,7 +99,6 @@ jobs:
- name: Install codegraph
run: |
python -m pip install --upgrade pip
pip install matplotlib networkx click
pip install -e .
- name: Clone simple-ddl-parser for demo
run: |
Expand Down
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2025-01-18

### Added

**Massive Objects Detection**
- New "Massive Objects" panel to find large code entities by lines of code
- Filter by type: modules, classes, functions
- Configurable threshold (default: 50 lines)
- Click on any item to highlight it on the graph

**Lines of Code Tracking**
- Each entity (function, class, module) now tracks lines of code
- Lines of code displayed in tooltips
- Node size scales based on lines of code (toggleable in Display panel)

**Improved UI Panels**
- All panels are now draggable - move them anywhere on screen
- All panels are collapsible - click the toggle button to minimize
- Display panel with "Size by lines of code" toggle

**Smart Initial Zoom**
- Graph now auto-zooms based on node count
- Large graphs start more zoomed out for better overview

### Changed

**matplotlib is now optional**
- D3.js visualization works without matplotlib installed
- Install with `pip install codegraph[matplotlib]` for legacy matplotlib support
- Reduces installation size and dependencies for most users

### Testing
- Added package installation tests (`tests/test_package_install.py`)
- Tests verify package works without matplotlib
- Added CI jobs for package build and installation testing
- tox environments for testing with and without matplotlib

## [1.0.0] - 2025-01-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion codegraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.0"
__version__ = "1.1.0"
31 changes: 31 additions & 0 deletions codegraph/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ def get_lines_numbers(self):
data[module][func.name] = (func.lineno, func.endno)
return data

def get_entity_metadata(self) -> Dict:
"""
Return metadata for all entities including line counts and types.
:return: {module_path: {entity_name: {'lines': int, 'type': 'function'|'class'}}}
"""
from codegraph.parser import Class, Function, AsyncFunction, Import

data = {}
for module_path in self.modules_data:
data[module_path] = {}
for entity in self.modules_data[module_path]:
if isinstance(entity, Import):
continue
lines = 0
if entity.lineno and entity.endno:
lines = entity.endno - entity.lineno + 1

entity_type = "function"
if isinstance(entity, Class):
entity_type = "class"
elif isinstance(entity, (Function, AsyncFunction)):
entity_type = "function"

data[module_path][entity.name] = {
"lines": lines,
"entity_type": entity_type,
"lineno": entity.lineno,
"endno": entity.endno
}
return data

def usage_graph(self) -> Dict:
"""
module name: function
Expand Down
3 changes: 2 additions & 1 deletion codegraph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def cli(paths, object_only, file_path, distance, matplotlib, output):
def main(args):
code_graph = core.CodeGraph(args)
usage_graph = code_graph.usage_graph()
entity_metadata = code_graph.get_entity_metadata()

if args.file_path and args.distance:
dependencies = code_graph.get_dependencies(args.file_path, args.distance)
Expand All @@ -77,7 +78,7 @@ def main(args):
if args.matplotlib:
vz.draw_graph_matplotlib(usage_graph)
else:
vz.draw_graph(usage_graph, output_path=args.output)
vz.draw_graph(usage_graph, entity_metadata=entity_metadata, output_path=args.output)


if __name__ == "__main__":
Expand Down
Loading