setup.py 6.5 KB

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