Skip to content

Commit 9f2f074

Browse files
authored
Reintroduce tree-sitter-languages. (#384)
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
2 parents 7b71573 + d3e03c7 commit 9f2f074

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

.github/workflows/python-package.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ jobs:
4747
python -m pip install --upgrade pip
4848
pip install -r requirements-dev.txt
4949
flit install --symlink
50-
git clone https://github.com/stsewd/tree-sitter-rst
51-
cd tree-sitter-rst
52-
git checkout 3fc88d2097bc854ab6bf70c52b3c482849cf8e8f
53-
cd -
54-
papyri build-parser
50+
# this is not needed if tree-sitter-languages works
51+
#git clone https://github.com/stsewd/tree-sitter-rst
52+
#cd tree-sitter-rst
53+
#git checkout 3fc88d2097bc854ab6bf70c52b3c482849cf8e8f
54+
#cd -
55+
#papyri build-parser
5556
- name: dependency tree
5657
run: |
5758
pipdeptree

papyri/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ def build_parser():
596596
work on all platofrms
597597
598598
"""
599+
# this is used just for dev of tree-sitter
600+
return
599601
from tree_sitter import Language
600602

601603
pth = Path(__file__).parent / "rst.so"

papyri/rich_render.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222
from .myst_ast import MText
2323

24+
import logging
25+
26+
logger = logging.getLogger(__name__)
27+
2428
if TYPE_CHECKING:
2529
from .myst_ast import MAdmonition, MAdmonitionTitle
2630

@@ -163,6 +167,10 @@ def visit_MText(self, node):
163167
assert res[-1].value != "\n"
164168
return res
165169

170+
def visit_MImage(self, node):
171+
logger.warning("TODO: implement images")
172+
return RToken("Image TODO").partition()
173+
166174
def visit_MEmphasis(self, node):
167175
return self.generic_visit(node.children)
168176

papyri/tests/expected/numpy:linspace.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Return evenly spaced numbers over a specified interval.
66

77
## Extended Summary
88

9-
Returns num evenly spaced samples, calculated over the interval [`start`, stop
10-
].
9+
Returns num evenly spaced samples, calculated over the interval [start, stop].
10+
1111

1212
The endpoint of the interval can optionally be excluded.
1313

papyri/tree.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def generic_visit(self, node) -> List[Node]:
356356
"MComment",
357357
"MInlineCode",
358358
"MInlineMath",
359+
"MImage",
359360
"MMath",
360361
"MText",
361362
"MThematicBreak",

papyri/ts.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import logging
22
import itertools
3-
from pathlib import Path
43
from textwrap import dedent, indent
54
from typing import List, Any, Dict
65

7-
from tree_sitter import Language, Parser
86

97
from .myst_ast import (
108
MText,
@@ -43,19 +41,12 @@
4341
# VisitSubstitutionDefinitionNotImplementedError,
4442
)
4543

44+
45+
from tree_sitter_languages import get_parser
46+
47+
parser = get_parser("rst")
4648
allowed_adorn = "=-`:.'\"~^_*+#<>"
47-
pth = str(Path(__file__).parent / "rst.so")
48-
49-
# replace by tree-sitter-languages once it works See https://github.com/grantjenks/py-tree-sitter-languages/issues/15
50-
try:
51-
RST = Language(pth, "rst")
52-
except OSError as e:
53-
raise OSError(
54-
"tree-sitter-rst not found, rst parsing will not work. Please run `papyri build-parser`"
55-
) from e
56-
57-
parser = Parser()
58-
parser.set_language(RST)
49+
5950
log = logging.getLogger("papyri")
6051

6152

requirements-dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pytest-cov
33
flit
44
matplotlib
55
pytest-trio
6-
tree_sitter
76
coverage
87
jinja2==3.1.3
98
pipdeptree

tree-sitter-rst

Submodule tree-sitter-rst deleted from 3fc88d2

0 commit comments

Comments
 (0)