Skip to content

Commit e21e668

Browse files
committed
feat: upgrade dependencies, thread safety
1 parent 58060a3 commit e21e668

File tree

9 files changed

+44
-94
lines changed

9 files changed

+44
-94
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install python
2525
uses: actions/setup-python@v2
2626
with:
27-
python-version: "3.11.9"
27+
python-version: "3.12"
2828

2929
- name: Run tests
3030
run: make setup test

.github/workflows/release.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- uses: actions/checkout@v4
4848
- uses: actions/setup-python@v5
4949
with:
50-
python-version: '3.11'
50+
python-version: '3.12'
5151
- name: Build wheels
5252
uses: PyO3/maturin-action@v1
5353
with:
@@ -74,7 +74,7 @@ jobs:
7474
- uses: actions/checkout@v4
7575
- uses: actions/setup-python@v5
7676
with:
77-
python-version: '3.11'
77+
python-version: '3.12'
7878
architecture: ${{ matrix.platform.target }}
7979
- name: Build wheels
8080
uses: PyO3/maturin-action@v1
@@ -101,7 +101,7 @@ jobs:
101101
- uses: actions/checkout@v4
102102
- uses: actions/setup-python@v5
103103
with:
104-
python-version: '3.11'
104+
python-version: '3.12'
105105
- name: Build wheels
106106
uses: PyO3/maturin-action@v1
107107
with:

Cargo.lock

Lines changed: 15 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "stack_graphs_python"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = "0.20.0"
12+
pyo3 = "0.24.2"
1313
stack-graphs = { version = "0.14.1", features = ["storage"] }
1414
tree-sitter-stack-graphs = { version = "0.10.0", features = ["cli"] }
1515
tree-sitter-stack-graphs-java = "0.5.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const foo = "bar"
9696
### Requirements
9797

9898
- Rust
99-
- Python 3.11+
99+
- Python 3.12+
100100

101101
### Setup
102102

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "stack-graphs-python-bindings"
7-
requires-python = ">=3.11"
7+
requires-python = ">=3.12"
88
classifiers = [
99
"Programming Language :: Rust",
1010
"Programming Language :: Python :: Implementation :: CPython",

src/classes.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt::Display;
2+
use std::sync::{Arc, Mutex};
23

34
use pyo3::prelude::*;
45

@@ -10,17 +11,17 @@ use crate::stack_graphs_wrapper::{
1011
get_status, get_status_all, index_all, new_loader, query_definition,
1112
};
1213

13-
#[pyclass]
14-
#[derive(Clone)]
14+
#[pyclass(eq, eq_int)]
15+
#[derive(Clone, PartialEq)]
1516
pub enum Language {
1617
Python,
1718
JavaScript,
1819
TypeScript,
1920
Java,
2021
}
2122

22-
#[pyclass]
23-
#[derive(Clone)]
23+
#[pyclass(eq, eq_int)]
24+
#[derive(Clone, PartialEq)]
2425
pub enum FileStatus {
2526
Missing,
2627
Indexed,
@@ -103,7 +104,7 @@ pub struct Position {
103104

104105
#[pyclass]
105106
pub struct Querier {
106-
db_reader: SQLiteReader,
107+
db_reader: Arc<Mutex<SQLiteReader>>,
107108
db_path: String,
108109
}
109110

@@ -113,13 +114,15 @@ impl Querier {
113114
pub fn new(db_path: String) -> Self {
114115
println!("Opening database: {}", db_path);
115116
Querier {
116-
db_reader: SQLiteReader::open(db_path.clone()).unwrap(),
117+
db_reader: Arc::new(Mutex::new(
118+
SQLiteReader::open(db_path.clone()).unwrap().into(),
119+
)),
117120
db_path: db_path,
118121
}
119122
}
120123

121124
pub fn definitions(&mut self, reference: Position) -> PyResult<Vec<Position>> {
122-
let result = query_definition(reference.into(), &mut self.db_reader)?;
125+
let result = query_definition(reference.into(), &mut *self.db_reader.lock().unwrap())?;
123126

124127
let positions: Vec<Position> = result
125128
.into_iter()
@@ -138,8 +141,8 @@ impl Querier {
138141

139142
#[pyclass]
140143
pub struct Indexer {
141-
db_writer: SQLiteWriter,
142-
db_reader: SQLiteReader,
144+
db_writer: Arc<Mutex<SQLiteWriter>>,
145+
db_reader: Arc<Mutex<SQLiteReader>>,
143146
db_path: String,
144147
loader: Loader,
145148
}
@@ -149,8 +152,8 @@ impl Indexer {
149152
#[new]
150153
pub fn new(db_path: String, languages: Vec<Language>) -> Self {
151154
Indexer {
152-
db_writer: SQLiteWriter::open(db_path.clone()).unwrap(),
153-
db_reader: SQLiteReader::open(db_path.clone()).unwrap(),
155+
db_writer: Arc::new(Mutex::new(SQLiteWriter::open(db_path.clone()).unwrap())),
156+
db_reader: Arc::new(Mutex::new(SQLiteReader::open(db_path.clone()).unwrap())),
154157
db_path: db_path,
155158
loader: new_loader(languages),
156159
}
@@ -160,7 +163,11 @@ impl Indexer {
160163
let paths: Vec<std::path::PathBuf> =
161164
paths.iter().map(|p| std::path::PathBuf::from(p)).collect();
162165

163-
match index_all(paths, &mut self.loader, &mut self.db_writer) {
166+
match index_all(
167+
paths,
168+
&mut self.loader,
169+
&mut *self.db_writer.lock().unwrap(),
170+
) {
164171
Ok(_) => Ok(()),
165172
Err(e) => Err(e.into()),
166173
}
@@ -170,14 +177,14 @@ impl Indexer {
170177
let paths: Vec<std::path::PathBuf> =
171178
paths.iter().map(|p| std::path::PathBuf::from(p)).collect();
172179

173-
get_status(paths, &mut self.db_reader)?
180+
get_status(paths, &mut *self.db_reader.lock().unwrap())?
174181
.into_iter()
175182
.map(|e| Ok(e.into()))
176183
.collect()
177184
}
178185

179186
pub fn status_all(&mut self) -> PyResult<Vec<FileEntry>> {
180-
get_status_all(&mut self.db_reader)?
187+
get_status_all(&mut *self.db_reader.lock().unwrap())?
181188
.into_iter()
182189
.map(|e| Ok(e.into()))
183190
.collect()

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn index(paths: Vec<String>, db_path: String, language: Language) -> PyResult<()
2424

2525
/// A Python module implemented in Rust.
2626
#[pymodule]
27-
fn stack_graphs_python(_py: Python, m: &PyModule) -> PyResult<()> {
27+
fn stack_graphs_python(m: &Bound<'_, PyModule>) -> PyResult<()> {
2828
m.add_function(wrap_pyfunction!(index, m)?)?;
2929
m.add_class::<Position>()?;
3030
m.add_class::<Language>()?;

tests/py_ok_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
"""
1919

2020

21-
@pytest.mark.skip(
22-
"Stack-graphs python module resolution is currently broken. See issue: https://github.com/github/stack-graphs/issues/430"
23-
)
2421
def test_py_ok():
2522
with string_to_virtual_files(code) as (dir, positions):
2623
db_path = os.path.join(dir, "db.sqlite")

0 commit comments

Comments
 (0)