Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 9e19c6a

Browse files
authored
Reorganize CONTRIBUTING.md documentation. (#9281)
1 parent d2f0ec1 commit 9e19c6a

File tree

2 files changed

+190
-82
lines changed

2 files changed

+190
-82
lines changed

CONTRIBUTING.md

+189-82
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
# Contributing code to Synapse
1+
Welcome to Synapse
2+
3+
This document aims to get you started with contributing to this repo!
4+
5+
- [1. Who can contribute to Synapse?](#1-who-can-contribute-to-synapse)
6+
- [2. What do I need?](#2-what-do-i-need)
7+
- [3. Get the source.](#3-get-the-source)
8+
- [4. Install the dependencies](#4-install-the-dependencies)
9+
* [Under Unix (macOS, Linux, BSD, ...)](#under-unix-macos-linux-bsd-)
10+
* [Under Windows](#under-windows)
11+
- [5. Get in touch.](#5-get-in-touch)
12+
- [6. Pick an issue.](#6-pick-an-issue)
13+
- [7. Turn coffee and documentation into code and documentation!](#7-turn-coffee-and-documentation-into-code-and-documentation)
14+
- [8. Test, test, test!](#8-test-test-test)
15+
* [Run the linters.](#run-the-linters)
16+
* [Run the unit tests.](#run-the-unit-tests)
17+
* [Run the integration tests.](#run-the-integration-tests)
18+
- [9. Submit your patch.](#9-submit-your-patch)
19+
* [Changelog](#changelog)
20+
+ [How do I know what to call the changelog file before I create the PR?](#how-do-i-know-what-to-call-the-changelog-file-before-i-create-the-pr)
21+
+ [Debian changelog](#debian-changelog)
22+
* [Sign off](#sign-off)
23+
- [10. Turn feedback into better code.](#10-turn-feedback-into-better-code)
24+
- [11. Find a new issue.](#11-find-a-new-issue)
25+
- [Notes for maintainers on merging PRs etc](#notes-for-maintainers-on-merging-prs-etc)
26+
- [Conclusion](#conclusion)
27+
28+
# 1. Who can contribute to Synapse?
229

330
Everyone is welcome to contribute code to [matrix.org
431
projects](https://github.com/matrix-org), provided that they are willing to
@@ -9,70 +36,179 @@ license the code under the same terms as the project's overall 'outbound'
936
license - in our case, this is almost always Apache Software License v2 (see
1037
[LICENSE](LICENSE)).
1138

12-
## How to contribute
39+
# 2. What do I need?
40+
41+
The code of Synapse is written in Python 3. To do pretty much anything, you'll need [a recent version of Python 3](https://wiki.python.org/moin/BeginnersGuide/Download).
42+
43+
The source code of Synapse is hosted on GitHub. You will also need [a recent version of git](https://github.com/git-guides/install-git).
44+
45+
For some tests, you will need [a recent version of Docker](https://docs.docker.com/get-docker/).
46+
47+
48+
# 3. Get the source.
1349

1450
The preferred and easiest way to contribute changes is to fork the relevant
15-
project on github, and then [create a pull request](
51+
project on GitHub, and then [create a pull request](
1652
https://help.github.com/articles/using-pull-requests/) to ask us to pull your
1753
changes into our repo.
1854

19-
Some other points to follow:
55+
Please base your changes on the `develop` branch.
56+
57+
```sh
58+
git clone [email protected]:YOUR_GITHUB_USER_NAME/synapse.git
59+
git checkout develop
60+
```
61+
62+
If you need help getting started with git, this is beyond the scope of the document, but you
63+
can find many good git tutorials on the web.
64+
65+
# 4. Install the dependencies
2066

21-
* Please base your changes on the `develop` branch.
67+
## Under Unix (macOS, Linux, BSD, ...)
2268

23-
* Please follow the [code style requirements](#code-style).
69+
Once you have installed Python 3 and added the source, please open a terminal and
70+
setup a *virtualenv*, as follows:
71+
72+
```sh
73+
cd path/where/you/have/cloned/the/repository
74+
python3 -m venv ./env
75+
source ./env/bin/activate
76+
pip install -e ".[all,lint,mypy,test]"
77+
pip install tox
78+
```
79+
80+
This will install the developer dependencies for the project.
81+
82+
## Under Windows
83+
84+
TBD
2485

25-
* Please include a [changelog entry](#changelog) with each PR.
2686

27-
* Please [sign off](#sign-off) your contribution.
87+
# 5. Get in touch.
2888

29-
* Please keep an eye on the pull request for feedback from the [continuous
30-
integration system](#continuous-integration-and-testing) and try to fix any
31-
errors that come up.
89+
Join our developer community on Matrix: #synapse-dev:matrix.org !
3290

33-
* If you need to [update your PR](#updating-your-pull-request), just add new
34-
commits to your branch rather than rebasing.
3591

36-
## Code style
92+
# 6. Pick an issue.
93+
94+
Fix your favorite problem or perhaps find a [Good First Issue](https://github.com/matrix-org/synapse/issues?q=is%3Aopen+is%3Aissue+label%3A%22Good+First+Issue%22)
95+
to work on.
96+
97+
98+
# 7. Turn coffee and documentation into code and documentation!
3799

38100
Synapse's code style is documented [here](docs/code_style.md). Please follow
39101
it, including the conventions for the [sample configuration
40102
file](docs/code_style.md#configuration-file-format).
41103

42-
Many of the conventions are enforced by scripts which are run as part of the
43-
[continuous integration system](#continuous-integration-and-testing). To help
44-
check if you have followed the code style, you can run `scripts-dev/lint.sh`
45-
locally. You'll need python 3.6 or later, and to install a number of tools:
104+
There is a growing amount of documentation located in the [docs](docs)
105+
directory. This documentation is intended primarily for sysadmins running their
106+
own Synapse instance, as well as developers interacting externally with
107+
Synapse. [docs/dev](docs/dev) exists primarily to house documentation for
108+
Synapse developers. [docs/admin_api](docs/admin_api) houses documentation
109+
regarding Synapse's Admin API, which is used mostly by sysadmins and external
110+
service developers.
46111

47-
```
48-
# Install the dependencies
49-
pip install -e ".[lint,mypy]"
112+
If you add new files added to either of these folders, please use [GitHub-Flavoured
113+
Markdown](https://guides.github.com/features/mastering-markdown/).
114+
115+
Some documentation also exists in [Synapse's GitHub
116+
Wiki](https://github.com/matrix-org/synapse/wiki), although this is primarily
117+
contributed to by community authors.
118+
119+
120+
# 8. Test, test, test!
121+
<a name="test-test-test"></a>
122+
123+
While you're developing and before submitting a patch, you'll
124+
want to test your code.
125+
126+
## Run the linters.
127+
128+
The linters look at your code and do two things:
129+
130+
- ensure that your code follows the coding style adopted by the project;
131+
- catch a number of errors in your code.
132+
133+
They're pretty fast, don't hesitate!
50134

51-
# Run the linter script
135+
```sh
136+
source ./env/bin/activate
52137
./scripts-dev/lint.sh
53138
```
54139

55-
**Note that the script does not just test/check, but also reformats code, so you
56-
may wish to ensure any new code is committed first**.
140+
Note that this script *will modify your files* to fix styling errors.
141+
Make sure that you have saved all your files.
57142

58-
By default, this script checks all files and can take some time; if you alter
59-
only certain files, you might wish to specify paths as arguments to reduce the
60-
run-time:
143+
If you wish to restrict the linters to only the files changed since the last commit
144+
(much faster!), you can instead run:
61145

146+
```sh
147+
source ./env/bin/activate
148+
./scripts-dev/lint.sh -d
62149
```
150+
151+
Or if you know exactly which files you wish to lint, you can instead run:
152+
153+
```sh
154+
source ./env/bin/activate
63155
./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
64156
```
65157

66-
You can also provide the `-d` option, which will lint the files that have been
67-
changed since the last git commit. This will often be significantly faster than
68-
linting the whole codebase.
158+
## Run the unit tests.
159+
160+
The unit tests run parts of Synapse, including your changes, to see if anything
161+
was broken. They are slower than the linters but will typically catch more errors.
162+
163+
```sh
164+
source ./env/bin/activate
165+
trial tests
166+
```
167+
168+
If you wish to only run *some* unit tests, you may specify
169+
another module instead of `tests` - or a test class or a method:
170+
171+
```sh
172+
source ./env/bin/activate
173+
trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
174+
```
175+
176+
If your tests fail, you may wish to look at the logs:
177+
178+
```sh
179+
less _trial_temp/test.log
180+
```
181+
182+
## Run the integration tests.
183+
184+
The integration tests are a more comprehensive suite of tests. They
185+
run a full version of Synapse, including your changes, to check if
186+
anything was broken. They are slower than the unit tests but will
187+
typically catch more errors.
188+
189+
The following command will let you run the integration test with the most common
190+
configuration:
191+
192+
```sh
193+
$ docker run --rm -it -v /path/where/you/have/cloned/the/repository\:/src:ro -v /path/to/where/you/want/logs\:/logs matrixdotorg/sytest-synapse:py37
194+
```
195+
196+
This configuration should generally cover your needs. For more details about other configurations, see [documentation in the SyTest repo](https://github.com/matrix-org/sytest/blob/develop/docker/README.md).
197+
69198

70-
Before pushing new changes, ensure they don't produce linting errors. Commit any
71-
files that were corrected.
199+
# 9. Submit your patch.
200+
201+
Once you're happy with your patch, it's time to prepare a Pull Request.
202+
203+
To prepare a Pull Request, please:
204+
205+
1. verify that [all the tests pass](#test-test-test), including the coding style;
206+
2. [sign off](#sign-off) your contribution;
207+
3. `git push` your commit to your fork of Synapse;
208+
4. on GitHub, [create the Pull Request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request);
209+
5. add a [changelog entry](#changelog) and push it to your Pull Request;
210+
6. for most contributors, that's all - however, if you are a member of the organization `matrix-org`, on GitHub, please request a review from `matrix.org / Synapse Core`.
72211

73-
Please ensure your changes match the cosmetic style of the existing project,
74-
and **never** mix cosmetic and functional changes in the same commit, as it
75-
makes it horribly hard to review otherwise.
76212

77213
## Changelog
78214

@@ -156,24 +292,6 @@ directory, you will need both a regular newsfragment *and* an entry in the
156292
debian changelog. (Though typically such changes should be submitted as two
157293
separate pull requests.)
158294

159-
## Documentation
160-
161-
There is a growing amount of documentation located in the [docs](docs)
162-
directory. This documentation is intended primarily for sysadmins running their
163-
own Synapse instance, as well as developers interacting externally with
164-
Synapse. [docs/dev](docs/dev) exists primarily to house documentation for
165-
Synapse developers. [docs/admin_api](docs/admin_api) houses documentation
166-
regarding Synapse's Admin API, which is used mostly by sysadmins and external
167-
service developers.
168-
169-
New files added to both folders should be written in [Github-Flavoured
170-
Markdown](https://guides.github.com/features/mastering-markdown/), and attempts
171-
should be made to migrate existing documents to markdown where possible.
172-
173-
Some documentation also exists in [Synapse's Github
174-
Wiki](https://github.com/matrix-org/synapse/wiki), although this is primarily
175-
contributed to by community authors.
176-
177295
## Sign off
178296

179297
In order to have a concrete record that your contribution is intentional
@@ -240,47 +358,36 @@ Git allows you to add this signoff automatically when using the `-s`
240358
flag to `git commit`, which uses the name and email set in your
241359
`user.name` and `user.email` git configs.
242360

243-
## Continuous integration and testing
244361

245-
[Buildkite](https://buildkite.com/matrix-dot-org/synapse) will automatically
246-
run a series of checks and tests against any PR which is opened against the
247-
project; if your change breaks the build, this will be shown in GitHub, with
248-
links to the build results. If your build fails, please try to fix the errors
249-
and update your branch.
362+
# 10. Turn feedback into better code.
363+
364+
Once the Pull Request is opened, you will see a few things:
250365

251-
To run unit tests in a local development environment, you can use:
366+
1. our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;
367+
2. one or more of the developers will take a look at your Pull Request and offer feedback.
252368

253-
- ``tox -e py35`` (requires tox to be installed by ``pip install tox``)
254-
for SQLite-backed Synapse on Python 3.5.
255-
- ``tox -e py36`` for SQLite-backed Synapse on Python 3.6.
256-
- ``tox -e py36-postgres`` for PostgreSQL-backed Synapse on Python 3.6
257-
(requires a running local PostgreSQL with access to create databases).
258-
- ``./test_postgresql.sh`` for PostgreSQL-backed Synapse on Python 3.5
259-
(requires Docker). Entirely self-contained, recommended if you don't want to
260-
set up PostgreSQL yourself.
369+
From this point, you should:
261370

262-
Docker images are available for running the integration tests (SyTest) locally,
263-
see the [documentation in the SyTest repo](
264-
https://github.com/matrix-org/sytest/blob/develop/docker/README.md) for more
265-
information.
371+
1. Look at the results of the CI pipeline.
372+
- If there is any error, fix the error.
373+
2. If a developer has requested changes, make these changes and let us know if it is ready for a developer to review again.
374+
3. Create a new commit with the changes.
375+
- Please do NOT overwrite the history. New commits make the reviewer's life easier.
376+
- Push this commits to your Pull Request.
377+
4. Back to 1.
266378

267-
## Updating your pull request
379+
Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!
268380

269-
If you decide to make changes to your pull request - perhaps to address issues
270-
raised in a review, or to fix problems highlighted by [continuous
271-
integration](#continuous-integration-and-testing) - just add new commits to your
272-
branch, and push to GitHub. The pull request will automatically be updated.
381+
# 11. Find a new issue.
273382

274-
Please **avoid** rebasing your branch, especially once the PR has been
275-
reviewed: doing so makes it very difficult for a reviewer to see what has
276-
changed since a previous review.
383+
By now, you know the drill!
277384

278-
## Notes for maintainers on merging PRs etc
385+
# Notes for maintainers on merging PRs etc
279386

280387
There are some notes for those with commit access to the project on how we
281388
manage git [here](docs/dev/git.md).
282389

283-
## Conclusion
390+
# Conclusion
284391

285392
That's it! Matrix is a very open and collaborative project as you might expect
286393
given our obsession with open communication. If we're going to successfully

changelog.d/9281.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Reorganizing CHANGELOG.md.

0 commit comments

Comments
 (0)