2016-01-06 23:26:29 -05:00
|
|
|
# Copyright 2015, 2016 OpenMarket Ltd
|
2017-03-13 13:27:51 -04:00
|
|
|
# Copyright 2017 Vector Creations Ltd
|
2018-04-26 07:34:40 -04:00
|
|
|
# Copyright 2018 New Vector Ltd
|
2020-01-30 06:25:59 -05:00
|
|
|
# Copyright 2020 The Matrix.org Foundation C.I.C.
|
2015-04-24 05:35:29 -04:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2021-03-29 06:55:33 -04:00
|
|
|
import itertools
|
2015-01-08 12:07:28 -05:00
|
|
|
import logging
|
2019-10-02 08:29:01 -04:00
|
|
|
from typing import List, Set
|
2018-12-21 09:37:26 -05:00
|
|
|
|
2019-05-21 10:58:01 -04:00
|
|
|
from pkg_resources import (
|
|
|
|
DistributionNotFound,
|
|
|
|
Requirement,
|
|
|
|
VersionConflict,
|
|
|
|
get_provider,
|
|
|
|
)
|
2015-01-08 12:07:28 -05:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2018-12-21 09:37:26 -05:00
|
|
|
|
|
|
|
# REQUIREMENTS is a simple list of requirement specifiers[1], and must be
|
|
|
|
# installed. It is passed to setup() as install_requires in setup.py.
|
2018-04-26 07:34:40 -04:00
|
|
|
#
|
2018-12-21 09:37:26 -05:00
|
|
|
# CONDITIONAL_REQUIREMENTS is the optional dependencies, represented as a dict
|
|
|
|
# of lists. The dict key is the optional dependency name and can be passed to
|
|
|
|
# pip when installing. The list is a series of requirement specifiers[1] to be
|
|
|
|
# installed when that optional dependency requirement is specified. It is passed
|
|
|
|
# to setup() as extras_require in setup.py
|
2018-04-26 07:34:40 -04:00
|
|
|
#
|
2020-09-23 06:45:37 -04:00
|
|
|
# Note that these both represent runtime dependencies (and the versions
|
|
|
|
# installed are checked at runtime).
|
|
|
|
#
|
2020-12-04 08:01:06 -05:00
|
|
|
# Also note that we replicate these constraints in the Synapse Dockerfile while
|
|
|
|
# pre-installing dependencies. If these constraints are updated here, the same
|
|
|
|
# change should be made in the Dockerfile.
|
|
|
|
#
|
2018-04-26 07:34:40 -04:00
|
|
|
# [1] https://pip.pypa.io/en/stable/reference/pip_install/#requirement-specifiers.
|
|
|
|
|
2018-12-21 09:37:26 -05:00
|
|
|
REQUIREMENTS = [
|
|
|
|
"jsonschema>=2.5.1",
|
|
|
|
"frozendict>=1",
|
|
|
|
"unpaddedbase64>=1.1.0",
|
2020-09-07 07:21:38 -04:00
|
|
|
"canonicaljson>=1.4.0",
|
2020-01-30 06:25:59 -05:00
|
|
|
# we use the type definitions added in signedjson 1.1.
|
|
|
|
"signedjson>=1.1.0",
|
2018-12-21 09:37:26 -05:00
|
|
|
"pynacl>=1.2.1",
|
2019-06-12 07:31:59 -04:00
|
|
|
"idna>=2.5",
|
2019-06-10 10:58:35 -04:00
|
|
|
# validating SSL certs for IP addresses requires service_identity 18.1.
|
|
|
|
"service_identity>=18.1.0",
|
2019-08-28 07:18:53 -04:00
|
|
|
# Twisted 18.9 introduces some logger improvements that the structured
|
|
|
|
# logger utilises
|
|
|
|
"Twisted>=18.9.0",
|
2018-12-21 09:37:26 -05:00
|
|
|
"treq>=15.1",
|
2018-09-06 07:53:15 -04:00
|
|
|
# Twisted has required pyopenssl 16.0 since about Twisted 16.6.
|
2018-12-21 09:37:26 -05:00
|
|
|
"pyopenssl>=16.0.0",
|
|
|
|
"pyyaml>=3.11",
|
|
|
|
"pyasn1>=0.1.9",
|
|
|
|
"pyasn1-modules>=0.0.7",
|
|
|
|
"bcrypt>=3.1.0",
|
2019-05-16 14:04:26 -04:00
|
|
|
"pillow>=4.3.0",
|
2018-12-21 09:37:26 -05:00
|
|
|
"sortedcontainers>=1.4.4",
|
2019-01-16 03:44:22 -05:00
|
|
|
"pymacaroons>=0.13.0",
|
2019-06-12 07:31:59 -04:00
|
|
|
"msgpack>=0.5.2",
|
2018-12-21 09:37:26 -05:00
|
|
|
"phonenumbers>=8.2.0",
|
2020-09-30 11:42:05 -04:00
|
|
|
# we use GaugeHistogramMetric, which was added in prom-client 0.4.0.
|
2020-12-04 08:01:06 -05:00
|
|
|
"prometheus_client>=0.4.0",
|
2020-08-28 12:12:45 -04:00
|
|
|
# we use attr.validators.deep_iterable, which arrived in 19.1.0 (Note:
|
|
|
|
# Fedora 31 only has 19.1, so if we want to upgrade we should wait until 33
|
|
|
|
# is out in November.)
|
2021-05-06 09:06:06 -04:00
|
|
|
# Note: 21.1.0 broke `/sync`, see #9936
|
2021-05-07 07:57:21 -04:00
|
|
|
"attrs>=19.1.0,!=21.1.0",
|
2018-12-21 09:37:26 -05:00
|
|
|
"netaddr>=0.7.18",
|
2019-06-21 11:52:09 -04:00
|
|
|
"Jinja2>=2.9",
|
|
|
|
"bleach>=1.4.3",
|
2019-10-02 08:29:01 -04:00
|
|
|
"typing-extensions>=3.7.4",
|
2021-03-26 08:00:25 -04:00
|
|
|
# We enforce that we have a `cryptography` version that bundles an `openssl`
|
|
|
|
# with the latest security patches.
|
2021-04-27 08:13:07 -04:00
|
|
|
"cryptography>=3.4.7",
|
2021-05-20 11:11:48 -04:00
|
|
|
"ijson>=3.0",
|
2018-12-21 09:37:26 -05:00
|
|
|
]
|
2018-06-05 10:13:57 -04:00
|
|
|
|
2015-03-17 07:45:37 -04:00
|
|
|
CONDITIONAL_REQUIREMENTS = {
|
2018-12-21 09:37:26 -05:00
|
|
|
"matrix-synapse-ldap3": ["matrix-synapse-ldap3>=0.1"],
|
2021-02-04 08:29:47 -05:00
|
|
|
"postgres": [
|
|
|
|
# we use execute_values with the fetch param, which arrived in psycopg 2.8.
|
|
|
|
"psycopg2>=2.8 ; platform_python_implementation != 'PyPy'",
|
|
|
|
"psycopg2cffi>=2.8 ; platform_python_implementation == 'PyPy'",
|
|
|
|
"psycopg2cffi-compat==1.1 ; platform_python_implementation == 'PyPy'",
|
|
|
|
],
|
2019-01-23 03:39:06 -05:00
|
|
|
# ACME support is required to provision TLS certificates from authorities
|
|
|
|
# that use the protocol, such as Let's Encrypt.
|
2019-05-21 10:58:01 -04:00
|
|
|
"acme": [
|
|
|
|
"txacme>=0.9.2",
|
|
|
|
],
|
2020-12-08 13:41:25 -05:00
|
|
|
"saml2": [
|
2021-04-27 08:13:07 -04:00
|
|
|
"pysaml2>=4.5.0",
|
2020-12-08 13:41:25 -05:00
|
|
|
],
|
2020-05-08 08:30:40 -04:00
|
|
|
"oidc": ["authlib>=0.14.0"],
|
2021-02-23 08:42:36 -05:00
|
|
|
# systemd-python is necessary for logging to the systemd journal via
|
|
|
|
# `systemd.journal.JournalHandler`, as is documented in
|
|
|
|
# `contrib/systemd/log_config.yaml`.
|
2019-04-16 06:41:17 -04:00
|
|
|
"systemd": ["systemd-python>=231"],
|
2018-12-21 09:37:26 -05:00
|
|
|
"url_preview": ["lxml>=3.5.0"],
|
2019-02-12 08:55:58 -05:00
|
|
|
"sentry": ["sentry-sdk>=0.7.2"],
|
2019-07-11 05:36:03 -04:00
|
|
|
"opentracing": ["jaeger-client>=4.0.0", "opentracing>=2.2.0"],
|
2019-06-27 07:02:41 -04:00
|
|
|
"jwt": ["pyjwt>=1.6.4"],
|
2020-05-06 12:36:46 -04:00
|
|
|
# hiredis is not a *strict* dependency, but it makes things much faster.
|
|
|
|
# (if it is not installed, we fall back to slow code.)
|
|
|
|
"redis": ["txredisapi>=1.4.7", "hiredis"],
|
2021-05-05 11:54:36 -04:00
|
|
|
# Required to use experimental `caches.track_memory_usage` config option.
|
|
|
|
"cache_memory": ["pympler"],
|
2015-03-17 07:45:37 -04:00
|
|
|
}
|
|
|
|
|
2019-09-12 12:29:55 -04:00
|
|
|
ALL_OPTIONAL_REQUIREMENTS = set() # type: Set[str]
|
2019-04-16 06:41:17 -04:00
|
|
|
|
|
|
|
for name, optional_deps in CONDITIONAL_REQUIREMENTS.items():
|
|
|
|
# Exclude systemd as it's a system-based requirement.
|
2020-09-17 16:45:22 -04:00
|
|
|
# Exclude lint as it's a dev-based requirement.
|
2020-09-23 06:45:37 -04:00
|
|
|
if name not in ["systemd"]:
|
2019-04-16 06:41:17 -04:00
|
|
|
ALL_OPTIONAL_REQUIREMENTS = set(optional_deps) | ALL_OPTIONAL_REQUIREMENTS
|
2015-03-17 07:45:37 -04:00
|
|
|
|
2015-01-08 12:07:28 -05:00
|
|
|
|
2021-03-29 06:55:33 -04:00
|
|
|
# ensure there are no double-quote characters in any of the deps (otherwise the
|
|
|
|
# 'pip install' incantation in DependencyException will break)
|
|
|
|
for dep in itertools.chain(
|
|
|
|
REQUIREMENTS,
|
|
|
|
*CONDITIONAL_REQUIREMENTS.values(),
|
|
|
|
):
|
|
|
|
if '"' in dep:
|
|
|
|
raise Exception(
|
|
|
|
"Dependency `%s` contains double-quote; use single-quotes instead" % (dep,)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-04-16 06:41:17 -04:00
|
|
|
def list_requirements():
|
|
|
|
return list(set(REQUIREMENTS) | ALL_OPTIONAL_REQUIREMENTS)
|
2015-02-10 11:30:48 -05:00
|
|
|
|
2015-02-02 12:22:40 -05:00
|
|
|
|
2018-12-21 09:37:26 -05:00
|
|
|
class DependencyException(Exception):
|
2019-01-07 05:14:31 -05:00
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
return "\n".join(
|
|
|
|
[
|
|
|
|
"Missing Requirements: %s" % (", ".join(self.dependencies),),
|
|
|
|
"To install run:",
|
|
|
|
" pip install --upgrade --force %s" % (" ".join(self.dependencies),),
|
|
|
|
"",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2018-12-21 09:37:26 -05:00
|
|
|
@property
|
|
|
|
def dependencies(self):
|
|
|
|
for i in self.args[0]:
|
2021-03-29 06:55:33 -04:00
|
|
|
yield '"' + i + '"'
|
2016-11-15 06:22:29 -05:00
|
|
|
|
2015-02-02 12:22:40 -05:00
|
|
|
|
2019-05-21 10:58:01 -04:00
|
|
|
def check_requirements(for_feature=None):
|
2018-12-21 09:37:26 -05:00
|
|
|
deps_needed = []
|
|
|
|
errors = []
|
2015-01-08 12:07:28 -05:00
|
|
|
|
2019-01-07 05:14:31 -05:00
|
|
|
if for_feature:
|
|
|
|
reqs = CONDITIONAL_REQUIREMENTS[for_feature]
|
|
|
|
else:
|
|
|
|
reqs = REQUIREMENTS
|
|
|
|
|
|
|
|
for dependency in reqs:
|
2018-12-21 09:37:26 -05:00
|
|
|
try:
|
2019-05-21 10:58:01 -04:00
|
|
|
_check_requirement(dependency)
|
2018-12-21 09:37:26 -05:00
|
|
|
except VersionConflict as e:
|
|
|
|
deps_needed.append(dependency)
|
|
|
|
errors.append(
|
|
|
|
"Needed %s, got %s==%s"
|
2019-10-02 08:29:01 -04:00
|
|
|
% (
|
|
|
|
dependency,
|
|
|
|
e.dist.project_name, # type: ignore[attr-defined] # noqa
|
|
|
|
e.dist.version, # type: ignore[attr-defined] # noqa
|
|
|
|
)
|
2015-01-08 12:07:28 -05:00
|
|
|
)
|
2018-12-21 09:37:26 -05:00
|
|
|
except DistributionNotFound:
|
|
|
|
deps_needed.append(dependency)
|
2019-09-11 09:00:37 -04:00
|
|
|
if for_feature:
|
|
|
|
errors.append(
|
|
|
|
"Needed %s for the '%s' feature but it was not installed"
|
|
|
|
% (dependency, for_feature)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
errors.append("Needed %s but it was not installed" % (dependency,))
|
2015-01-08 12:07:28 -05:00
|
|
|
|
2019-01-07 05:14:31 -05:00
|
|
|
if not for_feature:
|
|
|
|
# Check the optional dependencies are up to date. We allow them to not be
|
|
|
|
# installed.
|
2019-10-02 08:29:01 -04:00
|
|
|
OPTS = sum(CONDITIONAL_REQUIREMENTS.values(), []) # type: List[str]
|
2019-01-07 05:14:31 -05:00
|
|
|
|
|
|
|
for dependency in OPTS:
|
|
|
|
try:
|
2019-05-21 10:58:01 -04:00
|
|
|
_check_requirement(dependency)
|
2019-01-23 12:41:59 -05:00
|
|
|
except VersionConflict as e:
|
2019-01-07 05:14:31 -05:00
|
|
|
deps_needed.append(dependency)
|
2019-01-23 12:41:59 -05:00
|
|
|
errors.append(
|
|
|
|
"Needed optional %s, got %s==%s"
|
2019-10-02 08:29:01 -04:00
|
|
|
% (
|
|
|
|
dependency,
|
|
|
|
e.dist.project_name, # type: ignore[attr-defined] # noqa
|
|
|
|
e.dist.version, # type: ignore[attr-defined] # noqa
|
|
|
|
)
|
2019-01-23 12:41:59 -05:00
|
|
|
)
|
2019-01-07 05:14:31 -05:00
|
|
|
except DistributionNotFound:
|
|
|
|
# If it's not found, we don't care
|
|
|
|
pass
|
2015-02-10 11:30:48 -05:00
|
|
|
|
2018-12-21 09:37:26 -05:00
|
|
|
if deps_needed:
|
2019-09-12 12:29:55 -04:00
|
|
|
for err in errors:
|
|
|
|
logging.error(err)
|
2018-12-21 09:37:26 -05:00
|
|
|
|
|
|
|
raise DependencyException(deps_needed)
|
2015-02-02 12:22:40 -05:00
|
|
|
|
2016-11-15 06:22:29 -05:00
|
|
|
|
2019-05-21 10:58:01 -04:00
|
|
|
def _check_requirement(dependency_string):
|
|
|
|
"""Parses a dependency string, and checks if the specified requirement is installed
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
VersionConflict if the requirement is installed, but with the the wrong version
|
|
|
|
DistributionNotFound if nothing is found to provide the requirement
|
|
|
|
"""
|
|
|
|
req = Requirement.parse(dependency_string)
|
|
|
|
|
|
|
|
# first check if the markers specify that this requirement needs installing
|
|
|
|
if req.marker is not None and not req.marker.evaluate():
|
|
|
|
# not required for this environment
|
|
|
|
return
|
|
|
|
|
|
|
|
get_provider(req)
|
|
|
|
|
|
|
|
|
2015-02-02 12:22:40 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
import sys
|
2018-12-21 09:37:26 -05:00
|
|
|
|
2015-02-02 12:22:40 -05:00
|
|
|
sys.stdout.writelines(req + "\n" for req in list_requirements())
|