|
39 | 39 | Python REPL plugin for automatic time tracking and metrics generated from your |
40 | 40 | programming activity. |
41 | 41 |
|
42 | | - |
| 42 | + |
43 | 43 |
|
44 | | -Supported REPLs: |
| 44 | +## REPLs |
45 | 45 |
|
46 | | -- [x] [python](https://github.com/python/cpython): |
47 | | - - executes |
48 | | - [`str(sys.ps1)`](https://docs.python.org/3/library/sys.html#sys.ps1) after |
49 | | - every input. |
50 | | - - configure file: |
51 | | - [`$PYTHON_STARTUP`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP). |
| 46 | +### [python](https://github.com/python/cpython) |
| 47 | + |
| 48 | +[`$PYTHON_STARTUP`](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP): |
52 | 49 |
|
53 | 50 | ```python |
54 | | -from repl_python_wakatime.python import install_hook |
| 51 | +import sys |
| 52 | + |
| 53 | +from repl_python_wakatime.backends.wakatime import Wakatime |
| 54 | +from repl_python_wakatime.frontends.python import Python |
55 | 55 |
|
56 | | -install_hook() |
| 56 | +sys.ps1 = Python(Wakatime()) |
57 | 57 | ``` |
58 | 58 |
|
59 | | -- [x] [ptpython](https://github.com/prompt-toolkit/ptpython): |
60 | | - - executes `get_ptpython().get_output_prompt()` after every output. |
61 | | - - configure file: `.../ptpython/config.py`. `...` depends on OS. |
| 59 | +### [ptpython](https://github.com/prompt-toolkit/ptpython) |
| 60 | + |
| 61 | +`${XDG_CONFIG_HOME:-$HOME/.config}/ptpython/config.py`: |
62 | 62 |
|
63 | 63 | ```python |
64 | | -from ptpython.repl import PythonRepl |
65 | | -from repl_python_wakatime.ptpython import install_hook |
| 64 | +from repl_python_wakatime.backends.wakatime import Wakatime |
| 65 | +from repl_python_wakatime.frontends.ptpython import Ptpython |
66 | 66 |
|
67 | 67 |
|
68 | 68 | def configure(repl: PythonRepl) -> None: |
69 | | - install_hook(repl) |
| 69 | + repl.all_prompt_styles[repl.prompt_style] = Ptpython( |
| 70 | + Wakatime(), repl.all_prompt_styles[repl.prompt_style] |
| 71 | + ) |
70 | 72 | ``` |
71 | 73 |
|
72 | | -- [x] [ipython](https://github.com/ipython/ipython): |
73 | | - - executes |
74 | | - `c.TerminalInteractiveShell.prompts_class(shell).out_prompt_tokens()` after |
75 | | - every output. |
76 | | - - configure file: `~/.ipython/profile_default/ipython_config.py`. |
| 74 | +### [ipython](https://github.com/ipython/ipython)/[ptipython](https://github.com/prompt-toolkit/ptpython) |
| 75 | + |
| 76 | +`~/.ipython/profile_default/ipython_config.py`: |
77 | 77 |
|
78 | 78 | ```python |
79 | | -from repl_python_wakatime.iptpython import install_hook |
| 79 | +from IPython.terminal.prompts import ClassicPrompts |
| 80 | +from repl_python_wakatime.backends.wakatime import Wakatime |
| 81 | +from repl_python_wakatime.frontends.ipython import Ipython |
80 | 82 |
|
81 | | -install_hook(c) |
| 83 | +c.TerminalInteractiveShell.prompts_class = lambda *args, **kwargs: Ipython( |
| 84 | + Wakatime(), ClassicPrompts(*args, **kwargs) |
| 85 | +) |
82 | 86 | ``` |
83 | 87 |
|
84 | | -- [x] [gdb](https://sourceware.org/gdb/): |
| 88 | +### [gdb](https://sourceware.org/gdb/) |
85 | 89 |
|
86 | 90 | Your `gdb` must be compiled with |
87 | 91 | [python port](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Python.html). |
88 | 92 |
|
89 | 93 | `~/.config/gdb/gdbinit`: |
90 | 94 |
|
91 | 95 | ```gdb |
92 | | -source /the/path/of/repl_python_wakatime/gdb.py |
| 96 | +source ~/.config/gdb/gdbinit.py |
93 | 97 | ``` |
94 | 98 |
|
95 | | -See [GDB Hooks](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Hooks.html) |
96 | | -to know more. |
| 99 | +`~/.config/gdb/gdbinit.py`: |
| 100 | + |
| 101 | +```python |
| 102 | +from repl_python_wakatime.backends.wakatime import Wakatime |
| 103 | +from repl_python_wakatime.frontends.gdb import StopHook |
97 | 104 |
|
98 | | -Use environment variables `HOOK_NAMES=hook1:hook2` to defines which |
99 | | -[hook](#configure) will be used. |
| 105 | +StopHook(Wakatime()) |
| 106 | +``` |
100 | 107 |
|
101 | | -- [x] [ptipython](https://github.com/prompt-toolkit/ptpython): Same as |
102 | | - [ipython](https://github.com/ipython/ipython). |
103 | 108 | - [ ] [bpython](https://github.com/bpython/bpython) |
104 | 109 | - [ ] [xonsh](https://github.com/xonsh/xonsh) |
105 | | -- [ ] [mypython](https://github.com/asmeurer/mypython): Won't fix. |
106 | | - - configure file: non-exist. |
| 110 | +- [ ] [mypython](https://github.com/asmeurer/mypython): won't fix due to no any |
| 111 | + configuration. |
| 112 | +- [ ] vim/neovim with python support: see |
| 113 | + [vim-wakatime](https://github.com/wakatime/vim-wakatime) |
| 114 | + |
| 115 | +## Hooks |
107 | 116 |
|
108 | | -`install_hook()` must be after the customization of the prompt string and best |
109 | | -at the end of file. |
| 117 | +- [x] [wakatime](https://wakatime.com/) |
| 118 | +- [x] [codestats](https://codestats.net/) |
| 119 | +- [ ] [codetime](https://codetime.dev/) |
| 120 | +- [ ] [rescuetime](https://www.rescuetime.com/) |
110 | 121 |
|
111 | | -## Configure |
| 122 | +You can use many hooks at the same time: |
112 | 123 |
|
113 | 124 | ```python |
114 | | -from repl_python_wakatime.python import install_hook |
| 125 | +from repl_python_wakatime.backends.codestats import CodeStats |
| 126 | +from repl_python_wakatime.backends.wakatime import Wakatime |
| 127 | +from repl_python_wakatime.frontends.python import Python |
115 | 128 |
|
116 | | -install_hook(hook_function, args, kwargs) |
| 129 | +Python(Wakatime() | CodeStats()).install() |
117 | 130 | ``` |
118 | 131 |
|
119 | | -will execute `hook_function(*args, **kwargs)` after every output/input. Other |
120 | | -REPLs are similar. Currently, `hook_function` can be: |
| 132 | +## APIs |
| 133 | + |
| 134 | +You can use this project to statistic the time of using any programs. Such as, |
| 135 | +[translate-shell](https://github.com/Freed-Wu/translate-shell/) is a translating |
| 136 | +program: |
121 | 137 |
|
122 | | -- `repl_python_wakatime.hooks.wakatime.wakatime_hook()`: By default. |
123 | | -- `repl_python_wakatime.hooks.codestats.codestats_hook()`: for [codestats](https://codestats.net/) |
124 | | -- Create your hooks for other similar projects, such as: |
125 | | - - [codetime](https://codetime.dev/) |
126 | | - - [rescuetime](https://www.rescuetime.com/) |
127 | | - - ... |
| 138 | +```python |
| 139 | +from repl_python_wakatime.backends.wakatime import Wakatime |
| 140 | + |
| 141 | +# after each translating |
| 142 | +Wakatime(language="translate-shell", category="translating")() |
| 143 | +``` |
128 | 144 |
|
129 | 145 | ## Similar projects |
130 | 146 |
|
|
0 commit comments