Skip to content

Commit

Permalink
Reintroduce tree-sitter-languages.
Browse files Browse the repository at this point in the history
It seem to be active again, with proper builds, and a newer version of
tree-sitter-rst. It allow to not have to do the build-parser step
  • Loading branch information
Carreau committed Feb 2, 2024
1 parent d665532 commit 864f8d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
flit install --symlink
git clone https://github.com/stsewd/tree-sitter-rst
cd tree-sitter-rst
git checkout 3fc88d2097bc854ab6bf70c52b3c482849cf8e8f
cd -
papyri build-parser
# this is not needed if tree-sitter-languages works
#git clone https://github.com/stsewd/tree-sitter-rst
#cd tree-sitter-rst
#git checkout 3fc88d2097bc854ab6bf70c52b3c482849cf8e8f
#cd -
#papyri build-parser
- name: dependency tree
run: |
pipdeptree
Expand Down
28 changes: 18 additions & 10 deletions papyri/ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from textwrap import dedent, indent
from typing import List, Any, Dict

from tree_sitter import Language, Parser

from .myst_ast import (
MText,
Expand Down Expand Up @@ -46,16 +45,25 @@
allowed_adorn = "=-`:.'\"~^_*+#<>"
pth = str(Path(__file__).parent / "rst.so")

# replace by tree-sitter-languages once it works See https://github.com/grantjenks/py-tree-sitter-languages/issues/15
try:
RST = Language(pth, "rst")
except OSError as e:
raise OSError(
"tree-sitter-rst not found, rst parsing will not work. Please run `papyri build-parser`"
) from e

parser = Parser()
parser.set_language(RST)
from tree_sitter_languages import get_language, get_parser

# language = get_language('python')
parser = get_parser("rst")
except ModuleNotFoundError:
# replace by tree-sitter-languages once it works See https://github.com/grantjenks/py-tree-sitter-languages/issues/15
try:
from tree_sitter import Language, Parser

RST = Language(pth, "rst")
except OSError as e:
raise OSError(
"tree-sitter-rst not found, rst parsing will not work. Please run `papyri build-parser`"
) from e

parser = Parser()
parser.set_language(RST)

log = logging.getLogger("papyri")


Expand Down

0 comments on commit 864f8d8

Please sign in to comment.