Move tree-sitter and tree_sitter_languages to optional extras (#3398)

* Move tree-sitter and tree_sitter_languages to optional extras

* Update docs and GitHub action for moving syntax to extras

* Updating, remake lockfile

* Update snapshots from textual-dev change

* Improve warning when a language is set but tree-sitter not available

* Update CHANGELOG

* Add note on syntax extras

* Update lock
This commit is contained in:
Darren Burns
2023-10-09 10:57:13 +01:00
committed by GitHub
parent c88c031415
commit d2320f11fc
6 changed files with 1434 additions and 1292 deletions

View File

@@ -41,7 +41,7 @@ jobs:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
run: poetry install --extras syntax
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
# - name: Typecheck with mypy
# run: |

View File

@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Breaking change: tree-sitter and tree-sitter-languages dependencies moved to `syntax` extra https://github.com/Textualize/textual/pull/3398
- `Pilot.click`/`Pilot.hover` now raises `OutOfBounds` when clicking outside visible screen https://github.com/Textualize/textual/pull/3360
- `Pilot.click`/`Pilot.hover` now return a Boolean indicating whether the click/hover landed on the widget that matches the selector https://github.com/Textualize/textual/pull/3360
- Added a delay to when the `No Matches` message appears in the command palette, thus removing a flicker https://github.com/Textualize/textual/pull/3399

View File

@@ -12,6 +12,25 @@ Supports syntax highlighting for a selection of languages.
## Guide
### Syntax highlighting dependencies
To enable syntax highlighting, you'll need to install the `syntax` extra dependencies:
=== "pip"
```
pip install "textual[syntax]"
```
=== "poetry"
```
poetry add "textual[syntax]"
```
This will install `tree-sitter` and `tree-sitter-languages`.
These packages are distributed as binary wheels, so it may limit your applications ability to run in environments where these wheels are not supported.
### Loading text
In this example we load some initial text into the `TextArea`, and set the language to `"python"` to enable syntax highlighting.

2693
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -47,8 +47,11 @@ markdown-it-py = { extras = ["plugins", "linkify"], version = ">=2.1.0" }
#rich = {path="../rich", develop=true}
importlib-metadata = ">=4.11.3"
typing-extensions = "^4.4.0"
tree-sitter = "^0.20.1"
tree_sitter_languages = {version = ">=1.7.0", python = "^3.8"}
tree-sitter = {version = "^0.20.1", optional = true }
tree_sitter_languages = {version = ">=1.7.0", optional = true}
[tool.poetry.extras]
syntax = ["tree-sitter", "tree_sitter_languages"]
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.3"

View File

@@ -645,7 +645,9 @@ TextArea {
self._highlight_query = document.prepare_query(highlight_query)
elif language and not TREE_SITTER:
log.warning(
"tree-sitter not available in this environment. Parsing disabled."
"tree-sitter not available in this environment. Parsing disabled.\n"
"You may need to install the `syntax` extras alongside textual.\n"
"Try `pip install 'textual[syntax]'` or '`poetry add textual[syntax]'."
)
document = Document(text)
else: