setup.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 setuptools import setup, find_packages, Command
  20. import sys
  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. user_options = []
  49. def initialize_options(self):
  50. pass
  51. def finalize_options(self):
  52. pass
  53. def run(self):
  54. print(
  55. """Synapse's tests cannot be run via setup.py. To run them, try:
  56. PYTHONPATH="." trial tests
  57. """
  58. )
  59. def read_file(path_segments):
  60. """Read a file from the package. Takes a list of strings to join to
  61. make the path"""
  62. file_path = os.path.join(here, *path_segments)
  63. with open(file_path) as f:
  64. return f.read()
  65. def exec_file(path_segments):
  66. """Execute a single python file to get the variables defined in it"""
  67. result = {}
  68. code = read_file(path_segments)
  69. exec(code, result)
  70. return result
  71. version = exec_file(("synapse", "__init__.py"))["__version__"]
  72. dependencies = exec_file(("synapse", "python_dependencies.py"))
  73. long_description = read_file(("README.rst",))
  74. REQUIREMENTS = dependencies["REQUIREMENTS"]
  75. CONDITIONAL_REQUIREMENTS = dependencies["CONDITIONAL_REQUIREMENTS"]
  76. ALL_OPTIONAL_REQUIREMENTS = dependencies["ALL_OPTIONAL_REQUIREMENTS"]
  77. # Make `pip install matrix-synapse[all]` install all the optional dependencies.
  78. CONDITIONAL_REQUIREMENTS["all"] = list(ALL_OPTIONAL_REQUIREMENTS)
  79. setup(
  80. name="matrix-synapse",
  81. version=version,
  82. packages=find_packages(exclude=["tests", "tests.*"]),
  83. description="Reference homeserver for the Matrix decentralised comms protocol",
  84. install_requires=REQUIREMENTS,
  85. extras_require=CONDITIONAL_REQUIREMENTS,
  86. include_package_data=True,
  87. zip_safe=False,
  88. long_description=long_description,
  89. python_requires="~=3.5",
  90. classifiers=[
  91. "Development Status :: 5 - Production/Stable",
  92. "Topic :: Communications :: Chat",
  93. "License :: OSI Approved :: Apache Software License",
  94. "Programming Language :: Python :: 3 :: Only",
  95. "Programming Language :: Python :: 3.5",
  96. "Programming Language :: Python :: 3.6",
  97. "Programming Language :: Python :: 3.7",
  98. ],
  99. scripts=["synctl"] + glob.glob("scripts/*"),
  100. cmdclass={"test": TestCommand},
  101. )