setup.py 5.2 KB

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