feat(bindings)!: use capsules in python
This commit is contained in:
parent
3c7c17b00b
commit
f459c3d872
3 changed files with 15 additions and 5 deletions
|
|
@ -447,9 +447,19 @@ pub fn generate_grammar_files(
|
|||
let lang_path = path.join(format!("tree_sitter_{}", language_name.to_snake_case()));
|
||||
missing_path(&lang_path, create_dir)?;
|
||||
|
||||
missing_path(lang_path.join("binding.c"), |path| {
|
||||
generate_file(path, PY_BINDING_C_TEMPLATE, language_name)
|
||||
})?;
|
||||
missing_path_else(
|
||||
lang_path.join("binding.c"),
|
||||
|path| generate_file(path, PY_BINDING_C_TEMPLATE, language_name),
|
||||
|path| {
|
||||
let binding_c = fs::read_to_string(path)
|
||||
.with_context(|| "Failed to read bindings/python/binding.c")?;
|
||||
if !binding_c.contains("PyCapsule_New") {
|
||||
eprintln!("Replacing bindings/python/binding.c with new binding API");
|
||||
generate_file(path, PY_BINDING_C_TEMPLATE, language_name)?;
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
)?;
|
||||
|
||||
missing_path(lang_path.join("__init__.py"), |path| {
|
||||
generate_file(path, INIT_PY_TEMPLATE, language_name)
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@ from typing import Final
|
|||
# LOCALS_QUERY: Final[str]
|
||||
# TAGS_QUERY: Final[str]
|
||||
|
||||
def language() -> int: ...
|
||||
def language() -> object: ...
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ typedef struct TSLanguage TSLanguage;
|
|||
TSLanguage *tree_sitter_LOWER_PARSER_NAME(void);
|
||||
|
||||
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
|
||||
return PyLong_FromVoidPtr(tree_sitter_LOWER_PARSER_NAME());
|
||||
return PyCapsule_New(tree_sitter_LOWER_PARSER_NAME(), "tree_sitter.Language", NULL);
|
||||
}
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue