setup.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. # -*- encoding: utf-8 *-*
  2. import os
  3. import io
  4. import re
  5. import sys
  6. from collections import OrderedDict
  7. from datetime import datetime
  8. from glob import glob
  9. from distutils.command.build import build
  10. from distutils.core import Command
  11. import textwrap
  12. min_python = (3, 4)
  13. my_python = sys.version_info
  14. if my_python < min_python:
  15. print("Borg requires Python %d.%d or later" % min_python)
  16. sys.exit(1)
  17. # Are we building on ReadTheDocs?
  18. on_rtd = os.environ.get('READTHEDOCS')
  19. # msgpack pure python data corruption was fixed in 0.4.6.
  20. # Also, we might use some rather recent API features.
  21. install_requires = ['msgpack-python>=0.4.6', ]
  22. # note for package maintainers: if you package borgbackup for distribution,
  23. # please add llfuse as a *requirement* on all platforms that have a working
  24. # llfuse package. "borg mount" needs llfuse to work.
  25. # if you do not have llfuse, do not require it, most of borgbackup will work.
  26. extras_require = {
  27. # llfuse 0.40 (tested, proven, ok), needs FUSE version >= 2.8.0
  28. # llfuse 0.41 (tested shortly, looks ok), needs FUSE version >= 2.8.0
  29. # llfuse 0.41.1 (tested shortly, looks ok), needs FUSE version >= 2.8.0
  30. # llfuse 0.42 (tested shortly, looks ok), needs FUSE version >= 2.8.0
  31. # llfuse 1.0 (tested shortly, looks ok), needs FUSE version >= 2.8.0
  32. # llfuse 1.1.1 (tested shortly, looks ok), needs FUSE version >= 2.8.0
  33. # llfuse 2.0 will break API
  34. 'fuse': ['llfuse<2.0', ],
  35. }
  36. if sys.platform.startswith('freebsd'):
  37. # llfuse was frequently broken / did not build on freebsd
  38. # llfuse 0.41.1, 1.1 are ok
  39. extras_require['fuse'] = ['llfuse <2.0, !=0.42.*, !=0.43, !=1.0', ]
  40. from setuptools import setup, find_packages, Extension
  41. from setuptools.command.sdist import sdist
  42. from distutils.command.clean import clean
  43. compress_source = 'src/borg/compress.pyx'
  44. crypto_ll_source = 'src/borg/crypto/low_level.pyx'
  45. chunker_source = 'src/borg/chunker.pyx'
  46. hashindex_source = 'src/borg/hashindex.pyx'
  47. item_source = 'src/borg/item.pyx'
  48. checksums_source = 'src/borg/algorithms/checksums.pyx'
  49. platform_posix_source = 'src/borg/platform/posix.pyx'
  50. platform_linux_source = 'src/borg/platform/linux.pyx'
  51. platform_darwin_source = 'src/borg/platform/darwin.pyx'
  52. platform_freebsd_source = 'src/borg/platform/freebsd.pyx'
  53. cython_sources = [
  54. compress_source,
  55. crypto_ll_source,
  56. chunker_source,
  57. hashindex_source,
  58. item_source,
  59. checksums_source,
  60. platform_posix_source,
  61. platform_linux_source,
  62. platform_freebsd_source,
  63. platform_darwin_source,
  64. ]
  65. try:
  66. from Cython.Distutils import build_ext
  67. import Cython.Compiler.Main as cython_compiler
  68. class Sdist(sdist):
  69. def __init__(self, *args, **kwargs):
  70. for src in cython_sources:
  71. cython_compiler.compile(src, cython_compiler.default_options)
  72. super().__init__(*args, **kwargs)
  73. def make_distribution(self):
  74. self.filelist.extend([
  75. 'src/borg/compress.c',
  76. 'src/borg/crypto/low_level.c',
  77. 'src/borg/chunker.c', 'src/borg/_chunker.c',
  78. 'src/borg/hashindex.c', 'src/borg/_hashindex.c',
  79. 'src/borg/item.c',
  80. 'src/borg/algorithms/checksums.c',
  81. 'src/borg/algorithms/crc32_dispatch.c', 'src/borg/algorithms/crc32_clmul.c', 'src/borg/algorithms/crc32_slice_by_8.c',
  82. 'src/borg/algorithms/xxh64/xxhash.h', 'src/borg/algorithms/xxh64/xxhash.c',
  83. 'src/borg/platform/posix.c',
  84. 'src/borg/platform/linux.c',
  85. 'src/borg/platform/freebsd.c',
  86. 'src/borg/platform/darwin.c',
  87. ])
  88. super().make_distribution()
  89. except ImportError:
  90. class Sdist(sdist):
  91. def __init__(self, *args, **kwargs):
  92. raise Exception('Cython is required to run sdist')
  93. compress_source = compress_source.replace('.pyx', '.c')
  94. crypto_ll_source = crypto_ll_source.replace('.pyx', '.c')
  95. chunker_source = chunker_source.replace('.pyx', '.c')
  96. hashindex_source = hashindex_source.replace('.pyx', '.c')
  97. item_source = item_source.replace('.pyx', '.c')
  98. checksums_source = checksums_source.replace('.pyx', '.c')
  99. platform_posix_source = platform_posix_source.replace('.pyx', '.c')
  100. platform_linux_source = platform_linux_source.replace('.pyx', '.c')
  101. platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c')
  102. platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
  103. from distutils.command.build_ext import build_ext
  104. if not on_rtd and not all(os.path.exists(path) for path in [
  105. compress_source, crypto_ll_source, chunker_source, hashindex_source, item_source, checksums_source,
  106. platform_posix_source, platform_linux_source, platform_freebsd_source, platform_darwin_source]):
  107. raise ImportError('The GIT version of Borg needs Cython. Install Cython or use a released version.')
  108. def detect_openssl(prefixes):
  109. for prefix in prefixes:
  110. filename = os.path.join(prefix, 'include', 'openssl', 'evp.h')
  111. if os.path.exists(filename):
  112. with open(filename, 'r') as fd:
  113. if 'PKCS5_PBKDF2_HMAC(' in fd.read():
  114. return prefix
  115. def detect_lz4(prefixes):
  116. for prefix in prefixes:
  117. filename = os.path.join(prefix, 'include', 'lz4.h')
  118. if os.path.exists(filename):
  119. with open(filename, 'r') as fd:
  120. if 'LZ4_decompress_safe' in fd.read():
  121. return prefix
  122. def detect_libb2(prefixes):
  123. for prefix in prefixes:
  124. filename = os.path.join(prefix, 'include', 'blake2.h')
  125. if os.path.exists(filename):
  126. with open(filename, 'r') as fd:
  127. if 'blake2b_init' in fd.read():
  128. return prefix
  129. include_dirs = []
  130. library_dirs = []
  131. define_macros = []
  132. crypto_libraries = ['crypto']
  133. possible_openssl_prefixes = ['/usr', '/usr/local', '/usr/local/opt/openssl', '/usr/local/ssl', '/usr/local/openssl',
  134. '/usr/local/borg', '/opt/local', '/opt/pkg', ]
  135. if os.environ.get('BORG_OPENSSL_PREFIX'):
  136. possible_openssl_prefixes.insert(0, os.environ.get('BORG_OPENSSL_PREFIX'))
  137. ssl_prefix = detect_openssl(possible_openssl_prefixes)
  138. if not ssl_prefix:
  139. raise Exception('Unable to find OpenSSL >= 1.0 headers. (Looked here: {})'.format(', '.join(possible_openssl_prefixes)))
  140. include_dirs.append(os.path.join(ssl_prefix, 'include'))
  141. library_dirs.append(os.path.join(ssl_prefix, 'lib'))
  142. possible_lz4_prefixes = ['/usr', '/usr/local', '/usr/local/opt/lz4', '/usr/local/lz4',
  143. '/usr/local/borg', '/opt/local', '/opt/pkg', ]
  144. if os.environ.get('BORG_LZ4_PREFIX'):
  145. possible_lz4_prefixes.insert(0, os.environ.get('BORG_LZ4_PREFIX'))
  146. lz4_prefix = detect_lz4(possible_lz4_prefixes)
  147. if lz4_prefix:
  148. include_dirs.append(os.path.join(lz4_prefix, 'include'))
  149. library_dirs.append(os.path.join(lz4_prefix, 'lib'))
  150. elif not on_rtd:
  151. raise Exception('Unable to find LZ4 headers. (Looked here: {})'.format(', '.join(possible_lz4_prefixes)))
  152. possible_libb2_prefixes = ['/usr', '/usr/local', '/usr/local/opt/libb2', '/usr/local/libb2',
  153. '/usr/local/borg', '/opt/local', '/opt/pkg', ]
  154. if os.environ.get('BORG_LIBB2_PREFIX'):
  155. possible_libb2_prefixes.insert(0, os.environ.get('BORG_LIBB2_PREFIX'))
  156. libb2_prefix = detect_libb2(possible_libb2_prefixes)
  157. if libb2_prefix:
  158. print('Detected and preferring libb2 over bundled BLAKE2')
  159. include_dirs.append(os.path.join(libb2_prefix, 'include'))
  160. library_dirs.append(os.path.join(libb2_prefix, 'lib'))
  161. crypto_libraries.append('b2')
  162. define_macros.append(('BORG_USE_LIBB2', 'YES'))
  163. with open('README.rst', 'r') as fd:
  164. long_description = fd.read()
  165. # remove badges
  166. long_description = re.compile(r'^\.\. start-badges.*^\.\. end-badges', re.M | re.S).sub('', long_description)
  167. # remove |substitutions|
  168. long_description = re.compile(r'\|screencast\|').sub('', long_description)
  169. # remove unknown directives
  170. long_description = re.compile(r'^\.\. highlight:: \w+$', re.M).sub('', long_description)
  171. class build_usage(Command):
  172. description = "generate usage for each command"
  173. user_options = [
  174. ('output=', 'O', 'output directory'),
  175. ]
  176. def initialize_options(self):
  177. pass
  178. def finalize_options(self):
  179. pass
  180. def run(self):
  181. print('generating usage docs')
  182. import borg
  183. borg.doc_mode = 'build_man'
  184. if not os.path.exists('docs/usage'):
  185. os.mkdir('docs/usage')
  186. # allows us to build docs without the C modules fully loaded during help generation
  187. from borg.archiver import Archiver
  188. parser = Archiver(prog='borg').build_parser()
  189. self.generate_level("", parser, Archiver)
  190. def generate_level(self, prefix, parser, Archiver):
  191. is_subcommand = False
  192. choices = {}
  193. for action in parser._actions:
  194. if action.choices is not None and 'SubParsersAction' in str(action.__class__):
  195. is_subcommand = True
  196. for cmd, parser in action.choices.items():
  197. choices[prefix + cmd] = parser
  198. if prefix and not choices:
  199. return
  200. print('found commands: %s' % list(choices.keys()))
  201. for command, parser in sorted(choices.items()):
  202. if command.startswith('debug'):
  203. print('skipping', command)
  204. continue
  205. print('generating help for %s' % command)
  206. if self.generate_level(command + " ", parser, Archiver):
  207. continue
  208. with open('docs/usage/%s.rst.inc' % command.replace(" ", "_"), 'w') as doc:
  209. doc.write(".. IMPORTANT: this file is auto-generated from borg's built-in help, do not edit!\n\n")
  210. if command == 'help':
  211. for topic in Archiver.helptext:
  212. params = {"topic": topic,
  213. "underline": '~' * len('borg help ' + topic)}
  214. doc.write(".. _borg_{topic}:\n\n".format(**params))
  215. doc.write("borg help {topic}\n{underline}\n\n".format(**params))
  216. doc.write(Archiver.helptext[topic])
  217. else:
  218. params = {"command": command,
  219. "command_": command.replace(' ', '_'),
  220. "underline": '-' * len('borg ' + command)}
  221. doc.write(".. _borg_{command_}:\n\n".format(**params))
  222. doc.write("borg {command}\n{underline}\n.. code-block:: none\n\n borg [common options] {command}".format(**params))
  223. self.write_usage(parser, doc)
  224. epilog = parser.epilog
  225. parser.epilog = None
  226. self.write_options(parser, doc)
  227. doc.write("\n\nDescription\n~~~~~~~~~~~\n")
  228. doc.write(epilog)
  229. if 'create' in choices:
  230. common_options = [group for group in choices['create']._action_groups if group.title == 'Common options'][0]
  231. with open('docs/usage/common-options.rst.inc', 'w') as doc:
  232. self.write_options_group(common_options, doc, False)
  233. return is_subcommand
  234. def write_usage(self, parser, fp):
  235. if any(len(o.option_strings) for o in parser._actions):
  236. fp.write(' [options]')
  237. for option in parser._actions:
  238. if option.option_strings:
  239. continue
  240. fp.write(' ' + option.metavar)
  241. def write_options(self, parser, fp):
  242. for group in parser._action_groups:
  243. if group.title == 'Common options':
  244. fp.write('\n\n:ref:`common_options`\n')
  245. fp.write(' |')
  246. else:
  247. self.write_options_group(group, fp)
  248. def write_options_group(self, group, fp, with_title=True):
  249. def is_positional_group(group):
  250. return any(not o.option_strings for o in group._group_actions)
  251. def get_help(option):
  252. text = textwrap.dedent((option.help or '') % option.__dict__)
  253. return '\n'.join('| ' + line for line in text.splitlines())
  254. def shipout(text):
  255. fp.write(textwrap.indent('\n'.join(text), ' ' * 4))
  256. if not group._group_actions:
  257. return
  258. if with_title:
  259. fp.write('\n\n')
  260. fp.write(group.title + '\n')
  261. text = []
  262. if is_positional_group(group):
  263. for option in group._group_actions:
  264. text.append(option.metavar)
  265. text.append(textwrap.indent(option.help or '', ' ' * 4))
  266. shipout(text)
  267. return
  268. options = []
  269. for option in group._group_actions:
  270. if option.metavar:
  271. option_fmt = '``%%s %s``' % option.metavar
  272. else:
  273. option_fmt = '``%s``'
  274. option_str = ', '.join(option_fmt % s for s in option.option_strings)
  275. options.append((option_str, option))
  276. for option_str, option in options:
  277. help = textwrap.indent(get_help(option), ' ' * 4)
  278. text.append(option_str)
  279. text.append(help)
  280. shipout(text)
  281. class build_man(Command):
  282. description = 'build man pages'
  283. user_options = []
  284. see_also = {
  285. 'create': ('delete', 'prune', 'check', 'patterns', 'placeholders', 'compression'),
  286. 'recreate': ('patterns', 'placeholders', 'compression'),
  287. 'list': ('info', 'diff', 'prune', 'patterns'),
  288. 'info': ('list', 'diff'),
  289. 'init': ('create', 'delete', 'check', 'list', 'key-import', 'key-export', 'key-change-passphrase'),
  290. 'key-import': ('key-export', ),
  291. 'key-export': ('key-import', ),
  292. 'mount': ('umount', 'extract'), # Would be cooler if these two were on the same page
  293. 'umount': ('mount', ),
  294. 'extract': ('mount', ),
  295. }
  296. rst_prelude = textwrap.dedent("""
  297. .. role:: ref(title)
  298. .. |project_name| replace:: Borg
  299. """)
  300. usage_group = {
  301. 'break-lock': 'lock',
  302. 'with-lock': 'lock',
  303. 'change-passphrase': 'key',
  304. 'key_change-passphrase': 'key',
  305. 'key_export': 'key',
  306. 'key_import': 'key',
  307. 'key_migrate-to-repokey': 'key',
  308. 'export-tar': 'tar',
  309. 'benchmark_crud': 'benchmark',
  310. 'umount': 'mount',
  311. }
  312. def initialize_options(self):
  313. pass
  314. def finalize_options(self):
  315. pass
  316. def run(self):
  317. print('building man pages (in docs/man)', file=sys.stderr)
  318. import borg
  319. borg.doc_mode = 'build_man'
  320. os.makedirs('docs/man', exist_ok=True)
  321. # allows us to build docs without the C modules fully loaded during help generation
  322. from borg.archiver import Archiver
  323. parser = Archiver(prog='borg').build_parser()
  324. self.generate_level('', parser, Archiver)
  325. self.build_topic_pages(Archiver)
  326. self.build_intro_page()
  327. def generate_level(self, prefix, parser, Archiver):
  328. is_subcommand = False
  329. choices = {}
  330. for action in parser._actions:
  331. if action.choices is not None and 'SubParsersAction' in str(action.__class__):
  332. is_subcommand = True
  333. for cmd, parser in action.choices.items():
  334. choices[prefix + cmd] = parser
  335. if prefix and not choices:
  336. return
  337. for command, parser in sorted(choices.items()):
  338. if command.startswith('debug') or command == 'help':
  339. continue
  340. man_title = 'borg-' + command.replace(' ', '-')
  341. print('building man page', man_title + '(1)', file=sys.stderr)
  342. is_intermediary = self.generate_level(command + ' ', parser, Archiver)
  343. doc, write = self.new_doc()
  344. self.write_man_header(write, man_title, parser.description)
  345. self.write_heading(write, 'SYNOPSIS')
  346. if is_intermediary:
  347. subparsers = [action for action in parser._actions if 'SubParsersAction' in str(action.__class__)][0]
  348. for subcommand in subparsers.choices:
  349. write('| borg', '[common options]', command, subcommand, '...')
  350. self.see_also.setdefault(command, []).append('%s-%s' % (command, subcommand))
  351. else:
  352. write('borg', '[common options]', command, end='')
  353. self.write_usage(write, parser)
  354. write('\n')
  355. description, _, notes = parser.epilog.partition('\n.. man NOTES')
  356. if description:
  357. self.write_heading(write, 'DESCRIPTION')
  358. write(description)
  359. if not is_intermediary:
  360. self.write_heading(write, 'OPTIONS')
  361. write('See `borg-common(1)` for common options of Borg commands.')
  362. write()
  363. self.write_options(write, parser)
  364. self.write_examples(write, command)
  365. if notes:
  366. self.write_heading(write, 'NOTES')
  367. write(notes)
  368. self.write_see_also(write, man_title)
  369. self.gen_man_page(man_title, doc.getvalue())
  370. # Generate the borg-common(1) man page with the common options.
  371. if 'create' in choices:
  372. doc, write = self.new_doc()
  373. man_title = 'borg-common'
  374. self.write_man_header(write, man_title, 'Common options of Borg commands')
  375. common_options = [group for group in choices['create']._action_groups if group.title == 'Common options'][0]
  376. self.write_heading(write, 'SYNOPSIS')
  377. self.write_options_group(write, common_options)
  378. self.write_see_also(write, man_title)
  379. self.gen_man_page(man_title, doc.getvalue())
  380. return is_subcommand
  381. def build_topic_pages(self, Archiver):
  382. for topic, text in Archiver.helptext.items():
  383. doc, write = self.new_doc()
  384. man_title = 'borg-' + topic
  385. print('building man page', man_title + '(1)', file=sys.stderr)
  386. self.write_man_header(write, man_title, 'Details regarding ' + topic)
  387. self.write_heading(write, 'DESCRIPTION')
  388. write(text)
  389. self.gen_man_page(man_title, doc.getvalue())
  390. def build_intro_page(self):
  391. print('building man page borg(1)', file=sys.stderr)
  392. with open('docs/man_intro.rst') as fd:
  393. man_intro = fd.read()
  394. self.gen_man_page('borg', self.rst_prelude + man_intro)
  395. def new_doc(self):
  396. doc = io.StringIO(self.rst_prelude)
  397. doc.read()
  398. write = self.printer(doc)
  399. return doc, write
  400. def printer(self, fd):
  401. def write(*args, **kwargs):
  402. print(*args, file=fd, **kwargs)
  403. return write
  404. def write_heading(self, write, header, char='-', double_sided=False):
  405. write()
  406. if double_sided:
  407. write(char * len(header))
  408. write(header)
  409. write(char * len(header))
  410. write()
  411. def write_man_header(self, write, title, description):
  412. self.write_heading(write, title, '=', double_sided=True)
  413. self.write_heading(write, description, double_sided=True)
  414. # man page metadata
  415. write(':Author: The Borg Collective')
  416. write(':Date:', datetime.utcnow().date().isoformat())
  417. write(':Manual section: 1')
  418. write(':Manual group: borg backup tool')
  419. write()
  420. def write_examples(self, write, command):
  421. command = command.replace(' ', '_')
  422. with open('docs/usage/%s.rst' % self.usage_group.get(command, command)) as fd:
  423. usage = fd.read()
  424. usage_include = '.. include:: %s.rst.inc' % command
  425. begin = usage.find(usage_include)
  426. end = usage.find('.. include', begin + 1)
  427. # If a command has a dedicated anchor, it will occur before the command's include.
  428. if 0 < usage.find('.. _', begin + 1) < end:
  429. end = usage.find('.. _', begin + 1)
  430. examples = usage[begin:end]
  431. examples = examples.replace(usage_include, '')
  432. examples = examples.replace('Examples\n~~~~~~~~', '')
  433. examples = examples.replace('Miscellaneous Help\n------------------', '')
  434. examples = re.sub('^(~+)$', lambda matches: '+' * len(matches.group(0)), examples, flags=re.MULTILINE)
  435. examples = examples.strip()
  436. if examples:
  437. self.write_heading(write, 'EXAMPLES', '-')
  438. write(examples)
  439. def write_see_also(self, write, man_title):
  440. see_also = self.see_also.get(man_title.replace('borg-', ''), ())
  441. see_also = ['`borg-%s(1)`' % s for s in see_also]
  442. see_also.insert(0, '`borg-common(1)`')
  443. self.write_heading(write, 'SEE ALSO')
  444. write(', '.join(see_also))
  445. def gen_man_page(self, name, rst):
  446. from docutils.writers import manpage
  447. from docutils.core import publish_string
  448. # We give the source_path so that docutils can find relative includes
  449. # as-if the document where located in the docs/ directory.
  450. man_page = publish_string(source=rst, source_path='docs/virtmanpage.rst', writer=manpage.Writer())
  451. with open('docs/man/%s.1' % name, 'wb') as fd:
  452. fd.write(man_page)
  453. def write_usage(self, write, parser):
  454. if any(len(o.option_strings) for o in parser._actions):
  455. write(' <options> ', end='')
  456. for option in parser._actions:
  457. if option.option_strings:
  458. continue
  459. write(option.metavar, end=' ')
  460. def write_options(self, write, parser):
  461. for group in parser._action_groups:
  462. if group.title == 'Common options' or not group._group_actions:
  463. continue
  464. title = 'arguments' if group.title == 'positional arguments' else group.title
  465. self.write_heading(write, title, '+')
  466. self.write_options_group(write, group)
  467. def write_options_group(self, write, group):
  468. def is_positional_group(group):
  469. return any(not o.option_strings for o in group._group_actions)
  470. if is_positional_group(group):
  471. for option in group._group_actions:
  472. write(option.metavar)
  473. write(textwrap.indent(option.help or '', ' ' * 4))
  474. return
  475. opts = OrderedDict()
  476. for option in group._group_actions:
  477. if option.metavar:
  478. option_fmt = '%s ' + option.metavar
  479. else:
  480. option_fmt = '%s'
  481. option_str = ', '.join(option_fmt % s for s in option.option_strings)
  482. option_desc = textwrap.dedent((option.help or '') % option.__dict__)
  483. opts[option_str] = textwrap.indent(option_desc, ' ' * 4)
  484. padding = len(max(opts)) + 1
  485. for option, desc in opts.items():
  486. write(option.ljust(padding), desc)
  487. def rm(file):
  488. try:
  489. os.unlink(file)
  490. print('rm', file)
  491. except FileNotFoundError:
  492. pass
  493. class Clean(clean):
  494. def run(self):
  495. super().run()
  496. for source in cython_sources:
  497. genc = source.replace('.pyx', '.c')
  498. rm(genc)
  499. compiled_glob = source.replace('.pyx', '.cpython*')
  500. for compiled in sorted(glob(compiled_glob)):
  501. rm(compiled)
  502. cmdclass = {
  503. 'build_ext': build_ext,
  504. 'build_usage': build_usage,
  505. 'build_man': build_man,
  506. 'sdist': Sdist,
  507. 'clean': Clean,
  508. }
  509. ext_modules = []
  510. if not on_rtd:
  511. ext_modules += [
  512. Extension('borg.compress', [compress_source], libraries=['lz4'], include_dirs=include_dirs, library_dirs=library_dirs, define_macros=define_macros),
  513. Extension('borg.crypto.low_level', [crypto_ll_source], libraries=crypto_libraries, include_dirs=include_dirs, library_dirs=library_dirs, define_macros=define_macros),
  514. Extension('borg.hashindex', [hashindex_source]),
  515. Extension('borg.item', [item_source]),
  516. Extension('borg.chunker', [chunker_source]),
  517. Extension('borg.algorithms.checksums', [checksums_source]),
  518. ]
  519. if not sys.platform.startswith(('win32', )):
  520. ext_modules.append(Extension('borg.platform.posix', [platform_posix_source]))
  521. if sys.platform == 'linux':
  522. ext_modules.append(Extension('borg.platform.linux', [platform_linux_source], libraries=['acl']))
  523. elif sys.platform.startswith('freebsd'):
  524. ext_modules.append(Extension('borg.platform.freebsd', [platform_freebsd_source]))
  525. elif sys.platform == 'darwin':
  526. ext_modules.append(Extension('borg.platform.darwin', [platform_darwin_source]))
  527. setup(
  528. name='borgbackup',
  529. use_scm_version={
  530. 'write_to': 'src/borg/_version.py',
  531. },
  532. author='The Borg Collective (see AUTHORS file)',
  533. author_email='borgbackup@python.org',
  534. url='https://borgbackup.readthedocs.io/',
  535. description='Deduplicated, encrypted, authenticated and compressed backups',
  536. long_description=long_description,
  537. license='BSD',
  538. platforms=['Linux', 'MacOS X', 'FreeBSD', 'OpenBSD', 'NetBSD', ],
  539. classifiers=[
  540. 'Development Status :: 4 - Beta',
  541. 'Environment :: Console',
  542. 'Intended Audience :: System Administrators',
  543. 'License :: OSI Approved :: BSD License',
  544. 'Operating System :: POSIX :: BSD :: FreeBSD',
  545. 'Operating System :: POSIX :: BSD :: OpenBSD',
  546. 'Operating System :: POSIX :: BSD :: NetBSD',
  547. 'Operating System :: MacOS :: MacOS X',
  548. 'Operating System :: POSIX :: Linux',
  549. 'Programming Language :: Python',
  550. 'Programming Language :: Python :: 3',
  551. 'Programming Language :: Python :: 3.4',
  552. 'Programming Language :: Python :: 3.5',
  553. 'Programming Language :: Python :: 3.6',
  554. 'Topic :: Security :: Cryptography',
  555. 'Topic :: System :: Archiving :: Backup',
  556. ],
  557. packages=find_packages('src'),
  558. package_dir={'': 'src'},
  559. include_package_data=True,
  560. zip_safe=False,
  561. entry_points={
  562. 'console_scripts': [
  563. 'borg = borg.archiver:main',
  564. 'borgfs = borg.archiver:main',
  565. ]
  566. },
  567. package_data={
  568. 'borg': ['paperkey.html']
  569. },
  570. cmdclass=cmdclass,
  571. ext_modules=ext_modules,
  572. setup_requires=['setuptools_scm>=1.7'],
  573. install_requires=install_requires,
  574. extras_require=extras_require,
  575. )