diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 08464717..b20dd02e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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 diff --git a/papyri/__init__.py b/papyri/__init__.py index e9f2a062..d991d66d 100644 --- a/papyri/__init__.py +++ b/papyri/__init__.py @@ -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" diff --git a/papyri/rich_render.py b/papyri/rich_render.py index 5edb166b..c9478e6a 100644 --- a/papyri/rich_render.py +++ b/papyri/rich_render.py @@ -21,6 +21,10 @@ from .myst_ast import MText +import logging + +logger = logging.getLogger(__name__) + if TYPE_CHECKING: from .myst_ast import MAdmonition, MAdmonitionTitle @@ -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) diff --git a/papyri/tests/expected/numpy:linspace.expected b/papyri/tests/expected/numpy:linspace.expected index 7effcde5..718a9212 100644 --- a/papyri/tests/expected/numpy:linspace.expected +++ b/papyri/tests/expected/numpy:linspace.expected @@ -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. diff --git a/papyri/tree.py b/papyri/tree.py index 84444cfe..50ad126d 100644 --- a/papyri/tree.py +++ b/papyri/tree.py @@ -356,6 +356,7 @@ def generic_visit(self, node) -> List[Node]: "MComment", "MInlineCode", "MInlineMath", + "MImage", "MMath", "MText", "MThematicBreak", diff --git a/papyri/ts.py b/papyri/ts.py index 74283f2c..4b8296b9 100644 --- a/papyri/ts.py +++ b/papyri/ts.py @@ -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, @@ -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") diff --git a/requirements-dev.txt b/requirements-dev.txt index 850166bf..8263eef8 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,6 @@ pytest-cov flit matplotlib pytest-trio -tree_sitter coverage jinja2==3.1.3 pipdeptree diff --git a/tree-sitter-rst b/tree-sitter-rst deleted file mode 160000 index 3fc88d20..00000000 --- a/tree-sitter-rst +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3fc88d2097bc854ab6bf70c52b3c482849cf8e8f