2
0

setup.py 8.9 KB

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