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

Commit

Permalink
Use version string helper from matrix-common (#11979)
Browse files Browse the repository at this point in the history
* Require latest matrix-common
* Use the common function
  • Loading branch information
David Robertson authored Feb 14, 2022
1 parent 55113dd commit 4ae956c
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 112 deletions.
1 change: 1 addition & 0 deletions changelog.d/11979.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fetch Synapse's version using a helper from `matrix-common`.
7 changes: 4 additions & 3 deletions scripts/synapse_port_db
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import traceback
from typing import Dict, Iterable, Optional, Set

import yaml
from matrix_common.versionstring import get_distribution_version_string

from twisted.internet import defer, reactor

import synapse
from synapse.config.database import DatabaseConnectionConfig
from synapse.config.homeserver import HomeServerConfig
from synapse.logging.context import (
Expand Down Expand Up @@ -67,7 +67,6 @@ from synapse.storage.databases.state.bg_updates import StateBackgroundUpdateStor
from synapse.storage.engines import create_engine
from synapse.storage.prepare_database import prepare_database
from synapse.util import Clock
from synapse.util.versionstring import get_version_string

logger = logging.getLogger("synapse_port_db")

Expand Down Expand Up @@ -222,7 +221,9 @@ class MockHomeserver:
self.clock = Clock(reactor)
self.config = config
self.hostname = config.server.server_name
self.version_string = "Synapse/" + get_version_string(synapse)
self.version_string = "Synapse/" + get_distribution_version_string(
"matrix-synapse"
)

def get_clock(self):
return self.clock
Expand Down
7 changes: 4 additions & 3 deletions scripts/update_synapse_database
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import logging
import sys

import yaml
from matrix_common.versionstring import get_distribution_version_string

from twisted.internet import defer, reactor

import synapse
from synapse.config.homeserver import HomeServerConfig
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.server import HomeServer
from synapse.storage import DataStore
from synapse.util.versionstring import get_version_string

logger = logging.getLogger("update_database")

Expand All @@ -39,7 +38,9 @@ class MockHomeserver(HomeServer):
config.server.server_name, reactor=reactor, config=config, **kwargs
)

self.version_string = "Synapse/" + get_version_string(synapse)
self.version_string = "Synapse/" + get_distribution_version_string(
"matrix-synapse"
)


def run_background_updates(hs):
Expand Down
5 changes: 3 additions & 2 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
)

from cryptography.utils import CryptographyDeprecationWarning
from matrix_common.versionstring import get_distribution_version_string

import twisted
from twisted.internet import defer, error, reactor as _reactor
Expand Down Expand Up @@ -67,7 +68,6 @@
from synapse.util.daemonize import daemonize_process
from synapse.util.gai_resolver import GAIResolver
from synapse.util.rlimit import change_resource_limit
from synapse.util.versionstring import get_version_string

if TYPE_CHECKING:
from synapse.server import HomeServer
Expand Down Expand Up @@ -487,7 +487,8 @@ def setup_sentry(hs: "HomeServer") -> None:
import sentry_sdk

sentry_sdk.init(
dsn=hs.config.metrics.sentry_dsn, release=get_version_string(synapse)
dsn=hs.config.metrics.sentry_dsn,
release=get_distribution_version_string("matrix-synapse"),
)

# We set some default tags that give some context to this instance
Expand Down
5 changes: 3 additions & 2 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import tempfile
from typing import List, Optional

from matrix_common.versionstring import get_distribution_version_string

from twisted.internet import defer, task

import synapse
Expand All @@ -44,7 +46,6 @@
from synapse.storage.databases.main.room import RoomWorkerStore
from synapse.types import StateMap
from synapse.util.logcontext import LoggingContext
from synapse.util.versionstring import get_version_string

logger = logging.getLogger("synapse.app.admin_cmd")

Expand Down Expand Up @@ -223,7 +224,7 @@ def start(config_options: List[str]) -> None:
ss = AdminCmdServer(
config.server.server_name,
config=config,
version_string="Synapse/" + get_version_string(synapse),
version_string="Synapse/" + get_distribution_version_string("matrix-synapse"),
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 3 additions & 2 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import sys
from typing import Dict, List, Optional, Tuple

from matrix_common.versionstring import get_distribution_version_string

from twisted.internet import address
from twisted.web.resource import Resource

Expand Down Expand Up @@ -122,7 +124,6 @@
from synapse.storage.databases.main.user_directory import UserDirectoryStore
from synapse.types import JsonDict
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.versionstring import get_version_string

logger = logging.getLogger("synapse.app.generic_worker")

Expand Down Expand Up @@ -482,7 +483,7 @@ def start(config_options: List[str]) -> None:
hs = GenericWorkerServer(
config.server.server_name,
config=config,
version_string="Synapse/" + get_version_string(synapse),
version_string="Synapse/" + get_distribution_version_string("matrix-synapse"),
)

setup_logging(hs, config, use_worker_options=True)
Expand Down
5 changes: 3 additions & 2 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import sys
from typing import Dict, Iterable, Iterator, List

from matrix_common.versionstring import get_distribution_version_string

from twisted.internet.tcp import Port
from twisted.web.resource import EncodingResourceWrapper, Resource
from twisted.web.server import GzipEncoderFactory
Expand Down Expand Up @@ -70,7 +72,6 @@
from synapse.storage import DataStore
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.module_loader import load_module
from synapse.util.versionstring import get_version_string

logger = logging.getLogger("synapse.app.homeserver")

Expand Down Expand Up @@ -350,7 +351,7 @@ def setup(config_options: List[str]) -> SynapseHomeServer:
hs = SynapseHomeServer(
config.server.server_name,
config=config,
version_string="Synapse/" + get_version_string(synapse),
version_string="Synapse/" + get_distribution_version_string("matrix-synapse"),
)

synapse.config.logger.setup_logging(hs, config, use_worker_options=False)
Expand Down
9 changes: 6 additions & 3 deletions synapse/config/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import TYPE_CHECKING, Any, Dict, Optional

import yaml
from matrix_common.versionstring import get_distribution_version_string
from zope.interface import implementer

from twisted.logger import (
Expand All @@ -32,11 +33,9 @@
globalLogBeginner,
)

import synapse
from synapse.logging._structured import setup_structured_logging
from synapse.logging.context import LoggingContextFilter
from synapse.logging.filter import MetadataFilter
from synapse.util.versionstring import get_version_string

from ._base import Config, ConfigError

Expand Down Expand Up @@ -347,6 +346,10 @@ def setup_logging(

# Log immediately so we can grep backwards.
logging.warning("***** STARTING SERVER *****")
logging.warning("Server %s version %s", sys.argv[0], get_version_string(synapse))
logging.warning(
"Server %s version %s",
sys.argv[0],
get_distribution_version_string("matrix-synapse"),
)
logging.info("Server hostname: %s", config.server.server_name)
logging.info("Instance name: %s", hs.get_instance_name())
10 changes: 7 additions & 3 deletions synapse/federation/transport/server/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
Union,
)

from matrix_common.versionstring import get_distribution_version_string
from typing_extensions import Literal

import synapse
from synapse.api.errors import Codes, SynapseError
from synapse.api.room_versions import RoomVersions
from synapse.api.urls import FEDERATION_UNSTABLE_PREFIX, FEDERATION_V2_PREFIX
Expand All @@ -42,7 +42,6 @@
)
from synapse.types import JsonDict
from synapse.util.ratelimitutils import FederationRateLimiter
from synapse.util.versionstring import get_version_string

if TYPE_CHECKING:
from synapse.server import HomeServer
Expand Down Expand Up @@ -616,7 +615,12 @@ async def on_GET(
) -> Tuple[int, JsonDict]:
return (
200,
{"server": {"name": "Synapse", "version": get_version_string(synapse)}},
{
"server": {
"name": "Synapse",
"version": get_distribution_version_string("matrix-synapse"),
}
},
)


Expand Down
7 changes: 4 additions & 3 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
)

import attr
from matrix_common.versionstring import get_distribution_version_string
from prometheus_client import CollectorRegistry, Counter, Gauge, Histogram, Metric
from prometheus_client.core import (
REGISTRY,
Expand All @@ -43,14 +44,14 @@

from twisted.python.threadpool import ThreadPool

import synapse.metrics._reactor_metrics
# This module is imported for its side effects; flake8 needn't warn that it's unused.
import synapse.metrics._reactor_metrics # noqa: F401
from synapse.metrics._exposition import (
MetricsResource,
generate_latest,
start_http_server,
)
from synapse.metrics._gc import MIN_TIME_BETWEEN_GCS, install_gc_manager
from synapse.util.versionstring import get_version_string

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -417,7 +418,7 @@ def collect(self) -> Iterable[Metric]:
)
build_info.labels(
" ".join([platform.python_implementation(), platform.python_version()]),
get_version_string(synapse),
get_distribution_version_string("matrix-synapse"),
" ".join([platform.system(), platform.release()]),
).set(1)

Expand Down
2 changes: 1 addition & 1 deletion synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
# with the latest security patches.
"cryptography>=3.4.7",
"ijson>=3.1",
"matrix-common==1.0.0",
"matrix-common~=1.1.0",
]

CONDITIONAL_REQUIREMENTS = {
Expand Down
6 changes: 3 additions & 3 deletions synapse/rest/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from http import HTTPStatus
from typing import TYPE_CHECKING, Optional, Tuple

import synapse
from matrix_common.versionstring import get_distribution_version_string

from synapse.api.errors import Codes, NotFoundError, SynapseError
from synapse.http.server import HttpServer, JsonResource
from synapse.http.servlet import RestServlet, parse_json_object_from_request
Expand Down Expand Up @@ -88,7 +89,6 @@
WhoisRestServlet,
)
from synapse.types import JsonDict, RoomStreamToken
from synapse.util.versionstring import get_version_string

if TYPE_CHECKING:
from synapse.server import HomeServer
Expand All @@ -101,7 +101,7 @@ class VersionServlet(RestServlet):

def __init__(self, hs: "HomeServer"):
self.res = {
"server_version": get_version_string(synapse),
"server_version": get_distribution_version_string("matrix-synapse"),
"python_version": platform.python_version(),
}

Expand Down
85 changes: 0 additions & 85 deletions synapse/util/versionstring.py

This file was deleted.

0 comments on commit 4ae956c

Please sign in to comment.