Stack-Graphs Python bindings
Opinionated Python bindings for the tree-sitter-stack-graphs rust library.
(Note: the project curretly relies on fork)
It exposes a minimal, opinionated API to leverage the stack-graphs library for reference resolution in source code.
The rust bindings are built using PyO3 and maturin.
Note that this is a work in progress, and the API is subject to change. This project is not affiliated with GitHub.
Installation & Usage
pip install stack-graphs-python-bindings
Example
Given the following directory structure:
tests/js_sample
├── index.js
└── module.js
index.js
:
import { foo } from "./module"
const baz = foo
module.js
:
export const foo = "bar"
The following Python script:
import os
from stack_graphs_python import Indexer, Querier, Position, Language
db_path = os.path.abspath("./db.sqlite")
dir = os.path.abspath("./tests/js_sample")
indexer = Indexer(db_path, [Language.JavaScript])
indexer.index_all([dir])
querier = Querier(db_path)
source_reference = Position(path=dir + "/index.js", line=2, column=12)
results = querier.definitions(source_reference)
for r in results:
print(r)
Will output:
Position(path="[...]/tests/js_sample/index.js", line=0, column=9)
Position(path="[...]/tests/js_sample/module.js", line=0, column=13)
That translates to:
import { foo } from "./module"
export const foo = "bar"
Note: All the paths are absolute, and line and column numbers are 0-indexed (first line is 0, first column is 0).
Known stack-graphs / tree-sitter issues
Development
Ressources
https://pyo3.rs/v0.21.2/getting-started
Requirements
Setup
make setup
Testing
make test
Manual testing
make develop
. venv/bin/activate
Roadmap
Before releasing 0.1.0, which I expect to be a first stable API, the following needs to be done:
I'd also like to add the following features, after 0.1.0: