setup.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import glob
  16. import os
  17. from setuptools import setup, find_packages, Command
  18. import sys
  19. here = os.path.abspath(os.path.dirname(__file__))
  20. # Some notes on `setup.py test`:
  21. #
  22. # Once upon a time we used to try to make `setup.py test` run `tox` to run the
  23. # tests. That's a bad idea for three reasons:
  24. #
  25. # 1: `setup.py test` is supposed to find out whether the tests work in the
  26. # *current* environmentt, not whatever tox sets up.
  27. # 2: Empirically, trying to install tox during the test run wasn't working ("No
  28. # module named virtualenv").
  29. # 3: The tox documentation advises against it[1].
  30. #
  31. # Even further back in time, we used to use setuptools_trial [2]. That has its
  32. # own set of issues: for instance, it requires installation of Twisted to build
  33. # an sdist (because the recommended mode of usage is to add it to
  34. # `setup_requires`). That in turn means that in order to successfully run tox
  35. # you have to have the python header files installed for whichever version of
  36. # python tox uses (which is python3 on recent ubuntus, for example).
  37. #
  38. # So, for now at least, we stick with what appears to be the convention among
  39. # Twisted projects, and don't attempt to do anything when someone runs
  40. # `setup.py test`; instead we direct people to run `trial` directly if they
  41. # care.
  42. #
  43. # [1]: http://tox.readthedocs.io/en/2.5.0/example/basic.html#integration-with-setup-py-test-command
  44. # [2]: https://pypi.python.org/pypi/setuptools_trial
  45. class TestCommand(Command):
  46. user_options = []
  47. def initialize_options(self):
  48. pass
  49. def finalize_options(self):
  50. pass
  51. def run(self):
  52. print ("""Synapse's tests cannot be run via setup.py. To run them, try:
  53. PYTHONPATH="." trial tests
  54. """)
  55. def read_file(path_segments):
  56. """Read a file from the package. Takes a list of strings to join to
  57. make the path"""
  58. file_path = os.path.join(here, *path_segments)
  59. with open(file_path) as f:
  60. return f.read()
  61. def exec_file(path_segments):
  62. """Execute a single python file to get the variables defined in it"""
  63. result = {}
  64. code = read_file(path_segments)
  65. exec(code, result)
  66. return result
  67. version = exec_file(("synapse", "__init__.py"))["__version__"]
  68. dependencies = exec_file(("synapse", "python_dependencies.py"))
  69. long_description = read_file(("README.rst",))
  70. setup(
  71. name="matrix-synapse",
  72. version=version,
  73. packages=find_packages(exclude=["tests", "tests.*"]),
  74. description="Reference Synapse Home Server",
  75. install_requires=dependencies['requirements'](include_conditional=True).keys(),
  76. dependency_links=dependencies["DEPENDENCY_LINKS"].values(),
  77. include_package_data=True,
  78. zip_safe=False,
  79. long_description=long_description,
  80. scripts=["synctl"] + glob.glob("scripts/*"),
  81. cmdclass={'test': TestCommand},
  82. )