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

Commit ecef741

Browse files
David RobertsonH-Shayclokep
authored
Recommend poetry in docs (#12475)
* Recommend poetry in docs - readme - contributor guide - upgrade notes - new dev cheat sheet for poetry Co-authored-by: Shay <[email protected]> Co-authored-by: Patrick Cloke <[email protected]>
1 parent d0c1f4c commit ecef741

File tree

5 files changed

+301
-50
lines changed

5 files changed

+301
-50
lines changed

README.rst

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,39 +293,42 @@ directory of your choice::
293293
git clone https://github.com/matrix-org/synapse.git
294294
cd synapse
295295

296-
Synapse has a number of external dependencies, that are easiest
297-
to install using pip and a virtualenv::
296+
Synapse has a number of external dependencies. We maintain a fixed development
297+
environment using [poetry](https://python-poetry.org/). First, install poetry. We recommend
298298

299-
python3 -m venv ./env
300-
source ./env/bin/activate
301-
pip install -e ".[all,dev]"
299+
pip install --user pipx
300+
pipx install poetry
302301

303-
This will run a process of downloading and installing all the needed
304-
dependencies into a virtual env. If any dependencies fail to install,
305-
try installing the failing modules individually::
302+
as described `here <https://python-poetry.org/docs/#installing-with-pipx>`_.
303+
(See `poetry's installation docs <https://python-poetry.org/docs/#installation>`
304+
for other installation methods.) Then ask poetry to create a virtual environment
305+
from the project and install Synapse's dependencies::
306+
307+
poetry install --extras "all test"
306308

307-
pip install -e "module-name"
309+
This will run a process of downloading and installing all the needed
310+
dependencies into a virtual env.
308311

309312
We recommend using the demo which starts 3 federated instances running on ports `8080` - `8082`
310313

311-
./demo/start.sh
314+
poetry run ./demo/start.sh
312315

313-
(to stop, you can use `./demo/stop.sh`)
316+
(to stop, you can use `poetry run ./demo/stop.sh`)
314317

315318
See the `demo documentation <https://matrix-org.github.io/synapse/develop/development/demo.html>`_
316319
for more information.
317320

318321
If you just want to start a single instance of the app and run it directly::
319322

320323
# Create the homeserver.yaml config once
321-
python -m synapse.app.homeserver \
324+
poetry run synapse_homeserver \
322325
--server-name my.domain.name \
323326
--config-path homeserver.yaml \
324327
--generate-config \
325328
--report-stats=[yes|no]
326329

327330
# Start the app
328-
python -m synapse.app.homeserver --config-path homeserver.yaml
331+
poetry run synapse_homeserver --config-path homeserver.yaml
329332

330333

331334
Running the unit tests
@@ -334,7 +337,7 @@ Running the unit tests
334337
After getting up and running, you may wish to run Synapse's unit tests to
335338
check that everything is installed correctly::
336339

337-
trial tests
340+
poetry run trial tests
338341

339342
This should end with a 'PASSED' result (note that exact numbers will
340343
differ)::

changelog.d/12475.doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Strongly recommend `poetry` for development.

docs/development/contributing_guide.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,28 @@ can find many good git tutorials on the web.
4848

4949
# 4. Install the dependencies
5050

51-
Once you have installed Python 3 and added the source, please open a terminal and
52-
setup a *virtualenv*, as follows:
51+
Synapse uses the [poetry](https://python-poetry.org/) project to manage its dependencies
52+
and development environment. Once you have installed Python 3 and added the
53+
source, you should install `poetry`.
54+
Of their installation methods, we recommend
55+
[installing `poetry` using `pipx`](https://python-poetry.org/docs/#installing-with-pipx),
56+
57+
```shell
58+
pip install --user pipx
59+
pipx install poetry
60+
```
61+
62+
but see poetry's [installation instructions](https://python-poetry.org/docs/#installation)
63+
for other installation methods.
64+
65+
Next, open a terminal and install dependencies as follows:
5366

5467
```sh
5568
cd path/where/you/have/cloned/the/repository
56-
python3 -m venv ./env
57-
source ./env/bin/activate
58-
pip install wheel
59-
pip install -e ".[all,dev]"
60-
pip install tox
69+
poetry install --extras all
6170
```
6271

63-
This will install the developer dependencies for the project.
72+
This will install the runtime and developer dependencies for the project.
6473

6574

6675
# 5. Get in touch.
@@ -117,11 +126,10 @@ The linters look at your code and do two things:
117126
- ensure that your code follows the coding style adopted by the project;
118127
- catch a number of errors in your code.
119128

120-
The linter takes no time at all to run as soon as you've [downloaded the dependencies into your python virtual environment](#4-install-the-dependencies).
129+
The linter takes no time at all to run as soon as you've [downloaded the dependencies](#4-install-the-dependencies).
121130

122131
```sh
123-
source ./env/bin/activate
124-
./scripts-dev/lint.sh
132+
poetry run ./scripts-dev/lint.sh
125133
```
126134

127135
Note that this script *will modify your files* to fix styling errors.
@@ -131,15 +139,13 @@ If you wish to restrict the linters to only the files changed since the last com
131139
(much faster!), you can instead run:
132140

133141
```sh
134-
source ./env/bin/activate
135-
./scripts-dev/lint.sh -d
142+
poetry run ./scripts-dev/lint.sh -d
136143
```
137144

138145
Or if you know exactly which files you wish to lint, you can instead run:
139146

140147
```sh
141-
source ./env/bin/activate
142-
./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
148+
poetry run ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
143149
```
144150

145151
## Run the unit tests (Twisted trial).
@@ -148,16 +154,14 @@ The unit tests run parts of Synapse, including your changes, to see if anything
148154
was broken. They are slower than the linters but will typically catch more errors.
149155

150156
```sh
151-
source ./env/bin/activate
152-
trial tests
157+
poetry run trial tests
153158
```
154159

155160
If you wish to only run *some* unit tests, you may specify
156161
another module instead of `tests` - or a test class or a method:
157162

158163
```sh
159-
source ./env/bin/activate
160-
trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
164+
poetry run trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
161165
```
162166

163167
If your tests fail, you may wish to look at the logs (the default log level is `ERROR`):
@@ -169,7 +173,7 @@ less _trial_temp/test.log
169173
To increase the log level for the tests, set `SYNAPSE_TEST_LOG_LEVEL`:
170174

171175
```sh
172-
SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
176+
SYNAPSE_TEST_LOG_LEVEL=DEBUG poetry run trial tests
173177
```
174178

175179
By default, tests will use an in-memory SQLite database for test data. For additional
@@ -180,7 +184,7 @@ database state to be stored in a file named `test.db` under the trial process'
180184
working directory. Typically, this ends up being `_trial_temp/test.db`. For example:
181185

182186
```sh
183-
SYNAPSE_TEST_PERSIST_SQLITE_DB=1 trial tests
187+
SYNAPSE_TEST_PERSIST_SQLITE_DB=1 poetry run trial tests
184188
```
185189

186190
The database file can then be inspected with:

0 commit comments

Comments
 (0)