setup.py 5.5 KB

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