setup.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # -*- encoding: utf-8 *-*
  2. import os
  3. import sys
  4. from glob import glob
  5. min_python = (3, 2)
  6. if sys.version_info < min_python:
  7. print("Borg requires Python %d.%d or later" % min_python)
  8. sys.exit(1)
  9. from setuptools import setup, Extension
  10. from setuptools.command.sdist import sdist
  11. compress_source = 'borg/compress.pyx'
  12. crypto_source = 'borg/crypto.pyx'
  13. chunker_source = 'borg/chunker.pyx'
  14. hashindex_source = 'borg/hashindex.pyx'
  15. platform_linux_source = 'borg/platform_linux.pyx'
  16. platform_darwin_source = 'borg/platform_darwin.pyx'
  17. platform_freebsd_source = 'borg/platform_freebsd.pyx'
  18. try:
  19. from Cython.Distutils import build_ext
  20. import Cython.Compiler.Main as cython_compiler
  21. class Sdist(sdist):
  22. def __init__(self, *args, **kwargs):
  23. for src in glob('borg/*.pyx'):
  24. cython_compiler.compile(src, cython_compiler.default_options)
  25. super().__init__(*args, **kwargs)
  26. def make_distribution(self):
  27. self.filelist.extend([
  28. 'borg/compress.c',
  29. 'borg/crypto.c',
  30. 'borg/chunker.c', 'borg/_chunker.c',
  31. 'borg/hashindex.c', 'borg/_hashindex.c',
  32. 'borg/platform_linux.c',
  33. 'borg/platform_freebsd.c',
  34. 'borg/platform_darwin.c',
  35. ])
  36. super().make_distribution()
  37. except ImportError:
  38. class Sdist(sdist):
  39. def __init__(self, *args, **kwargs):
  40. raise Exception('Cython is required to run sdist')
  41. compress_source = compress_source.replace('.pyx', '.c')
  42. crypto_source = crypto_source.replace('.pyx', '.c')
  43. chunker_source = chunker_source.replace('.pyx', '.c')
  44. hashindex_source = hashindex_source.replace('.pyx', '.c')
  45. platform_linux_source = platform_linux_source.replace('.pyx', '.c')
  46. platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c')
  47. platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
  48. from distutils.command.build_ext import build_ext
  49. if not all(os.path.exists(path) for path in [
  50. compress_source, crypto_source, chunker_source, hashindex_source,
  51. platform_linux_source, platform_freebsd_source]):
  52. raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version')
  53. def detect_openssl(prefixes):
  54. for prefix in prefixes:
  55. filename = os.path.join(prefix, 'include', 'openssl', 'evp.h')
  56. if os.path.exists(filename):
  57. with open(filename, 'r') as fd:
  58. if 'PKCS5_PBKDF2_HMAC(' in fd.read():
  59. return prefix
  60. possible_openssl_prefixes = ['/usr', '/usr/local', '/usr/local/opt/openssl', '/usr/local/ssl', '/usr/local/openssl', '/usr/local/borg', '/opt/local']
  61. if os.environ.get('BORG_OPENSSL_PREFIX'):
  62. possible_openssl_prefixes.insert(0, os.environ.get('BORG_OPENSSL_PREFIX'))
  63. ssl_prefix = detect_openssl(possible_openssl_prefixes)
  64. if not ssl_prefix:
  65. raise Exception('Unable to find OpenSSL >= 1.0 headers. (Looked here: {})'.format(', '.join(possible_openssl_prefixes)))
  66. include_dirs = [os.path.join(ssl_prefix, 'include')]
  67. library_dirs = [os.path.join(ssl_prefix, 'lib')]
  68. with open('README.rst', 'r') as fd:
  69. long_description = fd.read()
  70. cmdclass = {'build_ext': build_ext, 'sdist': Sdist}
  71. ext_modules = [
  72. Extension('borg.compress', [compress_source], libraries=['lz4']),
  73. Extension('borg.crypto', [crypto_source], libraries=['crypto'], include_dirs=include_dirs, library_dirs=library_dirs),
  74. Extension('borg.chunker', [chunker_source]),
  75. Extension('borg.hashindex', [hashindex_source])
  76. ]
  77. if sys.platform.startswith('linux'):
  78. ext_modules.append(Extension('borg.platform_linux', [platform_linux_source], libraries=['acl']))
  79. elif sys.platform.startswith('freebsd'):
  80. ext_modules.append(Extension('borg.platform_freebsd', [platform_freebsd_source]))
  81. elif sys.platform == 'darwin':
  82. ext_modules.append(Extension('borg.platform_darwin', [platform_darwin_source]))
  83. setup(
  84. name='borgbackup',
  85. use_scm_version={
  86. 'write_to': 'borg/_version.py',
  87. },
  88. author='The Borg Collective (see AUTHORS file)',
  89. author_email='borgbackup@librelist.com',
  90. url='https://borgbackup.github.io/',
  91. description='Deduplicated, encrypted, authenticated and compressed backups',
  92. long_description=long_description,
  93. license='BSD',
  94. platforms=['Linux', 'MacOS X', 'FreeBSD', ],
  95. classifiers=[
  96. 'Development Status :: 4 - Beta',
  97. 'Environment :: Console',
  98. 'Intended Audience :: System Administrators',
  99. 'License :: OSI Approved :: BSD License',
  100. 'Operating System :: POSIX :: BSD :: FreeBSD',
  101. 'Operating System :: MacOS :: MacOS X',
  102. 'Operating System :: POSIX :: Linux',
  103. 'Programming Language :: Python',
  104. 'Programming Language :: Python :: 3',
  105. 'Programming Language :: Python :: 3.2',
  106. 'Programming Language :: Python :: 3.3',
  107. 'Programming Language :: Python :: 3.4',
  108. 'Topic :: Security :: Cryptography',
  109. 'Topic :: System :: Archiving :: Backup',
  110. ],
  111. packages=['borg', 'borg.testsuite'],
  112. entry_points={
  113. 'console_scripts': [
  114. 'borg = borg.archiver:main',
  115. ]
  116. },
  117. cmdclass=cmdclass,
  118. ext_modules=ext_modules,
  119. setup_requires=['setuptools_scm>=1.7'],
  120. # msgpack pure python data corruption was fixed in 0.4.6.
  121. # Also, we might use some rather recent API features.
  122. install_requires=['msgpack-python>=0.4.6'],
  123. )