python_dependencies.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. # Copyright 2015, 2016 OpenMarket Ltd
  2. # Copyright 2017 Vector Creations Ltd
  3. # Copyright 2018 New Vector Ltd
  4. # Copyright 2020 The Matrix.org Foundation C.I.C.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import itertools
  18. import logging
  19. from typing import Set
  20. logger = logging.getLogger(__name__)
  21. # REQUIREMENTS is a simple list of requirement specifiers[1], and must be
  22. # installed. It is passed to setup() as install_requires in setup.py.
  23. #
  24. # CONDITIONAL_REQUIREMENTS is the optional dependencies, represented as a dict
  25. # of lists. The dict key is the optional dependency name and can be passed to
  26. # pip when installing. The list is a series of requirement specifiers[1] to be
  27. # installed when that optional dependency requirement is specified. It is passed
  28. # to setup() as extras_require in setup.py
  29. #
  30. # Note that these both represent runtime dependencies (and the versions
  31. # installed are checked at runtime).
  32. #
  33. # Also note that we replicate these constraints in the Synapse Dockerfile while
  34. # pre-installing dependencies. If these constraints are updated here, the same
  35. # change should be made in the Dockerfile.
  36. #
  37. # [1] https://pip.pypa.io/en/stable/reference/pip_install/#requirement-specifiers.
  38. REQUIREMENTS = [
  39. # we use the TYPE_CHECKER.redefine method added in jsonschema 3.0.0
  40. "jsonschema>=3.0.0",
  41. # frozendict 2.1.2 is broken on Debian 10: https://github.com/Marco-Sulla/python-frozendict/issues/41
  42. "frozendict>=1,!=2.1.2",
  43. "unpaddedbase64>=1.1.0",
  44. "canonicaljson>=1.4.0",
  45. # we use the type definitions added in signedjson 1.1.
  46. "signedjson>=1.1.0",
  47. "pynacl>=1.2.1",
  48. "idna>=2.5",
  49. # validating SSL certs for IP addresses requires service_identity 18.1.
  50. "service_identity>=18.1.0",
  51. # Twisted 18.9 introduces some logger improvements that the structured
  52. # logger utilises
  53. "Twisted>=18.9.0",
  54. "treq>=15.1",
  55. # Twisted has required pyopenssl 16.0 since about Twisted 16.6.
  56. "pyopenssl>=16.0.0",
  57. "pyyaml>=3.11",
  58. "pyasn1>=0.1.9",
  59. "pyasn1-modules>=0.0.7",
  60. "bcrypt>=3.1.0",
  61. "pillow>=5.4.0",
  62. "sortedcontainers>=1.4.4",
  63. "pymacaroons>=0.13.0",
  64. "msgpack>=0.5.2",
  65. "phonenumbers>=8.2.0",
  66. # we use GaugeHistogramMetric, which was added in prom-client 0.4.0.
  67. "prometheus_client>=0.4.0",
  68. # we use `order`, which arrived in attrs 19.2.0.
  69. # Note: 21.1.0 broke `/sync`, see #9936
  70. "attrs>=19.2.0,!=21.1.0",
  71. "netaddr>=0.7.18",
  72. "Jinja2>=2.9",
  73. "bleach>=1.4.3",
  74. # We use `ParamSpec`, which was added in `typing-extensions` 3.10.0.0.
  75. "typing-extensions>=3.10.0",
  76. # We enforce that we have a `cryptography` version that bundles an `openssl`
  77. # with the latest security patches.
  78. "cryptography>=3.4.7",
  79. # ijson 3.1.4 fixes a bug with "." in property names
  80. "ijson>=3.1.4",
  81. "matrix-common~=1.1.0",
  82. # We need packaging.requirements.Requirement, added in 16.1.
  83. "packaging>=16.1",
  84. ]
  85. CONDITIONAL_REQUIREMENTS = {
  86. "matrix-synapse-ldap3": ["matrix-synapse-ldap3>=0.1"],
  87. "postgres": [
  88. # we use execute_values with the fetch param, which arrived in psycopg 2.8.
  89. "psycopg2>=2.8 ; platform_python_implementation != 'PyPy'",
  90. "psycopg2cffi>=2.8 ; platform_python_implementation == 'PyPy'",
  91. "psycopg2cffi-compat==1.1 ; platform_python_implementation == 'PyPy'",
  92. ],
  93. "saml2": [
  94. "pysaml2>=4.5.0",
  95. ],
  96. "oidc": ["authlib>=0.14.0"],
  97. # systemd-python is necessary for logging to the systemd journal via
  98. # `systemd.journal.JournalHandler`, as is documented in
  99. # `contrib/systemd/log_config.yaml`.
  100. "systemd": ["systemd-python>=231"],
  101. "url_preview": ["lxml>=4.2.0"],
  102. "sentry": ["sentry-sdk>=0.7.2"],
  103. "opentracing": ["jaeger-client>=4.0.0", "opentracing>=2.2.0"],
  104. "jwt": ["pyjwt>=1.6.4"],
  105. # hiredis is not a *strict* dependency, but it makes things much faster.
  106. # (if it is not installed, we fall back to slow code.)
  107. "redis": ["txredisapi>=1.4.7", "hiredis"],
  108. # Required to use experimental `caches.track_memory_usage` config option.
  109. "cache_memory": ["pympler"],
  110. }
  111. ALL_OPTIONAL_REQUIREMENTS: Set[str] = set()
  112. for name, optional_deps in CONDITIONAL_REQUIREMENTS.items():
  113. # Exclude systemd as it's a system-based requirement.
  114. # Exclude lint as it's a dev-based requirement.
  115. if name not in ["systemd"]:
  116. ALL_OPTIONAL_REQUIREMENTS = set(optional_deps) | ALL_OPTIONAL_REQUIREMENTS
  117. # ensure there are no double-quote characters in any of the deps (otherwise the
  118. # 'pip install' incantation in DependencyException will break)
  119. for dep in itertools.chain(
  120. REQUIREMENTS,
  121. *CONDITIONAL_REQUIREMENTS.values(),
  122. ):
  123. if '"' in dep:
  124. raise Exception(
  125. "Dependency `%s` contains double-quote; use single-quotes instead" % (dep,)
  126. )
  127. def list_requirements():
  128. return list(set(REQUIREMENTS) | ALL_OPTIONAL_REQUIREMENTS)
  129. if __name__ == "__main__":
  130. import sys
  131. sys.stdout.writelines(req + "\n" for req in list_requirements())