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

[WIP] Use Poetry to manage Synapse's dependencies #12337

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8dc02f9
DEBUG: always run twisted trunk; don't raise bugs
Mar 30, 2022
211becb
DEBUG: build all debs
Mar 30, 2022
7d57414
DEPS: Specify deps in pyproject.toml
Feb 18, 2022
53e804f
DEPS: Add missing dependency on importlib_metadata
Mar 29, 2022
c50da48
DEPS: Dirty duplication to make `all` work
Mar 4, 2022
87ecb33
BUILDS: `poetry` in Synapse docker image
Mar 8, 2022
d820ff2
BUILDS: `poetry` in deb virtualenvs
H-Shay Mar 30, 2022
e53e99e
CI: Use common linting workflow
Mar 3, 2022
3de49f4
CI: Fix the "main" trial test runs
Mar 4, 2022
03e5c93
CI: Fix the portdb job to run under poetry
Mar 9, 2022
6ab6f61
CI: Fix the export-data job to run under poetry
Mar 9, 2022
0d8a54a
CI: Fix the olddeps job to run under poetry
Mar 10, 2022
d3386af
CI: Fix Twisted trunk to run under poetry
squahtx Mar 14, 2022
b03ffaa
Changelog
Feb 21, 2022
5f8db3e
DOCS: recommend poetry where appropriate
Mar 30, 2022
680dbc8
Undebug various changes
Mar 30, 2022
a3fb2b8
Fix typos spotted by Sean
Mar 31, 2022
4c780ab
Batch of suggestsion from Brendan, part 1
Mar 31, 2022
8469bd8
Batch of suggestsion from Brendan, part 2
Mar 31, 2022
5dc21d9
Recommend synapse_homeserver entrypoint in README
Mar 31, 2022
e60c8f3
More clearly explain which extras are omitted from `all`.
Mar 31, 2022
6fd43c4
Explain where requirements.txt comes from.
Mar 31, 2022
45a23c0
olddeps: echo patch to confirm sed is sensible
Mar 31, 2022
e96fd31
Olddeps: leave a TODO for caret bounds
Mar 31, 2022
d2df831
Merge remote-tracking branch 'origin/develop' into dmr/pyproject-poetry
Mar 31, 2022
0af56b8
Olddeps: cat patched pyproject, instead of diffing
Apr 1, 2022
2ff7fbf
Docker: `pip install --user poetry` path fix
Apr 1, 2022
18f91a7
Only upgrade pip in dhvirtualenv
Apr 4, 2022
f0d72ac
Install and run poetry export in dpkg-buildpackage
callahad Apr 6, 2022
60a6671
Merge branch 'develop' into dmr/pyproject-poetry
callahad Apr 6, 2022
a653c20
Bump locked version of prometheus-client to 0.14.0
callahad Apr 7, 2022
232a270
Clarify a CI workflow step for Twisted trunk
callahad Apr 7, 2022
9225764
Inline CI steps for installing Twisted trunk
callahad Apr 7, 2022
99892e7
Merge branch 'develop' into dmr/pyproject-poetry
callahad Apr 7, 2022
872dfb8
Minor tweaks to comments in response to reviews
callahad Apr 7, 2022
379944c
Merge branch 'develop' into dmr/pyproject-poetry
callahad Apr 8, 2022
fb611f1
Merge branch 'develop' into dmr/pyproject-poetry
Apr 11, 2022
0cf4705
Merge remote-tracking branch 'origin/develop' into dmr/pyproject-poetry
Apr 12, 2022
988ff61
Include some dockerfile changes from develop
Apr 14, 2022
badd5cf
We don't need README to export
Apr 14, 2022
443b94f
Merge remote-tracking branch 'origin/develop' into dmr/pyproject-poetry
Apr 14, 2022
cbdbcb0
Merge remote-tracking branch 'origin/develop' into dmr/pyproject-poetry
Apr 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,39 +293,41 @@ directory of your choice::
git clone https://github.com/matrix-org/synapse.git
cd synapse

Synapse has a number of external dependencies, that are easiest
to install using pip and a virtualenv::
Synapse has a number of external dependencies. We maintain a fixed development
environment using [poetry](). First, install poetry. We recommend
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved

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

This will run a process of downloading and installing all the needed
dependencies into a virtual env. If any dependencies fail to install,
try installing the failing modules individually::
but see the `poetry installation docs <https://python-poetry.org/docs/#installation>`_
for more details. Then ask poetry to create a virtualenvironment from the project
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
and install Synapse's dependencies::

poetry install --extras "all test"

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

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

./demo/start.sh
poetry run ./demo/start.sh

(to stop, you can use `./demo/stop.sh`)
(to stop, you can use `poetry run ./demo/stop.sh`)

See the [demo documentation](https://matrix-org.github.io/synapse/develop/development/demo.html)
for more information.

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

# Create the homeserver.yaml config once
python -m synapse.app.homeserver \
poetry run python -m synapse.app.homeserver \
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
--server-name my.domain.name \
--config-path homeserver.yaml \
--generate-config \
--report-stats=[yes|no]

# Start the app
python -m synapse.app.homeserver --config-path homeserver.yaml
poetry run python -m synapse.app.homeserver --config-path homeserver.yaml
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved


Running the unit tests
Expand All @@ -334,7 +336,7 @@ Running the unit tests
After getting up and running, you may wish to run Synapse's unit tests to
check that everything is installed correctly::

trial tests
poetry run trial tests

This should end with a 'PASSED' result (note that exact numbers will
differ)::
Expand Down
9 changes: 2 additions & 7 deletions docs/code_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ The Synapse codebase uses a number of code formatting tools in order to
quickly and automatically check for formatting (and sometimes logical)
errors in code.

The necessary tools are detailed below.

First install them with:

```sh
pip install -e ".[lint,mypy]"
```
The necessary tools are detailed below. They should be installed by poetry as part
of Synapse's dev dependencies. See [the contributing guide](https://matrix-org.github.io/synapse/develop/development/contributing_guide.html#4-install-the-dependencies) for instructions.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved

- **black**

Expand Down
35 changes: 15 additions & 20 deletions docs/development/contributing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ can find many good git tutorials on the web.

# 4. Install the dependencies

Once you have installed Python 3 and added the source, please open a terminal and
setup a *virtualenv*, as follows:
Synapse uses the [poetry](https://python-poetry.org/) project to lock its dependencies
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
and development environment. Once you have installed Python 3 and added the
source, you should [install poetry](https://python-poetry.org/docs/#installation).
We recommend installing `poetry` using `pipx`; see their instructions for details.

Next, open a terminal and install dependencies as follows:

```sh
cd path/where/you/have/cloned/the/repository
python3 -m venv ./env
source ./env/bin/activate
pip install wheel
pip install -e ".[all,dev]"
pip install tox
poetry install --extras "all test"
```

This will install the developer dependencies for the project.
Expand Down Expand Up @@ -117,11 +117,10 @@ The linters look at your code and do two things:
- ensure that your code follows the coding style adopted by the project;
- catch a number of errors in your code.

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).
The linter takes no time at all to run as soon as you've [downloaded the dependencies](#4-install-the-dependencies).

```sh
source ./env/bin/activate
./scripts-dev/lint.sh
poetry run ./scripts-dev/lint.sh
```

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

```sh
source ./env/bin/activate
./scripts-dev/lint.sh -d
poetry run ./scripts-dev/lint.sh -d
```

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

```sh
source ./env/bin/activate
./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
poetry run ./scripts-dev/lint.sh path/to/file1.py path/to/file2.py path/to/folder
```

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

```sh
source ./env/bin/activate
trial tests
poetry run trial tests
```

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

```sh
source ./env/bin/activate
trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
poetry run trial tests.rest.admin.test_room tests.handlers.test_admin.ExfiltrateData.test_invite
```

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

```sh
SYNAPSE_TEST_LOG_LEVEL=DEBUG trial tests
SYNAPSE_TEST_LOG_LEVEL=DEBUG poetry run trial tests
```

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

```sh
SYNAPSE_TEST_PERSIST_SQLITE_DB=1 trial tests
SYNAPSE_TEST_PERSIST_SQLITE_DB=1 poetry run trial tests
```

The database file can then be inspected with:
Expand Down
33 changes: 18 additions & 15 deletions docs/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,35 @@ this document.
packages](setup/installation.md#prebuilt-packages), you will need to follow the
normal process for upgrading those packages.

- If Synapse was installed using pip then upgrade to the latest
version by running:

```bash
pip install --upgrade matrix-synapse
```

- If Synapse was installed from source, then:

1. Activate the virtualenv before upgrading. For example, if
Synapse is installed in a virtualenv in `~/synapse/env` then
1. Obtain the latest version of the source code. Git users can run
`git pull` to do this.

2. If you're running Synapse in a virtualenv, make sure to activate it before
upgrading. For example, if Synapse is installed in a virtualenv in `~/synapse/env` then
run:

```bash
source ~/synapse/env/bin/activate
pip install --upgrade .
```
Include any relevant extras with `-e`, e.g. `pip install --upgrade .[postgres,oidc]`.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved

2. If Synapse was installed using pip then upgrade to the latest
version by running:

```bash
pip install --upgrade matrix-synapse
```

If Synapse was installed using git then upgrade to the latest
version by running:

3. If you're using `poetry` to manage a Synapse installation, run:
```bash
git pull
pip install --upgrade .
poetry install
```
Include any relevant extras with `-E`, e.g. `poetry install -E "postgres oidc"`.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved

3. Restart Synapse:
4. Restart Synapse:

```bash
synctl restart
Expand Down