setup.py 5.7 KB

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