setup.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. def read_file(path_segments):
  21. """Read a file from the package. Takes a list of strings to join to
  22. make the path"""
  23. file_path = os.path.join(here, *path_segments)
  24. with open(file_path) as f:
  25. return f.read()
  26. def exec_file(path_segments):
  27. """Execute a single python file to get the variables defined in it"""
  28. result = {}
  29. code = read_file(path_segments)
  30. exec(code, result)
  31. return result
  32. class Tox(Command):
  33. user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
  34. def initialize_options(self):
  35. self.tox_args = None
  36. def finalize_options(self):
  37. self.test_args = []
  38. self.test_suite = True
  39. def run(self):
  40. #import here, cause outside the eggs aren't loaded
  41. try:
  42. import tox
  43. except ImportError:
  44. try:
  45. self.distribution.fetch_build_eggs("tox")
  46. import tox
  47. except:
  48. raise RuntimeError(
  49. "The tests need 'tox' to run. Please install 'tox'."
  50. )
  51. import shlex
  52. args = self.tox_args
  53. if args:
  54. args = shlex.split(self.tox_args)
  55. else:
  56. args = []
  57. errno = tox.cmdline(args=args)
  58. sys.exit(errno)
  59. version = exec_file(("synapse", "__init__.py"))["__version__"]
  60. dependencies = exec_file(("synapse", "python_dependencies.py"))
  61. long_description = read_file(("README.rst",))
  62. setup(
  63. name="matrix-synapse",
  64. version=version,
  65. packages=find_packages(exclude=["tests", "tests.*"]),
  66. description="Reference Synapse Home Server",
  67. install_requires=dependencies['requirements'](include_conditional=True).keys(),
  68. dependency_links=dependencies["DEPENDENCY_LINKS"].values(),
  69. include_package_data=True,
  70. zip_safe=False,
  71. long_description=long_description,
  72. scripts=["synctl"] + glob.glob("scripts/*"),
  73. cmdclass={'test': Tox},
  74. )