Skip to content

Commit

Permalink
Reintroduce tree-sitter-languages. (#384)
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 authored Feb 15, 2024
2 parents 7b71573 + d3e03c7 commit 9f2f074
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 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
2 changes: 2 additions & 0 deletions papyri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ def build_parser():
work on all platofrms
"""
# this is used just for dev of tree-sitter
return
from tree_sitter import Language

pth = Path(__file__).parent / "rst.so"
Expand Down
8 changes: 8 additions & 0 deletions papyri/rich_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

from .myst_ast import MText

import logging

logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from .myst_ast import MAdmonition, MAdmonitionTitle

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

def visit_MImage(self, node):
logger.warning("TODO: implement images")
return RToken("Image TODO").partition()

def visit_MEmphasis(self, node):
return self.generic_visit(node.children)

Expand Down
4 changes: 2 additions & 2 deletions papyri/tests/expected/numpy:linspace.expected
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Return evenly spaced numbers over a specified interval.

## Extended Summary

Returns num evenly spaced samples, calculated over the interval [`start`, stop
].
Returns num evenly spaced samples, calculated over the interval [start, stop].


The endpoint of the interval can optionally be excluded.

Expand Down
1 change: 1 addition & 0 deletions papyri/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def generic_visit(self, node) -> List[Node]:
"MComment",
"MInlineCode",
"MInlineMath",
"MImage",
"MMath",
"MText",
"MThematicBreak",
Expand Down
19 changes: 5 additions & 14 deletions papyri/ts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import logging
import itertools
from pathlib import Path
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 @@ -43,19 +41,12 @@
# VisitSubstitutionDefinitionNotImplementedError,
)


from tree_sitter_languages import get_parser

parser = get_parser("rst")
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)

log = logging.getLogger("papyri")


Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pytest-cov
flit
matplotlib
pytest-trio
tree_sitter
coverage
jinja2==3.1.3
pipdeptree
Expand Down
1 change: 0 additions & 1 deletion tree-sitter-rst
Submodule tree-sitter-rst deleted from 3fc88d

0 comments on commit 9f2f074

Please sign in to comment.