Skip to content

Commit c19ffe3

Browse files
Merge pull request #3595 from Textualize/pre-commit
Add more pre-commit hooks.
2 parents b3d6043 + d9594f5 commit c19ffe3

22 files changed

+27
-38
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@ repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
55
rev: v4.3.0
66
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-yaml
10-
args: [ '--unsafe' ]
7+
- id: check-ast # simply checks whether the files parse as valid python
8+
- id: check-builtin-literals # requires literal syntax when initializing empty or zero python builtin types
9+
- id: check-case-conflict # checks for files that would conflict in case-insensitive filesystems
10+
- id: check-merge-conflict # checks for files that contain merge conflict strings
11+
- id: check-json # checks json files for parseable syntax
12+
- id: check-toml # checks toml files for parseable syntax
13+
- id: check-yaml # checks yaml files for parseable syntax
14+
args: [ '--unsafe' ] # Instead of loading the files, simply parse them for syntax.
15+
- id: check-shebang-scripts-are-executable # ensures that (non-binary) files with a shebang are executable
16+
- id: check-vcs-permalinks # ensures that links to vcs websites are permalinks
17+
- id: end-of-file-fixer # ensures that a file is either empty, or ends with one newline
18+
- id: mixed-line-ending # replaces or checks mixed line ending
1119
- repo: https://github.com/pycqa/isort
1220
rev: 5.12.0
1321
hooks:
@@ -19,4 +27,9 @@ repos:
1927
rev: 23.1.0
2028
hooks:
2129
- id: black
30+
- repo: https://github.com/hadialqattan/pycln # removes unused imports
31+
rev: v2.3.0
32+
hooks:
33+
- id: pycln
34+
args: [--all]
2235
exclude: ^tests/snapshot_tests

docs/blog/snippets/2022-12-07-responsive-app-background-task/nonblocking01.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import time
32
from random import randint
43

54
from textual.app import App, ComposeResult

docs/examples/events/on_decorator01.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from textual import on
21
from textual.app import App, ComposeResult
32
from textual.widgets import Button
43

docs/examples/events/prevent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from textual.app import App, ComposeResult
2-
from textual.containers import Horizontal
32
from textual.widgets import Button, Input
43

54

docs/examples/guide/reactivity/validate01.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
3030
self.count += 1
3131
else:
3232
self.count -= 1
33-
self.query_one(RichLog).write(f"{self.count=}")
33+
self.query_one(RichLog).write(f"count = {self.count}")
3434

3535

3636
if __name__ == "__main__":

docs/examples/styles/padding_all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from textual.app import App
2-
from textual.containers import Container, Grid
2+
from textual.containers import Grid
33
from textual.widgets import Placeholder
44

55

docs/examples/widgets/content_switcher.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from rich.align import VerticalCenter
2-
31
from textual.app import App, ComposeResult
42
from textual.containers import Horizontal, VerticalScroll
53
from textual.widgets import Button, ContentSwitcher, DataTable, Markdown

src/textual/_parser.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ def parse(
165165

166166
test_parser = TestParser()
167167

168-
import time
169-
170168
for n in range(0, len(data), 5):
171169
for token in test_parser.feed(data[n : n + 5]):
172170
print(token)

src/textual/_types.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
from typing import TYPE_CHECKING, Any, Awaitable, Callable, List, Union
22

3-
from typing_extensions import (
4-
Literal,
5-
Protocol,
6-
SupportsIndex,
7-
get_args,
8-
runtime_checkable,
9-
)
3+
from typing_extensions import Protocol
104

115
if TYPE_CHECKING:
126
from rich.segment import Segment

src/textual/css/_style_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
if TYPE_CHECKING:
4949
from .._layout import Layout
50-
from .styles import Styles, StylesBase
50+
from .styles import StylesBase
5151

5252
from .types import AlignHorizontal, AlignVertical, DockEdge, EdgeType
5353

src/textual/document/_document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from functools import lru_cache
66
from typing import TYPE_CHECKING, NamedTuple, Tuple, overload
77

8+
from typing_extensions import Literal, get_args
9+
810
if TYPE_CHECKING:
911
from tree_sitter import Node
1012
from tree_sitter.binding import Query
1113

1214
from textual._cells import cell_len
13-
from textual._types import Literal, get_args
1415
from textual.geometry import Size
1516

1617
Newline = Literal["\r\n", "\n", "\r"]

src/textual/drivers/_input_reader_linux.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from threading import Event
55
from typing import Iterator
66

7-
from textual import log
8-
97

108
class InputReader:
119
"""Read input from stdin."""

src/textual/drivers/linux_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import rich.repr
1515
import rich.traceback
1616

17-
from .. import events, log
17+
from .. import events
1818
from .._xterm_parser import XTermParser
1919
from ..driver import Driver
2020
from ..geometry import Size

src/textual/message_pump.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from ._context import prevent_message_types_stack
2727
from ._on import OnNoWidget
2828
from ._time import time
29-
from ._types import CallbackType
3029
from .case import camel_to_snake
3130
from .css.match import match
3231
from .errors import DuplicateKeyHandlers

src/textual/widgets/_tabs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import asyncio
4-
from asyncio import create_task
54
from dataclasses import dataclass
65
from typing import ClassVar
76

src/textual/widgets/_text_area.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from rich.style import Style
1111
from rich.text import Text
12+
from typing_extensions import Literal, Protocol, runtime_checkable
1213

1314
from textual._text_area_theme import TextAreaTheme
1415
from textual._tree_sitter import TREE_SITTER
@@ -30,11 +31,9 @@
3031

3132
if TYPE_CHECKING:
3233
from tree_sitter import Language
33-
from tree_sitter.binding import Query
3434

3535
from textual import events, log
3636
from textual._cells import cell_len
37-
from textual._types import Literal, Protocol, runtime_checkable
3837
from textual.binding import Binding
3938
from textual.events import Message, MouseEvent
4039
from textual.geometry import Offset, Region, Size, Spacing, clamp

tests/css/test_programmatic_style_changes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from textual.app import App
44
from textual.containers import Grid
5-
from textual.screen import Screen
65
from textual.widgets import Label
76

87

tests/css/test_stylesheet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from contextlib import nullcontext as does_not_raise
2-
from typing import Any
32

43
import pytest
54

tests/input/test_input_validation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from textual import on
44
from textual.app import App, ComposeResult
5-
from textual.events import Blur
65
from textual.validation import Number, ValidationResult
76
from textual.widgets import Input
87

tests/test_reactive.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,6 @@ class Secondary(Primary):
298298
class Tertiary(Secondary):
299299
baz = reactive("baz")
300300

301-
from rich import print
302-
303301
primary = Primary()
304302
secondary = Secondary()
305303
tertiary = Tertiary()

tests/test_screens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
from textual import work
88
from textual.app import App, ComposeResult, ScreenStackError
9-
from textual.events import MouseMove, MouseScrollDown, MouseScrollUp
9+
from textual.events import MouseMove
1010
from textual.geometry import Offset
1111
from textual.screen import Screen
12-
from textual.widgets import Button, DataTable, Input, Label
12+
from textual.widgets import Button, Input, Label
1313
from textual.worker import NoActiveWorker
1414

1515
skip_py310 = pytest.mark.skipif(

tests/test_style_inheritance.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from rich.style import Style
2-
31
from textual.app import App, ComposeResult
42
from textual.widgets import Button, Static
53

0 commit comments

Comments
 (0)