2
0

setup.py 8.4 KB

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