1
0

setup.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #!/usr/bin/env python
  2. # Copyright 2014-2017 OpenMarket Ltd
  3. # Copyright 2017 Vector Creations Ltd
  4. # Copyright 2017-2018 New Vector Ltd
  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 os
  18. from typing import Any, Dict
  19. from setuptools import Command, find_packages, setup
  20. here = os.path.abspath(os.path.dirname(__file__))
  21. # Some notes on `setup.py test`:
  22. #
  23. # Once upon a time we used to try to make `setup.py test` run `tox` to run the
  24. # tests. That's a bad idea for three reasons:
  25. #
  26. # 1: `setup.py test` is supposed to find out whether the tests work in the
  27. # *current* environmentt, not whatever tox sets up.
  28. # 2: Empirically, trying to install tox during the test run wasn't working ("No
  29. # module named virtualenv").
  30. # 3: The tox documentation advises against it[1].
  31. #
  32. # Even further back in time, we used to use setuptools_trial [2]. That has its
  33. # own set of issues: for instance, it requires installation of Twisted to build
  34. # an sdist (because the recommended mode of usage is to add it to
  35. # `setup_requires`). That in turn means that in order to successfully run tox
  36. # you have to have the python header files installed for whichever version of
  37. # python tox uses (which is python3 on recent ubuntus, for example).
  38. #
  39. # So, for now at least, we stick with what appears to be the convention among
  40. # Twisted projects, and don't attempt to do anything when someone runs
  41. # `setup.py test`; instead we direct people to run `trial` directly if they
  42. # care.
  43. #
  44. # [1]: http://tox.readthedocs.io/en/2.5.0/example/basic.html#integration-with-setup-py-test-command
  45. # [2]: https://pypi.python.org/pypi/setuptools_trial
  46. class TestCommand(Command):
  47. def initialize_options(self):
  48. pass
  49. def finalize_options(self):
  50. pass
  51. def run(self):
  52. print(
  53. """Synapse's tests cannot be run via setup.py. To run them, try:
  54. PYTHONPATH="." trial tests
  55. """
  56. )
  57. def read_file(path_segments):
  58. """Read a file from the package. Takes a list of strings to join to
  59. make the path"""
  60. file_path = os.path.join(here, *path_segments)
  61. with open(file_path) as f:
  62. return f.read()
  63. def exec_file(path_segments):
  64. """Execute a single python file to get the variables defined in it"""
  65. result: Dict[str, Any] = {}
  66. code = read_file(path_segments)
  67. exec(code, result)
  68. return result
  69. version = exec_file(("synapse", "__init__.py"))["__version__"]
  70. dependencies = exec_file(("synapse", "python_dependencies.py"))
  71. long_description = read_file(("README.rst",))
  72. REQUIREMENTS = dependencies["REQUIREMENTS"]
  73. CONDITIONAL_REQUIREMENTS = dependencies["CONDITIONAL_REQUIREMENTS"]
  74. ALL_OPTIONAL_REQUIREMENTS = dependencies["ALL_OPTIONAL_REQUIREMENTS"]
  75. # Make `pip install matrix-synapse[all]` install all the optional dependencies.
  76. CONDITIONAL_REQUIREMENTS["all"] = list(ALL_OPTIONAL_REQUIREMENTS)
  77. # Developer dependencies should not get included in "all".
  78. #
  79. # We pin black so that our tests don't start failing on new releases.
  80. CONDITIONAL_REQUIREMENTS["lint"] = [
  81. "isort==5.7.0",
  82. "black==22.3.0",
  83. "flake8-comprehensions",
  84. "flake8-bugbear==21.3.2",
  85. "flake8",
  86. ]
  87. CONDITIONAL_REQUIREMENTS["mypy"] = [
  88. "mypy==0.931",
  89. "mypy-zope==0.3.5",
  90. "types-bleach>=4.1.0",
  91. "types-jsonschema>=3.2.0",
  92. "types-opentracing>=2.4.2",
  93. "types-Pillow>=8.3.4",
  94. "types-psycopg2>=2.9.9",
  95. "types-pyOpenSSL>=20.0.7",
  96. "types-PyYAML>=5.4.10",
  97. "types-requests>=2.26.0",
  98. "types-setuptools>=57.4.0",
  99. ]
  100. # Dependencies which are exclusively required by unit test code. This is
  101. # NOT a list of all modules that are necessary to run the unit tests.
  102. # Tests assume that all optional dependencies are installed.
  103. #
  104. # parameterized_class decorator was introduced in parameterized 0.7.0
  105. CONDITIONAL_REQUIREMENTS["test"] = ["parameterized>=0.7.0"]
  106. CONDITIONAL_REQUIREMENTS["dev"] = (
  107. CONDITIONAL_REQUIREMENTS["lint"]
  108. + CONDITIONAL_REQUIREMENTS["mypy"]
  109. + CONDITIONAL_REQUIREMENTS["test"]
  110. + [
  111. # The following are used by the release script
  112. "click==8.1.0",
  113. "redbaron==0.9.2",
  114. "GitPython==3.1.14",
  115. "commonmark==0.9.1",
  116. "pygithub==1.55",
  117. # The following are executed as commands by the release script.
  118. "twine",
  119. "towncrier",
  120. ]
  121. )
  122. setup(
  123. name="matrix-synapse",
  124. version=version,
  125. packages=find_packages(exclude=["tests", "tests.*"]),
  126. description="Reference homeserver for the Matrix decentralised comms protocol",
  127. install_requires=REQUIREMENTS,
  128. extras_require=CONDITIONAL_REQUIREMENTS,
  129. include_package_data=True,
  130. zip_safe=False,
  131. long_description=long_description,
  132. long_description_content_type="text/x-rst",
  133. python_requires="~=3.7",
  134. entry_points={
  135. "console_scripts": [
  136. # Application
  137. "synapse_homeserver = synapse.app.homeserver:main",
  138. "synapse_worker = synapse.app.generic_worker:main",
  139. "synctl = synapse._scripts.synctl:main",
  140. # Scripts
  141. "export_signing_key = synapse._scripts.export_signing_key:main",
  142. "generate_config = synapse._scripts.generate_config:main",
  143. "generate_log_config = synapse._scripts.generate_log_config:main",
  144. "generate_signing_key = synapse._scripts.generate_signing_key:main",
  145. "hash_password = synapse._scripts.hash_password:main",
  146. "register_new_matrix_user = synapse._scripts.register_new_matrix_user:main",
  147. "synapse_port_db = synapse._scripts.synapse_port_db:main",
  148. "synapse_review_recent_signups = synapse._scripts.review_recent_signups:main",
  149. "update_synapse_database = synapse._scripts.update_synapse_database:main",
  150. ]
  151. },
  152. classifiers=[
  153. "Development Status :: 5 - Production/Stable",
  154. "Topic :: Communications :: Chat",
  155. "License :: OSI Approved :: Apache Software License",
  156. "Programming Language :: Python :: 3 :: Only",
  157. "Programming Language :: Python :: 3.7",
  158. "Programming Language :: Python :: 3.8",
  159. "Programming Language :: Python :: 3.9",
  160. "Programming Language :: Python :: 3.10",
  161. ],
  162. cmdclass={"test": TestCommand},
  163. )