setup.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import os
  2. import io
  3. import re
  4. import sys
  5. from collections import OrderedDict
  6. from datetime import datetime
  7. from glob import glob
  8. try:
  9. import multiprocessing
  10. except ImportError:
  11. multiprocessing = None
  12. from distutils.command.clean import clean
  13. from setuptools.command.build_ext import build_ext
  14. from setuptools import setup, find_packages, Extension
  15. from setuptools.command.sdist import sdist
  16. try:
  17. from Cython.Build import cythonize
  18. except ImportError:
  19. cythonize = None
  20. import setup_lz4
  21. import setup_zstd
  22. import setup_b2
  23. import setup_crypto
  24. import setup_docs
  25. # True: use the shared liblz4 (>= 1.7.0 / r129) from the system, False: use the bundled lz4 code
  26. prefer_system_liblz4 = True
  27. # True: use the shared libzstd (>= 1.3.0) from the system, False: use the bundled zstd code
  28. prefer_system_libzstd = True
  29. # True: use the shared libb2 from the system, False: use the bundled blake2 code
  30. prefer_system_libb2 = True
  31. cpu_threads = multiprocessing.cpu_count() if multiprocessing else 1
  32. # Are we building on ReadTheDocs?
  33. on_rtd = os.environ.get('READTHEDOCS')
  34. install_requires = [
  35. # we are rather picky about msgpack versions, because a good working msgpack is
  36. # very important for borg, see: https://github.com/borgbackup/borg/issues/3753
  37. 'msgpack >=0.5.6, <=0.6.1',
  38. # Please note:
  39. # using any other version is not supported by borg development and
  40. # any feedback related to issues caused by this will be ignored.
  41. ]
  42. # note for package maintainers: if you package borgbackup for distribution,
  43. # please add llfuse as a *requirement* on all platforms that have a working
  44. # llfuse package. "borg mount" needs llfuse to work.
  45. # if you do not have llfuse, do not require it, most of borgbackup will work.
  46. extras_require = {
  47. # llfuse 1.x should work, llfuse 2.0 will break API
  48. 'fuse': [
  49. 'llfuse >=1.1, <2.0',
  50. 'llfuse >=1.3.4; python_version >="3.7"',
  51. ],
  52. }
  53. compress_source = 'src/borg/compress.pyx'
  54. crypto_ll_source = 'src/borg/crypto/low_level.pyx'
  55. crypto_helpers = 'src/borg/crypto/_crypto_helpers.c'
  56. chunker_source = 'src/borg/chunker.pyx'
  57. hashindex_source = 'src/borg/hashindex.pyx'
  58. item_source = 'src/borg/item.pyx'
  59. checksums_source = 'src/borg/algorithms/checksums.pyx'
  60. platform_posix_source = 'src/borg/platform/posix.pyx'
  61. platform_linux_source = 'src/borg/platform/linux.pyx'
  62. platform_darwin_source = 'src/borg/platform/darwin.pyx'
  63. platform_freebsd_source = 'src/borg/platform/freebsd.pyx'
  64. cython_sources = [
  65. compress_source,
  66. crypto_ll_source,
  67. chunker_source,
  68. hashindex_source,
  69. item_source,
  70. checksums_source,
  71. platform_posix_source,
  72. platform_linux_source,
  73. platform_freebsd_source,
  74. platform_darwin_source,
  75. ]
  76. if cythonize:
  77. Sdist = sdist
  78. else:
  79. class Sdist(sdist):
  80. def __init__(self, *args, **kwargs):
  81. raise Exception('Cython is required to run sdist')
  82. if not on_rtd and not all(os.path.exists(path) for path in [
  83. compress_source, crypto_ll_source, chunker_source, hashindex_source, item_source, checksums_source,
  84. platform_posix_source, platform_linux_source, platform_freebsd_source, platform_darwin_source]):
  85. raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
  86. with open('README.rst', 'r') as fd:
  87. long_description = fd.read()
  88. # remove header, but have one \n before first headline
  89. start = long_description.find('What is BorgBackup?')
  90. assert start >= 0
  91. long_description = '\n' + long_description[start:]
  92. # remove badges
  93. long_description = re.compile(r'^\.\. start-badges.*^\.\. end-badges', re.M | re.S).sub('', long_description)
  94. # remove unknown directives
  95. long_description = re.compile(r'^\.\. highlight:: \w+$', re.M).sub('', long_description)
  96. def rm(file):
  97. try:
  98. os.unlink(file)
  99. print('rm', file)
  100. except FileNotFoundError:
  101. pass
  102. class Clean(clean):
  103. def run(self):
  104. super().run()
  105. for source in cython_sources:
  106. genc = source.replace('.pyx', '.c')
  107. rm(genc)
  108. compiled_glob = source.replace('.pyx', '.cpython*')
  109. for compiled in sorted(glob(compiled_glob)):
  110. rm(compiled)
  111. cmdclass = {
  112. 'build_ext': build_ext,
  113. 'build_usage': setup_docs.build_usage,
  114. 'build_man': setup_docs.build_man,
  115. 'sdist': Sdist,
  116. 'clean': Clean,
  117. }
  118. ext_modules = []
  119. if not on_rtd:
  120. compress_ext_kwargs = dict(sources=[compress_source])
  121. compress_ext_kwargs = setup_lz4.lz4_ext_kwargs(prefer_system_liblz4, **compress_ext_kwargs)
  122. compress_ext_kwargs = setup_zstd.zstd_ext_kwargs(prefer_system_libzstd,
  123. multithreaded=False, legacy=False, **compress_ext_kwargs)
  124. crypto_ext_kwargs = dict(sources=[crypto_ll_source, crypto_helpers])
  125. crypto_ext_kwargs = setup_crypto.crypto_ext_kwargs(**crypto_ext_kwargs)
  126. crypto_ext_kwargs = setup_b2.b2_ext_kwargs(prefer_system_libb2, **crypto_ext_kwargs)
  127. ext_modules += [
  128. Extension('borg.compress', **compress_ext_kwargs),
  129. Extension('borg.crypto.low_level', **crypto_ext_kwargs),
  130. Extension('borg.hashindex', [hashindex_source]),
  131. Extension('borg.item', [item_source]),
  132. Extension('borg.chunker', [chunker_source]),
  133. Extension('borg.algorithms.checksums', [checksums_source]),
  134. ]
  135. posix_ext = Extension('borg.platform.posix', [platform_posix_source])
  136. linux_ext = Extension('borg.platform.linux', [platform_linux_source], libraries=['acl'])
  137. freebsd_ext = Extension('borg.platform.freebsd', [platform_freebsd_source])
  138. darwin_ext = Extension('borg.platform.darwin', [platform_darwin_source])
  139. if not sys.platform.startswith(('win32', )):
  140. ext_modules.append(posix_ext)
  141. if sys.platform == 'linux':
  142. ext_modules.append(linux_ext)
  143. elif sys.platform.startswith('freebsd'):
  144. ext_modules.append(freebsd_ext)
  145. elif sys.platform == 'darwin':
  146. ext_modules.append(darwin_ext)
  147. # sometimes there's no need to cythonize
  148. # this breaks chained commands like 'clean sdist'
  149. cythonizing = len(sys.argv) > 1 and sys.argv[1] not in ('clean', 'egg_info', '--help-commands', '--version') \
  150. and '--help' not in sys.argv[1:]
  151. if cythonize and cythonizing:
  152. cython_opts = dict(
  153. # compile .pyx extensions to .c in parallel
  154. nthreads=cpu_threads + 1,
  155. # default language_level will be '3str' starting from Cython 3.0.0,
  156. # but old cython versions (< 0.29) do not know that, thus we use 3 for now.
  157. compiler_directives={'language_level': 3},
  158. )
  159. cythonize([posix_ext, linux_ext, freebsd_ext, darwin_ext], **cython_opts)
  160. ext_modules = cythonize(ext_modules, **cython_opts)
  161. setup(
  162. name='borgbackup',
  163. use_scm_version={
  164. 'write_to': 'src/borg/_version.py',
  165. },
  166. author='The Borg Collective (see AUTHORS file)',
  167. author_email='borgbackup@python.org',
  168. url='https://borgbackup.readthedocs.io/',
  169. description='Deduplicated, encrypted, authenticated and compressed backups',
  170. long_description=long_description,
  171. license='BSD',
  172. platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ],
  173. classifiers=[
  174. 'Development Status :: 3 - Alpha',
  175. 'Environment :: Console',
  176. 'Intended Audience :: System Administrators',
  177. 'License :: OSI Approved :: BSD License',
  178. 'Operating System :: POSIX :: BSD :: FreeBSD',
  179. 'Operating System :: POSIX :: BSD :: OpenBSD',
  180. 'Operating System :: POSIX :: BSD :: NetBSD',
  181. 'Operating System :: MacOS :: MacOS X',
  182. 'Operating System :: POSIX :: Linux',
  183. 'Programming Language :: Python',
  184. 'Programming Language :: Python :: 3',
  185. 'Programming Language :: Python :: 3.5',
  186. 'Programming Language :: Python :: 3.6',
  187. 'Programming Language :: Python :: 3.7',
  188. 'Topic :: Security :: Cryptography',
  189. 'Topic :: System :: Archiving :: Backup',
  190. ],
  191. packages=find_packages('src'),
  192. package_dir={'': 'src'},
  193. zip_safe=False,
  194. entry_points={
  195. 'console_scripts': [
  196. 'borg = borg.archiver:main',
  197. 'borgfs = borg.archiver:main',
  198. ]
  199. },
  200. # See also the MANIFEST.in file.
  201. # We want to install all the files in the package directories...
  202. include_package_data=True,
  203. # ...except the source files which have been compiled (C extensions):
  204. exclude_package_data={
  205. '': ['*.c', '*.h', '*.pyx', ],
  206. },
  207. cmdclass=cmdclass,
  208. ext_modules=ext_modules,
  209. setup_requires=['setuptools_scm>=1.7'],
  210. install_requires=install_requires,
  211. extras_require=extras_require,
  212. python_requires='>=3.5',
  213. )