setup.py 5.4 KB

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