Tolerate missing `tree-sitter-languages` binaries
enhancement
**Describe the bug**
Starting harlequin (`harlequin`) fails with an error:
```bash
OSError: /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/tree_sitter_languages/languages.so: cannot open shared object file: No such file or directory
```
**To Reproduce**
1. Create a new python environment from this spec:
```yml
# repro-env.yml
name: harlequin-issue
dependencies:
- python=3.11
- harlequin
- python-duckdb
```
```bash
micromamba env create -f repro-env.yml
```
2. Try to start harlequin
```bash
harlequin
```
<details>
<summary> Error trace </summary>
```
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual/widget.py:3386 │
│ in _on_compose │
│ │
│ 3383 │ │
│ 3384 │ async def _on_compose(self) -> None: │
│ 3385 │ │ try: │
│ ❱ 3386 │ │ │ widgets = [*self._nodes, *compose(self)] │
│ 3387 │ │ except TypeError as error: │
│ 3388 │ │ │ raise TypeError( │
│ 3389 │ │ │ │ f"{self!r} compose() method returned an invalid result; {error}" │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual_textarea/texta │
│ rea.py:950 in compose │
│ │
│ 947 │ │
│ 948 │ def compose(self) -> ComposeResult: │
│ 949 │ │ with TextContainer(): │
│ ❱ 950 │ │ │ yield TextInput(language=self._language) │
│ 951 │ │ │ yield CompletionList() │
│ 952 │ │ with FooterContainer(): │
│ 953 │ │ │ yield Label("", id="validation_label") │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual_textarea/texta │
│ rea.py:191 in __init__ │
│ │
│ 188 │ │ classes: str | None = None, │
│ 189 │ │ disabled: bool = False, │
│ 190 │ ) -> None: │
│ ❱ 191 │ │ super().__init__( │
│ 192 │ │ │ text, │
│ 193 │ │ │ language=language, │
│ 194 │ │ │ theme=theme, │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual/widgets/_text_ │
│ area.py:339 in __init__ │
│ │
│ 336 │ │ reactive is set as a string, the watcher will update this attribute to the │
│ 337 │ │ corresponding `TextAreaTheme` object.""" │
│ 338 │ │ │
│ ❱ 339 │ │ self.language = language │
│ 340 │ │ │
│ 341 │ │ self.theme = theme │
│ 342 │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual/widgets/_text_ │
│ area.py:479 in _watch_language │
│ │
│ 476 │ │ │ │ f"then switch to it by setting the `TextArea.language` attribute." │
│ 477 │ │ │ ) │
│ 478 │ │ │
│ ❱ 479 │ │ self._set_document( │
│ 480 │ │ │ self.document.text if self.document is not None else self._initial_text, │
│ 481 │ │ │ language, │
│ 482 │ │ ) │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual/widgets/_text_ │
│ area.py:637 in _set_document │
│ │
│ 634 │ │ │ │ highlight_query = self._get_builtin_highlight_query(language) │
│ 635 │ │ │ document: DocumentBase │
│ 636 │ │ │ try: │
│ ❱ 637 │ │ │ │ document = SyntaxAwareDocument(text, document_language) │
│ 638 │ │ │ except SyntaxAwareDocumentError: │
│ 639 │ │ │ │ document = Document(text) │
│ 640 │ │ │ │ log.warning( │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/textual/document/_synt │
│ ax_aware_document.py:61 in __init__ │
│ │
│ 58 │ │ if isinstance(language, str): │
│ 59 │ │ │ if language not in BUILTIN_LANGUAGES: │
│ 60 │ │ │ │ raise SyntaxAwareDocumentError(f"Invalid language {language!r}") │
│ ❱ 61 │ │ │ self.language = get_language(language) │
│ 62 │ │ │ self._parser = get_parser(language) │
│ 63 │ │ else: │
│ 64 │ │ │ self.language = language │
│ │
│ in tree_sitter_languages.core.get_language:14 │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/tree_sitter/__init__.p │
│ y:131 in __init__ │
│ │
│ 128 │ │ at the given path. │
│ 129 │ │ """ │
│ 130 │ │ self.name = name │
│ ❱ 131 │ │ self.lib = cdll.LoadLibrary(library_path) │
│ 132 │ │ language_function: Callable[[], c_void_p] = getattr(self.lib, "tree_sitter_%s" % │
│ 133 │ │ language_function.restype = c_void_p │
│ 134 │ │ self.language_id: c_void_p = language_function() │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/ctypes/__init__.py:454 in │
│ LoadLibrary │
│ │
│ 451 │ │ return getattr(self, name) │
│ 452 │ │
│ 453 │ def LoadLibrary(self, name): │
│ ❱ 454 │ │ return self._dlltype(name) │
│ 455 │ │
│ 456 │ __class_getitem__ = classmethod(_types.GenericAlias) │
│ 457 │
│ │
│ /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/ctypes/__init__.py:376 in __init__ │
│ │
│ 373 │ │ self._FuncPtr = _FuncPtr │
│ 374 │ │ │
│ 375 │ │ if handle is None: │
│ ❱ 376 │ │ │ self._handle = _dlopen(self._name, mode) │
│ 377 │ │ else: │
│ 378 │ │ │ self._handle = handle │
│ 379 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
OSError: /home/moritz/micromamba/envs/harlequin-issue/lib/python3.11/site-packages/tree_sitter_languages/languages.so: cannot open shared object file: No such file or directory
NOTE: 1 of 2 errors shown. Run with textual run --dev to see all errors.
```
</details>
~~I also tried the installation through pip, but the same error persists so I don't think this is a packaging issue on conda forge.~~
**Additional context**
```
harlequin, version 1.9.2
Installed Adapters:
- duckdb, version 1.9.2
- sqlite, version 1.9.2
```
Can you tell us more about your system?
- Shell: zsh
- Terminal: iTerm2 ssh'ed into a Ubuntu box
- OS of the shell: Ubuntu
- OS of the terminal (if different from the shell): MacOS Sonoma 14.2.1
8 条评论