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

Commit f3f0ab1

Browse files
David Robertsonanoadragon453
andauthored
Move scripts directory inside synapse, exposing as setuptools entry_points (#12118)
* Two scripts are basically entry_points already * Move and rename scripts/* to synapse/_scripts/*.py * Delete sync_room_to_group.pl * Expose entry points in setup.py * Update linter script and config * Fixup scripts & docs mentioning scripts that moved Co-authored-by: Andrew Morgan <[email protected]>
1 parent 6adb89f commit f3f0ab1

27 files changed

+77
-135
lines changed

.ci/scripts/test_export_data_command.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ python -m synapse.app.homeserver --generate-keys -c .ci/sqlite-config.yaml
2121
echo "--- Prepare test database"
2222

2323
# Make sure the SQLite3 database is using the latest schema and has no pending background update.
24-
scripts/update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
24+
update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
2525

2626
# Run the export-data command on the sqlite test database
2727
python -m synapse.app.admin_cmd -c .ci/sqlite-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \
@@ -41,7 +41,7 @@ fi
4141

4242
# Port the SQLite databse to postgres so we can check command works against postgres
4343
echo "+++ Port SQLite3 databse to postgres"
44-
scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
44+
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
4545

4646
# Run the export-data command on postgres database
4747
python -m synapse.app.admin_cmd -c .ci/postgres-config.yaml export-data @anon-20191002_181700-832:localhost:8800 \

.ci/scripts/test_synapse_port_db.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ python -m synapse.app.homeserver --generate-keys -c .ci/sqlite-config.yaml
2525
echo "--- Prepare test database"
2626

2727
# Make sure the SQLite3 database is using the latest schema and has no pending background update.
28-
scripts/update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
28+
update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
2929

3030
# Create the PostgreSQL database.
3131
.ci/scripts/postgres_exec.py "CREATE DATABASE synapse"
3232

3333
echo "+++ Run synapse_port_db against test database"
34-
coverage run scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
34+
# TODO: this invocation of synapse_port_db (and others below) used to be prepended with `coverage run`,
35+
# but coverage seems unable to find the entrypoints installed by `pip install -e .`.
36+
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
3537

3638
# We should be able to run twice against the same database.
3739
echo "+++ Run synapse_port_db a second time"
38-
coverage run scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
40+
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
3941

4042
#####
4143

@@ -46,12 +48,12 @@ echo "--- Prepare empty SQLite database"
4648
# we do this by deleting the sqlite db, and then doing the same again.
4749
rm .ci/test_db.db
4850

49-
scripts/update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
51+
update_synapse_database --database-config .ci/sqlite-config.yaml --run-background-updates
5052

5153
# re-create the PostgreSQL database.
5254
.ci/scripts/postgres_exec.py \
5355
"DROP DATABASE synapse" \
5456
"CREATE DATABASE synapse"
5557

5658
echo "+++ Run synapse_port_db against empty database"
57-
coverage run scripts/synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml
59+
synapse_port_db --sqlite-database .ci/test_db.db --postgres-config .ci/postgres-config.yaml

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
# things to include
55
!docker
6-
!scripts
76
!synapse
87
!MANIFEST.in
98
!README.rst

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ recursive-include synapse/storage *.txt
1717
recursive-include synapse/storage *.md
1818

1919
recursive-include docs *
20-
recursive-include scripts *
2120
recursive-include scripts-dev *
2221
recursive-include synapse *.pyi
2322
recursive-include tests *.py

changelog.d/12118.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move scripts to Synapse package and expose as setuptools entry points.

docker/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ RUN \
4646
&& rm -rf /var/lib/apt/lists/*
4747

4848
# Copy just what we need to pip install
49-
COPY scripts /synapse/scripts/
5049
COPY MANIFEST.in README.rst setup.py synctl /synapse/
5150
COPY synapse/__init__.py /synapse/synapse/__init__.py
5251
COPY synapse/python_dependencies.py /synapse/synapse/python_dependencies.py

docs/development/database_schema.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ same as integers.
158158
There are three separate aspects to this:
159159

160160
* Any new boolean column must be added to the `BOOLEAN_COLUMNS` list in
161-
`scripts/synapse_port_db`. This tells the port script to cast the integer
162-
value from SQLite to a boolean before writing the value to the postgres
163-
database.
161+
`synapse/_scripts/synapse_port_db.py`. This tells the port script to cast
162+
the integer value from SQLite to a boolean before writing the value to the
163+
postgres database.
164164

165165
* Before SQLite 3.23, `TRUE` and `FALSE` were not recognised as constants by
166166
SQLite, and the `IS [NOT] TRUE`/`IS [NOT] FALSE` operators were not

docs/usage/administration/admin_api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ UPDATE users SET admin = 1 WHERE name = '@foo:bar.com';
1212
```
1313

1414
A new server admin user can also be created using the `register_new_matrix_user`
15-
command. This is a script that is located in the `scripts/` directory, or possibly
15+
command. This is a script that is distributed as part of synapse. It is possibly
1616
already on your `$PATH` depending on how Synapse was installed.
1717

1818
Finding your user's `access_token` is client-dependent, but will usually be shown in the client's settings.

mypy.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ files =
2323
# https://docs.python.org/3/library/re.html#re.X
2424
exclude = (?x)
2525
^(
26+
|synapse/_scripts/export_signing_key.py
27+
|synapse/_scripts/move_remote_media_to_new_store.py
28+
|synapse/_scripts/synapse_port_db.py
29+
|synapse/_scripts/update_synapse_database.py
2630
|synapse/storage/databases/__init__.py
2731
|synapse/storage/databases/main/__init__.py
2832
|synapse/storage/databases/main/cache.py

scripts-dev/generate_sample_config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ SAMPLE_CONFIG="docs/sample_config.yaml"
1010
SAMPLE_LOG_CONFIG="docs/sample_log_config.yaml"
1111

1212
check() {
13-
diff -u "$SAMPLE_LOG_CONFIG" <(./scripts/generate_log_config) >/dev/null || return 1
13+
diff -u "$SAMPLE_LOG_CONFIG" <(synapse/_scripts/generate_log_config.py) >/dev/null || return 1
1414
}
1515

1616
if [ "$1" == "--check" ]; then
17-
diff -u "$SAMPLE_CONFIG" <(./scripts/generate_config --header-file docs/.sample_config_header.yaml) >/dev/null || {
17+
diff -u "$SAMPLE_CONFIG" <(synapse/_scripts/generate_config.py --header-file docs/.sample_config_header.yaml) >/dev/null || {
1818
echo -e "\e[1m\e[31m$SAMPLE_CONFIG is not up-to-date. Regenerate it with \`scripts-dev/generate_sample_config\`.\e[0m" >&2
1919
exit 1
2020
}
21-
diff -u "$SAMPLE_LOG_CONFIG" <(./scripts/generate_log_config) >/dev/null || {
21+
diff -u "$SAMPLE_LOG_CONFIG" <(synapse/_scripts/generate_log_config.py) >/dev/null || {
2222
echo -e "\e[1m\e[31m$SAMPLE_LOG_CONFIG is not up-to-date. Regenerate it with \`scripts-dev/generate_sample_config\`.\e[0m" >&2
2323
exit 1
2424
}
2525
else
26-
./scripts/generate_config --header-file docs/.sample_config_header.yaml -o "$SAMPLE_CONFIG"
27-
./scripts/generate_log_config -o "$SAMPLE_LOG_CONFIG"
26+
synapse/_scripts/generate_config.py --header-file docs/.sample_config_header.yaml -o "$SAMPLE_CONFIG"
27+
synapse/_scripts/generate_log_config.py -o "$SAMPLE_LOG_CONFIG"
2828
fi

0 commit comments

Comments
 (0)