Skip to content

Commit

Permalink
feat: improve README and dev setup
Browse files Browse the repository at this point in the history
  • Loading branch information
nohehf committed May 16, 2024
1 parent f4c77e7 commit 4230e7f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: setup
setup:
pyenv virtualenvs | grep stack-graphs-python-bindings || pyenv virtualenv 3.11.9 stack-graphs-python-bindings
pyenv activate stack-graphs-python-bindings
python -m venv .venv
. .venv/bin/activate
pip install maturin

.PHONY: develop
Expand Down
48 changes: 42 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,64 @@ pip install stack-graphs-python-bindings # or poetry, ...
```

```python
from stack_graphs_python import index, query_definition, Position
import os
from stack_graphs_python import index, Querier, Position, Language

# ...
db_path = os.path.abspath("./db.sqlite")
dir = os.path.abspath("./tests/js_sample")

# Index the directory (creates stack-graphs database)
index([dir], db_path, language=Language.JavaScript)

# 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(f"{r.path}, l:{r.line}, c: {r.column}")
```

You can refer to the example in [test/test.py](https://github.com/nohehf/stack-graphs-python-bindings/blob/main/tests/test.py) for a concrete usage example.
Will result in:

```bash
[...]/stack-graphs-python-bindings/tests/js_sample/index.js, l:0, c: 9
[...]/stack-graphs-python-bindings/tests/js_sample/module.js, l:0, c: 13
```

That translates to:

```javascript
// index.js
import { foo } from "./module"

// module.js
export const foo = "bar"
```

## Development

### Ressources

https://pyo3.rs/v0.21.2/getting-started

### Requirements

- Rust
- Python 3.11+

### Setup

```bash
pipx install maturin # or pip, ...
# Setup venv and install maturin through pip
make setup
```

### Testing

```bash
maturin develop
python tests/test.py
make test
```

0 comments on commit 4230e7f

Please sign in to comment.