Skip to content
Open
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
8 changes: 0 additions & 8 deletions .flake8

This file was deleted.

11 changes: 6 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install flake8
- name: Install black and ruff
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run flake8
pip install black ruff
- name: Run black and ruff
run: |
flake8 codegraph/ tests/
black .
ruff check .

tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -115,4 +116,4 @@ jobs:
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@v4
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

16 changes: 4 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
repos:
- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
hooks:
- id: seed-isort-config
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/ambv/black
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
language_version: python3.12
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: flake8
- id: ruff
36 changes: 28 additions & 8 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ codegraph/
│ ├── __init__.py # Package init, version definition
│ ├── main.py # CLI entry point (click-based)
│ ├── core.py # Core graph building logic
│ ├── parser.py # Python source code parser
│ ├── parser.py # Python token parser (legacy, used by PythonParser)
│ ├── parsers/ # Pluggable language parsers
│ │ ├── base.py # Parser interface
│ │ ├── python_parser.py # Python parser implementation
│ │ ├── rust_parser.py # Rust parser stub
│ │ ├── registry.py # Parser registry / discovery
│ ├── utils.py # Utility functions
│ └── vizualyzer.py # Visualization (D3.js + matplotlib)
├── tests/ # Test suite
Expand All @@ -30,9 +35,25 @@ codegraph/

## Core Components

### 1. Parser (`codegraph/parser.py`)
### 1. Parser Layer (`codegraph/parsers/`)

The parser uses Python's `tokenize` module to extract code structure from source files.
Parser implementations are pluggable via a registry. Each parser exposes:
- `get_source_files()` for language-specific file discovery
- `parse_files()` to produce module objects
- `usage_graph()` to build dependencies
- `get_entity_metadata()` for entity stats

This allows adding new languages without changing core graph orchestration.

#### Python Parser (`codegraph/parsers/python_parser.py`)

Uses Python's `ast` (and `typed_ast` for Python 2.x) to extract classes, functions,
imports, and line ranges.

#### Rust Parser (`codegraph/parsers/rust_parser.py`)

Currently a stub to establish extension points. The intent is to parse `.rs` files,
extract functions/structs/impl blocks, and build dependency edges using a Rust-aware parser.

**Key Classes:**
- `_Object` - Base class for all parsed objects (lineno, endno, name, parent)
Expand All @@ -52,16 +73,15 @@ The parser uses Python's `tokenize` module to extract code structure from source

### 2. Core (`codegraph/core.py`)

The core module builds the dependency graph from parsed data.
The core module orchestrates parsing and visualization by delegating language-specific
work to the selected parser.

**Key Classes:**
- `CodeGraph` - Main class that orchestrates graph building

**Key Functions:**
- `get_code_objects(paths_list)` - Parse all files and return dict of module → objects
- `get_imports_and_entities_lines()` - Extract imports and entity line ranges
- `collect_entities_usage_in_modules()` - Find where entities are used
- `search_entity_usage()` - Check if entity is used in a line
- `usage_graph()` - Delegates to the active parser
- `get_entity_metadata()` - Delegates to the active parser

**Data Flow:**
```
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ 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.3.0] - 2026-01-24

### Added

- Pluggable parser architecture with registry and base parser interface
- Rust parser stub to establish language extension points
- AST-based Python parser with cross-version parsing support (Python 2.x via typed-ast)
- CLI options for language selection and target Python version
- Expanded test coverage for parsers, registry/utils, visualizer helpers, and legacy parser objects

### Changed

- Core now delegates parsing and dependency analysis to language parsers
- Python dependency detection now uses AST rather than token scanning
- Utilities now support multi-extension file discovery

### Fixed

- Legacy parser now handles comma-separated imports in a single statement
- Removed known false positives from string literals and alias leakage (AST parser)

## [1.2.0] - 2026-01-18

### Added
Expand Down
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ To follow code styles and successfully pass github pipelines install pre-commit

pre-commit install

```
```

### Formatting and linting

Before committing changes, run the formatter and linter:

```
black .
ruff check .
```
2 changes: 1 addition & 1 deletion codegraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.3.0"
Loading