File tree Expand file tree Collapse file tree 4 files changed +29
-10
lines changed
src/repl_python_wakatime/backends Expand file tree Collapse file tree 4 files changed +29
-10
lines changed Original file line number Diff line number Diff line change @@ -75,12 +75,12 @@ repos:
7575 additional_dependencies :
7676 - markdown-it-texmath
7777 - repo : https://github.com/astral-sh/ruff-pre-commit
78- rev : v0.13.0
78+ rev : v0.13.3
7979 hooks :
8080 - id : ruff-check
8181 - id : ruff-format
8282 - repo : https://github.com/kumaraditya303/mirrors-pyright
83- rev : v1.1.405
83+ rev : v1.1.406
8484 hooks :
8585 - id : pyright
8686
Original file line number Diff line number Diff line change @@ -123,11 +123,12 @@ StopHook(Wakatime())
123123You can use many hooks at the same time:
124124
125125``` python
126+ from repl_python_wakatime.backends.chainedhook import ChainedHook
126127from repl_python_wakatime.backends.codestats import CodeStats
127128from repl_python_wakatime.backends.wakatime import Wakatime
128129from repl_python_wakatime.frontends.python import Python
129130
130- sys.ps1 = Python(Wakatime() | CodeStats())
131+ sys.ps1 = Python(ChainedHook( hooks = ( Wakatime(), CodeStats()) ))
131132```
132133
133134## APIs
Original file line number Diff line number Diff line change 55import os
66from dataclasses import dataclass
77from pathlib import Path
8- from typing import Self
98
109
1110@dataclass
@@ -19,7 +18,6 @@ class Hook:
1918 frontend : str = "python"
2019 language : str = "python"
2120 category : str = "coding"
22- hooks : tuple [Self , ...] = ()
2321
2422 @property
2523 def plugin (self ) -> str :
@@ -57,10 +55,5 @@ def get_project(
5755 return parent .name
5856 return cwd .name
5957
60- def __or__ (self , hook : Self ) -> "Hook" :
61- return Hook (hooks = (self , hook ))
62-
6358 def __call__ (self ) -> None :
6459 r"""Run hook"""
65- for hook in self .hooks :
66- hook ()
Original file line number Diff line number Diff line change 1+ """Chained Hook
2+ ===============
3+
4+ """
5+
6+ from dataclasses import dataclass
7+ from typing import Any
8+
9+ from . import Hook
10+
11+
12+ @dataclass
13+ class ChainedHook (Hook ):
14+ hooks : tuple [Hook , ...] = ()
15+
16+ def __call__ (self ) -> None :
17+ r"""Run hook"""
18+ for hook in self .hooks :
19+ hook ()
20+
21+ def __setattr__ (self , k : Any , v : Any ) -> None :
22+ if k in {"frontend" , "language" , "category" }:
23+ for hook in self .hooks :
24+ setattr (hook , k , v )
25+ super ().__setattr__ (k , v )
You can’t perform that action at this time.
0 commit comments