setup.py 6.5 KB

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