@@ -5,7 +5,25 @@ This guide is a work in progress, but aims to help a new contributor make a succ
5
5
If you have questions about contributing not answered here, always feel free to [ open an issue] ( https://github.com/spyoungtech/ahk/issues )
6
6
or [ discussion] ( https://github.com/spyoungtech/ahk/discussions ) and I will help you the best that I am able.
7
7
8
- ## Before contributing
8
+ <!-- TOC -->
9
+ * [ Contribution Guide] ( #contribution-guide )
10
+ * [ Before contributing] ( #before-contributing )
11
+ * [ Initial development setup] ( #initial-development-setup )
12
+ * [ Code formatting, linting, etc.] ( #code-formatting-linting-etc )
13
+ * [ Unasync Code Generation] ( #unasync-code-generation )
14
+ * [ Pre-commit hooks] ( #pre-commit-hooks )
15
+ * [ Running tests] ( #running-tests )
16
+ * [ How this project works, briefly] ( #how-this-project-works-briefly )
17
+ * [ Hotkeys] ( #hotkeys )
18
+ * [ Example: Implementing a new method] ( #example-implementing-a-new-method )
19
+ * [ Writing the AutoHotkey code] ( #writing-the-autohotkey-code )
20
+ * [ Writing the Python code] ( #writing-the-python-code )
21
+ * [ Testing and code generation] ( #testing-and-code-generation )
22
+ * [ About your contributions :balance_scale : ] ( #about-your-contributions-balance_scale )
23
+ <!-- TOC -->
24
+
25
+
26
+ # Before contributing
9
27
10
28
Generally, all contributions should be associated with an [ open issue] ( https://github.com/spyoungtech/ahk/issues ) .
11
29
Contributors are strongly encouraged to comment on an existing issue or create a new issue before working on a PR,
@@ -14,14 +32,17 @@ improvements. When in doubt, create an issue.
14
32
15
33
16
34
17
- ## Initial development setup
35
+ # Initial development setup
36
+
37
+ Some prerequisite steps are needed to get ready for development on this project:
18
38
19
39
- Activated virtualenv with Python version 3.9 or later (` py -m venv venv ` and ` venv\Scripts\activate ` )
20
40
- Installed the dev requirements (` pip install -r requirements-dev.txt ` ) (this includes a binary redistribution of AutoHotkey)
21
41
- Installed pre-commit hooks (` pre-commit install ` )
22
42
43
+ That's it!
23
44
24
- ### Code formatting, linting, etc.
45
+ ## Code formatting, linting, etc.
25
46
26
47
All matters of code style, linting, etc. are all handled by pre-commit hooks. All the proper parameters for formatting
27
48
and correct order of operations are provided there. If you try to run ` black ` or similar formatters directly on the
@@ -30,7 +51,29 @@ project, it will likely produce a lot of unintended changes that will not be acc
30
51
For these reasons and more, it is critical that you use the ` pre-commit ` hooks in order to make a successful contribution.
31
52
32
53
33
- ## Running tests
54
+ # Unasync Code Generation
55
+
56
+ This project leverages a [ fork] ( https://github.com/spyoungtech/unasync/tree/unasync-remove ) of [ ` unasync ` ] ( https://github.com/python-trio/unasync )
57
+ to automatically generate synchronous code (output to the ` ahk/_sync ` directory) from async code in the ` ahk/_async ` directory.
58
+
59
+ To be clear: ** you will _ never_ need to write code directly in the ` ahk/_sync ` directory** . This is all auto-generated code.
60
+
61
+ Code generation runs as part of the pre-commit hooks.
62
+
63
+
64
+ # Pre-commit hooks
65
+
66
+ Pre-commit hooks are an essential part of development for this project. They will ensure your code is properly formatted
67
+ and linted. It is also essential for performing code generation, as discussed in the previous section.
68
+
69
+ To run the pre-commit hooks:
70
+
71
+ ``` bash
72
+ pre-commit run --all-files
73
+ ```
74
+
75
+
76
+ # Running tests
34
77
35
78
The test suite is managed by [ ` tox ` ] ( https://tox.wiki/en/latest/ ) (installed as part of ` requirements-dev ` )
36
79
@@ -43,7 +86,7 @@ tox -e py
43
86
Tox runs tests in an isolated environment.
44
87
45
88
Although ` tox ` is the recommended way of testing, with all dev requirements installed,
46
- you can run the tests directly with ` pytest ` :
89
+ you can run the tests directly with ` pytest ` (but be sure to run code generation first!) :
47
90
48
91
``` bash
49
92
pytest tests
@@ -58,28 +101,12 @@ Notes:
58
101
- Some tests are flaky -- the tox configuration adds appropriate reruns to pytest to compensate for this, but reruns are not always 100% effective
59
102
- You can also simply rely on the GitHub Actions workflows for running tests
60
103
61
- ## Unasync Code Generation
62
-
63
- This project leverages a [ fork] ( https://github.com/spyoungtech/unasync/tree/unasync-remove ) of [ ` unasync ` ] ( https://github.com/python-trio/unasync )
64
- to automatically generate synchronous code (output to the ` ahk/_sync ` directory) from async code in the ` ahk/_async ` directory.
65
-
66
- To be clear: ** you will _ never_ need to write code directly in the ` ahk/_sync ` directory** . This is all auto-generated code.
67
-
68
- Code generation runs as part of the pre-commit hooks.
69
-
70
104
71
- ## Pre-commit hooks
72
-
73
- Pre-commit hooks are an essential part of development for this project. They will ensure your code is properly formatted
74
- and linted. It is also essential for performing code generation, as discussed in the previous section.
75
-
76
- To run the pre-commit hooks:
77
-
78
- ``` bash
79
- pre-commit run --all-files
80
- ```
105
+ # How this project works, briefly
81
106
82
- ## How this project works, generally
107
+ Understanding how this project works under the hood is an important part to contributing. Here, we'll graze over the
108
+ most important implementation details, but contributors are encouraged to dive into the source code to learn more
109
+ and always feel free to open an issue or discussion to ask questions.
83
110
84
111
This project is a wrapper around AutoHotkey. That is: it does not directly implement the underlying functionality, but
85
112
instead relies directly on AutoHotkey itself to function; specifically, AutoHotkey is invoked as a subprocess.
@@ -103,16 +130,16 @@ alternate transports can be used, such as in the [ahk-client](https://github.com
103
130
AHK function calls over HTTP (to a server running [ ahk-server] ( https://github.com/spyoungtech/ahk-server ) ).
104
131
105
132
106
- ### Hotkeys
133
+ ## Hotkeys
107
134
108
135
Hotkeys work slightly different from typical functions. Hotkeys are powered by a separate subprocess, which is started
109
136
with the ` start_hotkeys ` method. This subprocess runs the hotkeys script (e.g. ` ahk/templates/hotkeys-v2.ahk ` ). This works
110
137
like a normal AutoHotkey script and when hotkeys are triggered, they write to ` stdout ` . A Python thread reads
111
138
from ` stdout ` and triggers the registered hotkey function. Unlike normal functions found in ` ahk/_async ` , the implementation of hotkeys
112
- (found in ` ahk/hotkeys.py ` ) is not implemented async-first -- it is all synchronous Python.
139
+ (found in ` ahk/hotkeys.py ` ) is not implemented async-first -- it is all synchronous/threaded Python.
113
140
114
141
115
- ## Implementing a new method
142
+ # Example: Implementing a new method
116
143
117
144
This section will guide you through the steps of implementing a basic new feature. This is very closely related to the
118
145
documented process of [ writing an extension] ( https://ahk.readthedocs.io/en/latest/extending.html ) , except that you are
@@ -138,7 +165,7 @@ git checkout -b gh-12345
138
165
```
139
166
140
167
141
- ### Writing the AutoHotkey code
168
+ ## Writing the AutoHotkey code
142
169
143
170
For example, in ` ahk/templates/daemon-v2.ahk ` , you may add a new function as so:
144
171
@@ -161,7 +188,7 @@ Note that functions must always return a response (e.g. as provided by `FormatRe
161
188
for more information about available message formats and implementing new message formats.
162
189
163
190
164
- ### Writing the Python code
191
+ ## Writing the Python code
165
192
166
193
167
194
For example, in ` ahk/_async/engine.py ` you might add the following method to the ` AsyncAHK ` class:
@@ -190,7 +217,7 @@ The most important part of this code is that the last part of the function retur
190
217
should be implemented in the message type instead.
191
218
192
219
193
- ### Testing and code generation
220
+ ## Testing and code generation
194
221
195
222
In ` tests/_async ` create a new testcase in a new file like ` tests/_async/test_math.py ` with some basic test cases
196
223
that cover a range of possible inputs and expected exceptional cases:
@@ -239,7 +266,7 @@ tox -e py
239
266
240
267
When all tests are passing, you are ready to open a pull request to get your contributions reviewed and merged.
241
268
242
- ## About your contributions :balance_scale :
269
+ # About your contributions :balance_scale :
243
270
244
271
When you submit contributions to this project, you should understand that your contributions will be licensed under
245
272
the license terms of the project (found in ` LICENSE ` ).
0 commit comments