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

Fix Synapse git info missing in version strings #12973

Merged
merged 6 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.d/12973.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug introduced in Synapse 1.58 where Synapse would not report full version information when installed from a git checkout. This is a best-effort affair and not guaranteed to be stable.
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ typing-extensions = ">=3.10.0.1"
cryptography = ">=3.4.7"
# ijson 3.1.4 fixes a bug with "." in property names
ijson = ">=3.1.4"
matrix-common = "~=1.1.0"
matrix-common = "~=1.2.1"
# We need packaging.requirements.Requirement, added in 16.1.
packaging = ">=16.1"
# At the time of writing, we only use functions from the version `importlib.metadata`
Expand Down
6 changes: 3 additions & 3 deletions synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import os
import sys

from matrix_common.versionstring import get_distribution_version_string

# Check that we're not running on an unsupported Python version.
if sys.version_info < (3, 7):
print("Synapse requires Python 3.7 or above.")
Expand Down Expand Up @@ -70,7 +68,9 @@
except ImportError:
pass

__version__ = get_distribution_version_string("matrix-synapse")
import synapse.util

__version__ = synapse.util.SYNAPSE_VERSION

if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
# We import here so that we don't have to install a bunch of deps when
Expand Down
7 changes: 2 additions & 5 deletions synapse/_scripts/synapse_port_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
)

import yaml
from matrix_common.versionstring import get_distribution_version_string
from typing_extensions import TypedDict

from twisted.internet import defer, reactor as reactor_
Expand Down Expand Up @@ -84,7 +83,7 @@
from synapse.storage.engines import create_engine
from synapse.storage.prepare_database import prepare_database
from synapse.types import ISynapseReactor
from synapse.util import Clock
from synapse.util import SYNAPSE_VERSION, Clock

# Cast safety: Twisted does some naughty magic which replaces the
# twisted.internet.reactor module with a Reactor instance at runtime.
Expand Down Expand Up @@ -258,9 +257,7 @@ def __init__(self, config: HomeServerConfig):
self.clock = Clock(reactor)
self.config = config
self.hostname = config.server.server_name
self.version_string = "Synapse/" + get_distribution_version_string(
"matrix-synapse"
)
self.version_string = SYNAPSE_VERSION

def get_clock(self) -> Clock:
return self.clock
Expand Down
5 changes: 2 additions & 3 deletions synapse/_scripts/update_synapse_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from typing import cast

import yaml
from matrix_common.versionstring import get_distribution_version_string

from twisted.internet import defer, reactor as reactor_

Expand All @@ -28,6 +27,7 @@
from synapse.server import HomeServer
from synapse.storage import DataStore
from synapse.types import ISynapseReactor
from synapse.util import SYNAPSE_VERSION

# Cast safety: Twisted does some naughty magic which replaces the
# twisted.internet.reactor module with a Reactor instance at runtime.
Expand All @@ -43,8 +43,7 @@ def __init__(self, config: HomeServerConfig):
hostname=config.server.server_name,
config=config,
reactor=reactor,
version_string="Synapse/"
+ get_distribution_version_string("matrix-synapse"),
version_string=f"Synapse/{SYNAPSE_VERSION}",
)


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

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

import twisted
Expand Down Expand Up @@ -68,6 +67,7 @@
from synapse.metrics.background_process_metrics import wrap_as_background_process
from synapse.metrics.jemalloc import setup_jemalloc_stats
from synapse.types import ISynapseReactor
from synapse.util import SYNAPSE_VERSION
from synapse.util.caches.lrucache import setup_expire_lru_cache_entries
from synapse.util.daemonize import daemonize_process
from synapse.util.gai_resolver import GAIResolver
Expand Down Expand Up @@ -540,7 +540,7 @@ def setup_sentry(hs: "HomeServer") -> None:

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

# We set some default tags that give some context to this instance
Expand Down
5 changes: 2 additions & 3 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
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 @@ -43,6 +41,7 @@
from synapse.server import HomeServer
from synapse.storage.databases.main.room import RoomWorkerStore
from synapse.types import StateMap
from synapse.util import SYNAPSE_VERSION
from synapse.util.logcontext import LoggingContext

logger = logging.getLogger("synapse.app.admin_cmd")
Expand Down Expand Up @@ -220,7 +219,7 @@ def start(config_options: List[str]) -> None:
ss = AdminCmdServer(
config.server.server_name,
config=config,
version_string="Synapse/" + get_distribution_version_string("matrix-synapse"),
version_string=f"Synapse/{SYNAPSE_VERSION}",
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 2 additions & 3 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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 @@ -121,6 +119,7 @@
from synapse.storage.databases.main.ui_auth import UIAuthWorkerStore
from synapse.storage.databases.main.user_directory import UserDirectoryStore
from synapse.types import JsonDict
from synapse.util import SYNAPSE_VERSION
from synapse.util.httpresourcetree import create_resource_tree

logger = logging.getLogger("synapse.app.generic_worker")
Expand Down Expand Up @@ -447,7 +446,7 @@ def start(config_options: List[str]) -> None:
hs = GenericWorkerServer(
config.server.server_name,
config=config,
version_string="Synapse/" + get_distribution_version_string("matrix-synapse"),
version_string=f"Synapse/{SYNAPSE_VERSION}",
)

setup_logging(hs, config, use_worker_options=True)
Expand Down
6 changes: 2 additions & 4 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import sys
from typing import Dict, Iterable, 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 @@ -69,7 +67,7 @@
from synapse.rest.well_known import well_known_resource
from synapse.server import HomeServer
from synapse.storage import DataStore
from synapse.util.check_dependencies import check_requirements
from synapse.util.check_dependencies import VERSION, check_requirements
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.module_loader import load_module

Expand Down Expand Up @@ -371,7 +369,7 @@ def setup(config_options: List[str]) -> SynapseHomeServer:
hs = SynapseHomeServer(
config.server.server_name,
config=config,
version_string="Synapse/" + get_distribution_version_string("matrix-synapse"),
version_string=f"Synapse/{VERSION}",
)

synapse.config.logger.setup_logging(hs, config, use_worker_options=False)
Expand Down
4 changes: 2 additions & 2 deletions synapse/config/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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 @@ -37,6 +36,7 @@
from synapse.logging.filter import MetadataFilter
from synapse.types import JsonDict

from ..util import SYNAPSE_VERSION
from ._base import Config, ConfigError

if TYPE_CHECKING:
Expand Down Expand Up @@ -349,7 +349,7 @@ def setup_logging(
logging.warning(
"Server %s version %s",
sys.argv[0],
get_distribution_version_string("matrix-synapse"),
SYNAPSE_VERSION,
)
logging.info("Server hostname: %s", config.server.server_name)
logging.info("Instance name: %s", hs.get_instance_name())
4 changes: 2 additions & 2 deletions synapse/federation/transport/server/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
Union,
)

from matrix_common.versionstring import get_distribution_version_string
from typing_extensions import Literal

from synapse.api.constants import EduTypes
Expand All @@ -42,6 +41,7 @@
parse_strings_from_args,
)
from synapse.types import JsonDict
from synapse.util import SYNAPSE_VERSION
from synapse.util.ratelimitutils import FederationRateLimiter

if TYPE_CHECKING:
Expand Down Expand Up @@ -622,7 +622,7 @@ async def on_GET(
{
"server": {
"name": "Synapse",
"version": get_distribution_version_string("matrix-synapse"),
"version": SYNAPSE_VERSION,
}
},
)
Expand Down
4 changes: 2 additions & 2 deletions synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
)

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 @@ -54,6 +53,7 @@
)
from synapse.metrics._gc import MIN_TIME_BETWEEN_GCS, install_gc_manager
from synapse.metrics._types import Collector
from synapse.util import SYNAPSE_VERSION

logger = logging.getLogger(__name__)

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

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

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,6 +86,7 @@
WhoisRestServlet,
)
from synapse.types import JsonDict, RoomStreamToken
from synapse.util import SYNAPSE_VERSION

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

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

Expand Down
6 changes: 6 additions & 0 deletions synapse/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import attr
from frozendict import frozendict
from matrix_common.versionstring import get_distribution_version_string

from twisted.internet import defer, task
from twisted.internet.defer import Deferred
Expand Down Expand Up @@ -183,3 +184,8 @@ def log_failure(
if not consumeErrors:
return failure
return None


# Version string with git info. Computed here once so that we don't invoke git multiple
# times.
SYNAPSE_VERSION = get_distribution_version_string("matrix-synapse", __file__)