Skip to content

Commit ecb6c51

Browse files
committed
update doc ordering, format, TOC
1 parent c8e7ef5 commit ecb6c51

File tree

1 file changed

+59
-32
lines changed

1 file changed

+59
-32
lines changed

CONTRIBUTING.md

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,25 @@ This guide is a work in progress, but aims to help a new contributor make a succ
55
If you have questions about contributing not answered here, always feel free to [open an issue](https://github.com/spyoungtech/ahk/issues)
66
or [discussion](https://github.com/spyoungtech/ahk/discussions) and I will help you the best that I am able.
77

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
927

1028
Generally, all contributions should be associated with an [open issue](https://github.com/spyoungtech/ahk/issues).
1129
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.
1432

1533

1634

17-
## Initial development setup
35+
# Initial development setup
36+
37+
Some prerequisite steps are needed to get ready for development on this project:
1838

1939
- Activated virtualenv with Python version 3.9 or later (`py -m venv venv` and `venv\Scripts\activate`)
2040
- Installed the dev requirements (`pip install -r requirements-dev.txt`) (this includes a binary redistribution of AutoHotkey)
2141
- Installed pre-commit hooks (`pre-commit install`)
2242

43+
That's it!
2344

24-
### Code formatting, linting, etc.
45+
## Code formatting, linting, etc.
2546

2647
All matters of code style, linting, etc. are all handled by pre-commit hooks. All the proper parameters for formatting
2748
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
3051
For these reasons and more, it is critical that you use the `pre-commit` hooks in order to make a successful contribution.
3152

3253

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
3477

3578
The test suite is managed by [`tox`](https://tox.wiki/en/latest/) (installed as part of `requirements-dev`)
3679

@@ -43,7 +86,7 @@ tox -e py
4386
Tox runs tests in an isolated environment.
4487

4588
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!):
4790

4891
```bash
4992
pytest tests
@@ -58,28 +101,12 @@ Notes:
58101
- Some tests are flaky -- the tox configuration adds appropriate reruns to pytest to compensate for this, but reruns are not always 100% effective
59102
- You can also simply rely on the GitHub Actions workflows for running tests
60103

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-
70104

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
81106

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.
83110

84111
This project is a wrapper around AutoHotkey. That is: it does not directly implement the underlying functionality, but
85112
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
103130
AHK function calls over HTTP (to a server running [ahk-server](https://github.com/spyoungtech/ahk-server)).
104131

105132

106-
### Hotkeys
133+
## Hotkeys
107134

108135
Hotkeys work slightly different from typical functions. Hotkeys are powered by a separate subprocess, which is started
109136
with the `start_hotkeys` method. This subprocess runs the hotkeys script (e.g. `ahk/templates/hotkeys-v2.ahk`). This works
110137
like a normal AutoHotkey script and when hotkeys are triggered, they write to `stdout`. A Python thread reads
111138
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.
113140

114141

115-
## Implementing a new method
142+
# Example: Implementing a new method
116143

117144
This section will guide you through the steps of implementing a basic new feature. This is very closely related to the
118145
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
138165
```
139166

140167

141-
### Writing the AutoHotkey code
168+
## Writing the AutoHotkey code
142169

143170
For example, in `ahk/templates/daemon-v2.ahk`, you may add a new function as so:
144171

@@ -161,7 +188,7 @@ Note that functions must always return a response (e.g. as provided by `FormatRe
161188
for more information about available message formats and implementing new message formats.
162189

163190

164-
### Writing the Python code
191+
## Writing the Python code
165192

166193

167194
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
190217
should be implemented in the message type instead.
191218

192219

193-
### Testing and code generation
220+
## Testing and code generation
194221

195222
In `tests/_async` create a new testcase in a new file like `tests/_async/test_math.py` with some basic test cases
196223
that cover a range of possible inputs and expected exceptional cases:
@@ -239,7 +266,7 @@ tox -e py
239266

240267
When all tests are passing, you are ready to open a pull request to get your contributions reviewed and merged.
241268

242-
## About your contributions :balance_scale:
269+
# About your contributions :balance_scale:
243270

244271
When you submit contributions to this project, you should understand that your contributions will be licensed under
245272
the license terms of the project (found in `LICENSE`).

0 commit comments

Comments
 (0)