No project description provided
Project description
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")
# Index the directory (creates stack-graphs database)
indexer = Indexer(db_path, [Language.JavaScript])
indexer.index_all([dir])
# Instantiate a querier
querier = Querier(db_path)
# Query a reference at a given position (0-indexed line and column):
# foo in: const baz = foo
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:
// index.js
import { foo } from "./module"
// ^ line 0, column 9
// module.js
export const foo = "bar"
// ^ line 0, column 13
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
- Typescript: tree-sitter-typescript fails when passing a generic type to a decorator: https://github.com/tree-sitter/tree-sitter-typescript/issues/283
Development
Ressources
https://pyo3.rs/v0.21.2/getting-started
Requirements
- Rust
- Python 3.11+
Setup
# Setup venv and install dev dependencies
make setup
Testing
make test
Manual testing
# build the package
make develop
# activate the venv
. venv/bin/activate
Roadmap
Before releasing 0.1.0, which I expect to be a first stable API, the following needs to be done:
- Add more testing, especially:
- Test all supported languages (Java,
Python,TypeScript,JavaScript) - Test failing cases, eg. files that cannot be indexed
- Test all supported languages (Java,
- Add options to the classes:
- Verbosity
- Force for the Indexer
- Fail on error for the Indexer, or continue indexing
- Handle the storage (database) in a dedicated class, and pass it to the Indexer and Querier -> this might not be necessary
- Add methods to query the indexing status (eg. which files have been indexed, which failed, etc.)
- Rely on the main branch of stack-graphs, and update the bindings accordingly
- Better error handling, return clear errors, test them and add them to the
.pyi
interface - Lint and format the rust code
- CI/CD for the rust code
- Lint and format the python code
- Propper changelog, starting in 0.1.0
I'd also like to add the following features, after 0.1.0:
- Expose the exact, lower-level API of stack-graphs, for more flexibility, in a separate module (eg.
stack_graphs_python.core
) - Benchmark performance
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for stack_graphs_python_bindings-0.0.13.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f92be194d6a6ebe57c90b479f2da59549578b0e5f3b2123611d63836c895eae |
|
MD5 | 92ace64c409c1f49b919711d0147763a |
|
BLAKE2b-256 | f5a80c848c5b936fc5106b8759dbd990069f8a49236f649d22b7e87766c44702 |
Hashes for stack_graphs_python_bindings-0.0.13-cp312-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4495d9b32c14d2ba9b393ec02368f9b79fa0c872504f4c66b06318cde14deda5 |
|
MD5 | 327b0e3761d1c913721b718129a2847b |
|
BLAKE2b-256 | bdc5c7fa6b9ab0c332d8c658655ea763d629ba3f44eaad2a74e464c313260b4b |
Hashes for stack_graphs_python_bindings-0.0.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a36ae795778a8b906940916818fa82534262e77bfa39bd9becfc26d9ceb20f3 |
|
MD5 | 87e0501ba029687e34992738a9666bb7 |
|
BLAKE2b-256 | d92e1ad6d5641bc71e21a12a07ed11d10e996f6e00cf4006a2ee1e64175f629b |
Hashes for stack_graphs_python_bindings-0.0.13-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cca333e517f64e57f8937be4282f0800ad73aee33400c7a7d46528ad59b3376b |
|
MD5 | f552b260753e7ec7c64df98fae3d6ab8 |
|
BLAKE2b-256 | c8f7797f14c09d9fba852a5983f32b89889fc92828f2fecc308f6fdc3873990d |
Hashes for stack_graphs_python_bindings-0.0.13-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa4aa89388edc51608cd44e470712102d2bf7f3947fa9488c0792c90be3bec0e |
|
MD5 | 1d7ab4b2c4b7cb0a942658be5b02c8bb |
|
BLAKE2b-256 | 27e3b78d42c0549d73c6019e375025142d7d83ec97f672376d4696e66632a32b |
Hashes for stack_graphs_python_bindings-0.0.13-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fb52e8ba07716e3222eb8fca6f13e1dff8afc36c53e9d5b8a814150439f748f |
|
MD5 | 39a839cea4ac97506ac55c7964fff73f |
|
BLAKE2b-256 | c9086a9e4aa477070567c2afa8642f7ab7bc65a9e859fbfa4b237bddb6d9aa4e |
Hashes for stack_graphs_python_bindings-0.0.13-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3966484c40147eb7b6f93dbcde21d0f161487c6b44fe599a0cbb81090194c15b |
|
MD5 | d5bf940f76d4ebd3b2e4f01810c1bef1 |
|
BLAKE2b-256 | 31ae8489d809a370d414ab6437e17368f05472859477fbed6ce788369863c481 |
Hashes for stack_graphs_python_bindings-0.0.13-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45e9e07cc672ca91007491a1a76848e236c65c0b8c361caeee755ce6f465374d |
|
MD5 | 8d3be709434575b9dedd6fde01511b4b |
|
BLAKE2b-256 | 605cd0ddc10e79e22c2089049c500ae91775b90afc3470e3cd9df8945dd036c1 |
Hashes for stack_graphs_python_bindings-0.0.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36992e318bf199bc17ed8fe32243612dc4b5078fed037594d9a5abf8643677c9 |
|
MD5 | ba416cd6b1db6b720253bdcbd5c12c90 |
|
BLAKE2b-256 | 5688301bc17de57c37ed65c66f982bc74f7b477230cd90d98bb118979d54665f |
Hashes for stack_graphs_python_bindings-0.0.13-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03000981256aab7cbf6426aef085c5457e4d3f43ee6e8f2ac789f09e2b182b4f |
|
MD5 | 1ddba83e658a03d80b55f57ca78736e0 |
|
BLAKE2b-256 | 49723c61cd8f758b7ce1dda69b60b109a8d1acede60bf1f32fd9151808e09b48 |
Hashes for stack_graphs_python_bindings-0.0.13-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e448c217e9470e09cb5ecd2c359382ed71f05140b78f2b76322d7685856b56b8 |
|
MD5 | 29a5705123025d3746808ce8bf8eb421 |
|
BLAKE2b-256 | 07cb4a0d35f7203383ef3cf478f67952efe8d2dfd0c09b383b2f19b3448475b3 |
Hashes for stack_graphs_python_bindings-0.0.13-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a570b27615498333ac4e20edce5eba81e555b8c7edb4ae95a91e5970f3f6d9c |
|
MD5 | b28745bb167f3e696d633b4e90b513e2 |
|
BLAKE2b-256 | 2774784b27d2880fa4eea3865109da67827c94aca16ffedf8a64d9ea21a5de6b |
Hashes for stack_graphs_python_bindings-0.0.13-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a756aee775e4fd26b57ad788eb6594e67132f7b70e3664a6887c26007ab284e |
|
MD5 | 734a1907ce63a7081ac01f0247d58c84 |
|
BLAKE2b-256 | bb57cd28da3e79f2a9171f98e94e58f99951f48e5b59e729dc4c1e8aeab61527 |