setup.py 5.4 KB

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