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
+ * [ Under Unix (macOS, Linux, BSD, ...)] ( #under-unix--macos--linux--bsd--- )
8
+ * [ Under Windows] ( #under-windows )
9
+ - [ 3. Get the source.] ( #3-get-the-source )
10
+ - [ 4. Get in touch.] ( #4-get-in-touch )
11
+ - [ 5. Pick an issue.] ( #5-pick-an-issue )
12
+ - [ 6. Turn coffee and documentation into code and documentation!] ( #6-turn-coffee-and-documentation-into-code-and-documentation- )
13
+ - [ 7. Test, test, test!] ( #7-test--test--test- )
14
+ * [ Run the linters.] ( #run-the-linters )
15
+ * [ Run the unit tests.] ( #run-the-unit-tests )
16
+ * [ Run the integration tests.] ( #run-the-integration-tests )
17
+ - [ 8. Submit your patch.] ( #8-submit-your-patch )
18
+ * [ Changelog] ( #changelog )
19
+ + [ 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- )
20
+ + [ Debian changelog] ( #debian-changelog )
21
+ * [ Sign off] ( #sign-off )
22
+ - [ 9. Turn feedback into better code.] ( #9-turn-feedback-into-better-code )
23
+ - [ 10. Find a new issue.] ( #10-find-a-new-issue )
24
+ - [ Notes for maintainers on merging PRs etc] ( #notes-for-maintainers-on-merging-prs-etc )
25
+ - [ Conclusion] ( #conclusion )
26
+
27
+
28
+ # 1. Who can contribute to Synapse?
2
29
3
30
Everyone is welcome to contribute code to [ matrix.org
4
31
projects] ( https://github.com/matrix-org ) , provided that they are willing to
@@ -9,70 +36,163 @@ license the code under the same terms as the project's overall 'outbound'
9
36
license - in our case, this is almost always Apache Software License v2 (see
10
37
[ LICENSE] ( LICENSE ) ).
11
38
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
+ ## Under Unix (macOS, Linux, BSD, ...)
48
+
49
+ Once you have installed Python 3, please open a Terminal and run:
50
+
51
+ ``` sh
52
+ mkdir -p ~ /synapse
53
+ python3 -m venv ./env
54
+ source ./env/bin/activate
55
+ pip install -e " .[all,lint,mypy,test,black,tox]"
56
+ ```
57
+
58
+ This will install the developer dependencies for the project.
59
+
60
+ ## Under Windows
61
+
62
+ TBD
63
+
64
+
65
+ # 3. Get the source.
13
66
14
67
The preferred and easiest way to contribute changes is to fork the relevant
15
68
project on github, and then [ create a pull request] (
16
69
https://help.github.com/articles/using-pull-requests/ ) to ask us to pull your
17
70
changes into our repo.
18
71
19
- Some other points to follow:
72
+ Please base your changes on the ` develop ` branch.
73
+
74
+ ``` sh
75
+ git clone
[email protected] :matrix-org/synapse.git
76
+ ```
20
77
21
- * Please base your changes on the ` develop ` branch .
78
+ # 4. Get in touch .
22
79
23
- * Please follow the [ code style requirements ] ( #code-style ) .
80
+ Join our developer community on Matrix: #synapse-dev : matrix .org !
24
81
25
- * Please include a [ changelog entry] ( #changelog ) with each PR.
26
82
27
- * Please [ sign off ] ( #sign-off ) your contribution .
83
+ # 5. Pick an issue .
28
84
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.
85
+ Fix your favorite problem of find an issue on https://github.com/matrix-org/synapse/issues/ .
32
86
33
- * If you need to [ update your PR] ( #updating-your-pull-request ) , just add new
34
- commits to your branch rather than rebasing.
35
87
36
- ## Code style
88
+ # 6. Turn coffee and documentation into code and documentation!
37
89
38
90
Synapse's code style is documented [ here] ( docs/code_style.md ) . Please follow
39
91
it, including the conventions for the [ sample configuration
40
92
file] ( docs/code_style.md#configuration-file-format ) .
41
93
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:
94
+ There is a growing amount of documentation located in the [ docs] ( docs )
95
+ directory. This documentation is intended primarily for sysadmins running their
96
+ own Synapse instance, as well as developers interacting externally with
97
+ Synapse. [ docs/dev] ( docs/dev ) exists primarily to house documentation for
98
+ Synapse developers. [ docs/admin_api] ( docs/admin_api ) houses documentation
99
+ regarding Synapse's Admin API, which is used mostly by sysadmins and external
100
+ service developers.
101
+
102
+ If you add new files added to either of these folders, please use [ Github-Flavoured
103
+ Markdown] ( https://guides.github.com/features/mastering-markdown/ ) .
104
+
105
+ Some documentation also exists in [ Synapse's Github
106
+ Wiki] ( https://github.com/matrix-org/synapse/wiki ) , although this is primarily
107
+ contributed to by community authors.
46
108
47
- ```
48
- # Install the dependencies
49
- pip install -e ".[lint,mypy]"
50
109
51
- # Run the linter script
110
+ # 7. Test, test, test!
111
+ <a name =" test-test-test " ></a >
112
+
113
+ While you're developing and before submitting a patch, you'll
114
+ want to test your code.
115
+
116
+ ## Run the linters.
117
+
118
+ The linters look at your code and do two things:
119
+
120
+ - ensure that your code follows the coding style adopted by the project;
121
+ - catch a number of errors in your code.
122
+
123
+ They're very fast, don't hesitate!
124
+
125
+ ``` sh
126
+ source ./env/bin/activate
52
127
./scripts-dev/lint.sh
53
128
```
54
129
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 ** .
130
+ Note that the linters * will modify your files * to fix styling errors.
131
+ Make sure that you have saved all your files .
57
132
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:
61
133
62
- ```
134
+ If you wish to restrict the linters to only run on some files, you can instead run:
135
+
136
+ ``` sh
137
+ source ./env/bin/activate
63
138
./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
64
139
```
65
140
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.
69
141
70
- Before pushing new changes, ensure they don't produce linting errors. Commit any
71
- files that were corrected.
142
+ ## Run the unit tests.
143
+
144
+ The unit tests run parts of Synapse, including your changes, to see if anything
145
+ was broken. They are slower than the linters but will typically catch more errors.
146
+
147
+ ``` sh
148
+ source ./env/bin/activate
149
+ python -m twisted.trial tests
150
+ ```
151
+
152
+ If you wish to only run * some* unit tests, you may specify
153
+ another module instead of ` tests ` :
154
+
155
+ ``` sh
156
+ source ./env/bin/activate
157
+ python -m twisted.trial tests.rest.admin.test_room
158
+ ```
159
+
160
+ If your tests fail, you may wish to look at the logs:
161
+
162
+ ``` sh
163
+ less _trial_temp/test.log
164
+ ```
165
+
166
+ ## Run the integration tests.
167
+
168
+ The integration tests run the full Synapse, including your changes, to
169
+ see if anything was broken. They are slower than the unit tests but will
170
+ typically catch more errors.
171
+
172
+
173
+ The following will run the test suite using postgres. You will need [ Docker] ( https://docs.docker.com/get-docker/ ) installed.
174
+
175
+ ``` sh
176
+ ./test_postgresql.sh
177
+ ```
178
+
179
+ Or, if you prefer running the same tests without postgres or Docker, use this command.
180
+
181
+ ``` sh
182
+ tox -e py36
183
+ ```
184
+
185
+ # 8. Submit your patch.
186
+
187
+ Once you're happy with your patch, it's time to prepare a Pull Request.
188
+
189
+ To prepare a Pull Request, please:
72
190
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.
191
+ 1 . verify that [ all the tests pass] ( #test-test-test ) , including the coding style;
192
+ 2 . add a [ changelog entry] ( #changelog ) ;
193
+ 3 . [ sign off] ( #sign-off ) your contribution;
194
+ 4 . on Github, [ create the Pull Request] ( https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request ) ;
195
+ 5 . on Github, request review from ` matrix.org / Synapse Core ` .
76
196
77
197
## Changelog
78
198
@@ -156,24 +276,6 @@ directory, you will need both a regular newsfragment *and* an entry in the
156
276
debian changelog. (Though typically such changes should be submitted as two
157
277
separate pull requests.)
158
278
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
-
177
279
## Sign off
178
280
179
281
In order to have a concrete record that your contribution is intentional
@@ -240,47 +342,38 @@ Git allows you to add this signoff automatically when using the `-s`
240
342
flag to ` git commit ` , which uses the name and email set in your
241
343
` user.name ` and ` user.email ` git configs.
242
344
243
- ## Continuous integration and testing
244
345
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.
346
+ # 9. Turn feedback into better code.
347
+
348
+ Once the Pull Request is opened, you will see a few things:
349
+
350
+ 1 . our automated CI (Continuous Integration) pipeline will run (again) the linters, the unit tests, the integration tests and more;
351
+ 2 . one or more of the developers will take a look at your Pull Request and offer feedback.
250
352
251
- To run unit tests in a local development environment , you can use :
353
+ From this point , you should :
252
354
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.
355
+ 1 . Look at the results of the CI pipeline.
356
+ - If there is any error, fix the error.
357
+ 2 . If a developer has requested changes, make these changes.
358
+ 3 . Create a new patch with the changes.
359
+ - Please do NOT overwrite the history. New patches make the reviewer's life easier.
360
+ - Push this patch to your Pull Request.
361
+ 4 . Back to 1.
261
362
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.
363
+ If the CI pipeline detects errors, please fix them. If the developers suggest change, please fix them, too.
266
364
267
- ## Updating your pull request
365
+ Once both the CI and the developers are happy, the patch will be merged into Synapse and released shortly!
268
366
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.
367
+ # 10. Find a new issue.
273
368
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.
369
+ By now, you know the drill!
277
370
278
- ## Notes for maintainers on merging PRs etc
371
+ # Notes for maintainers on merging PRs etc
279
372
280
373
There are some notes for those with commit access to the project on how we
281
374
manage git [ here] ( docs/dev/git.md ) .
282
375
283
- ## Conclusion
376
+ # Conclusion
284
377
285
378
That's it! Matrix is a very open and collaborative project as you might expect
286
379
given our obsession with open communication. If we're going to successfully
0 commit comments