setup.py 5.6 KB

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