Skip to content

Analyze Data Flow

Analyze data flow

flows = DataFlowAnalyzer(repo_root).analyze_file(file_path)

print(f"Symbols: {len(symbols.symbols)}") print(f"Imports: {len(imports)}") print(f"Calls: {len(calls)}") print(f"Types: {len(types)}") print(f"Data flows: {len(flows)}")

#### Pattern 5: Analyze From Source String

```python
from cogant.static import SymbolExtractor
from pathlib import Path

source = """
def hello(name: str) -> str:
    return f"Hello, {name}!"

class Greeter:
    def greet(self, name: str) -> str:
        return f"Hi, {name}!"
"""

extractor = SymbolExtractor()
table = extractor.extract_from_source(source, Path("example.py"))

Data Structure Quick Reference

RepoSnapshot

RepoSnapshot
├── metadata: RepoMetadata
│   ├── name: str
│   ├── url: str
│   ├── commit_hash: str
│   ├── commit_message: str
│   ├── author: str
│   ├── language: str
│   └── timestamp: datetime
├── files: List[FileInfo]
│   └── FileInfo
│       ├── path: Path
│       ├── relative_path: str
│       ├── language: str
│       ├── size_bytes: int
│       ├── is_test: bool
│       └── checksum: str
├── dependencies: List[Dependency]
│   └── Dependency
│       ├── name: str
│       ├── version: str
│       ├── is_dev: bool
│       └── is_local: bool
└── root_path: Path

SymbolTable

SymbolTable
├── file_path: Path
├── symbols: List[SymbolInfo]
│   └── SymbolInfo
│       ├── id: str (stable hash)
│       ├── name: str
│       ├── qualified_name: str
│       ├── kind: str (function|class|method|variable)
│       ├── scope: str
│       ├── parent_id: str
│       ├── decorators: List[str]
│       ├── doc: str
│       └── metadata: Dict
└── errors: List[str]

ImportEdge

ImportEdge
├── id: str (stable hash)
├── source_file: Path
├── module_name: str
├── is_relative: bool
├── is_stdlib: bool
├── is_third_party: bool
├── is_local: bool
├── resolved_file: Path
├── line_num: int
├── imported_names: List[str]
└── metadata: Dict

CallEdge

CallEdge
├── id: str (stable hash)
├── source_file: Path
├── caller_id: str
├── caller_name: str
├── callee_name: str
├── callee_id: str
├── line_num: int
├── is_method_call: bool
├── receiver: str
├── args: List[str]
└── metadata: Dict

TypeInfo

TypeInfo
├── symbol_id: str
├── symbol_name: str
├── symbol_kind: str
├── inferred_type: str
├── annotation: str
├── confidence: float (0.0-1.0)
├── is_mutable: bool
└── metadata: Dict

DataFlowEdge

DataFlowEdge
├── id: str (stable hash)
├── source_symbol: str
├── target_symbol: str
├── edge_type: str (reads|writes|mutates|depends_on)
├── file_path: Path
├── line_num: int
├── context: str
└── metadata: Dict

Testing

Run the integration test suite:

cd <package-root>   # the directory containing py/, tests/, pyproject.toml
uv run pytest tests/ -q --no-cov

Expected output: All 8 tests passing

Tests include: - FileEnumerator - PythonASTParser - SymbolExtractor - ImportAnalyzer - CallGraphBuilder - TypeInferencer - DataFlowAnalyzer - ManifestParser

File Paths

All files are located relative to the package root (the directory containing py/, tests/, pyproject.toml):

Ingest Stage: - py/cogant/ingest/__init__.py - py/cogant/ingest/repo.py - py/cogant/ingest/files.py - py/cogant/ingest/manifest.py

Static Analysis Stage: - py/cogant/static/__init__.py - py/cogant/static/parser.py - py/cogant/static/symbols.py - py/cogant/static/imports.py - py/cogant/static/calls.py - py/cogant/static/types.py - py/cogant/static/dataflow.py

Tests & Documentation: - tests/integration/ — end-to-end pipeline integration tests (pytest) - tests/test_engine.py — pipeline integration tests - Detailed pipeline guide (sibling doc) - Reference index (ingest milestone) - Pipeline module index (sibling doc)

Supported Languages

File enumeration detects and enumerates the languages with registered parsers (see cogant.parsers for the canonical capability list): - Python (.py, .pyi, .pyx) - JavaScript (.js, .jsx, .mjs, .cjs) - TypeScript (.ts, .tsx) - Rust (.rs) - Go (.go)

Manifest Formats Supported

  • Python: setup.py, pyproject.toml, requirements.txt
  • Node.js: package.json
  • Rust: Cargo.toml

Next Steps

The pipeline outputs are ready to be fed into:

  1. Graph Construction Layer - Convert to program graph nodes/edges
  2. GNN Translation - Compile Generalized Notation Notation (Active Inference Institute) state-space and process-model artifacts
  3. Semantic Analysis - Derive hidden-state / observation / action / policy mappings
  4. Pattern Recognition - Identify architectural patterns (event buses, schedulers, retry loops)

For detailed information, see Detailed pipeline guide or Reference index.