setup.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # -*- encoding: utf-8 *-*
  2. import os
  3. import sys
  4. from glob import glob
  5. import versioneer
  6. versioneer.versionfile_source = 'attic/_version.py'
  7. versioneer.versionfile_build = 'attic/_version.py'
  8. versioneer.tag_prefix = ''
  9. versioneer.parentdir_prefix = 'Attic-' # dirname like 'myproject-1.2.0'
  10. platform = os.uname()[0]
  11. min_python = (3, 2)
  12. if sys.version_info < min_python:
  13. print("Attic requires Python %d.%d or later" % min_python)
  14. sys.exit(1)
  15. try:
  16. from setuptools import setup, Extension
  17. except ImportError:
  18. from distutils.core import setup, Extension
  19. crypto_source = 'attic/crypto.pyx'
  20. chunker_source = 'attic/chunker.pyx'
  21. hashindex_source = 'attic/hashindex.pyx'
  22. platform_linux_source = 'attic/platform_linux.pyx'
  23. platform_darwin_source = 'attic/platform_darwin.pyx'
  24. platform_freebsd_source = 'attic/platform_freebsd.pyx'
  25. try:
  26. from Cython.Distutils import build_ext
  27. import Cython.Compiler.Main as cython_compiler
  28. class Sdist(versioneer.cmd_sdist):
  29. def __init__(self, *args, **kwargs):
  30. for src in glob('attic/*.pyx'):
  31. cython_compiler.compile(glob('attic/*.pyx'),
  32. cython_compiler.default_options)
  33. versioneer.cmd_sdist.__init__(self, *args, **kwargs)
  34. def make_distribution(self):
  35. 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'])
  36. super(Sdist, self).make_distribution()
  37. except ImportError:
  38. class Sdist(versioneer.cmd_sdist):
  39. def __init__(self, *args, **kwargs):
  40. raise Exception('Cython is required to run sdist')
  41. crypto_source = crypto_source.replace('.pyx', '.c')
  42. chunker_source = chunker_source.replace('.pyx', '.c')
  43. hashindex_source = hashindex_source.replace('.pyx', '.c')
  44. platform_linux_source = platform_linux_source.replace('.pyx', '.c')
  45. platform_freebsd_source = platform_freebsd_source.replace('.pyx', '.c')
  46. platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
  47. from distutils.command.build_ext import build_ext
  48. if not all(os.path.exists(path) for path in [crypto_source, chunker_source, hashindex_source, platform_linux_source, platform_freebsd_source]):
  49. raise ImportError('The GIT version of Attic needs Cython. Install Cython or use a released version')
  50. def detect_openssl(prefixes):
  51. for prefix in prefixes:
  52. filename = os.path.join(prefix, 'include', 'openssl', 'evp.h')
  53. if os.path.exists(filename):
  54. with open(filename, 'r') as fd:
  55. if 'PKCS5_PBKDF2_HMAC(' in fd.read():
  56. return prefix
  57. possible_openssl_prefixes = ['/usr', '/usr/local', '/usr/local/opt/openssl', '/usr/local/ssl', '/usr/local/openssl', '/usr/local/attic']
  58. if os.environ.get('ATTIC_OPENSSL_PREFIX'):
  59. possible_openssl_prefixes.insert(0, os.environ.get('ATTIC_OPENSSL_PREFIX'))
  60. ssl_prefix = detect_openssl(possible_openssl_prefixes)
  61. if not ssl_prefix:
  62. raise Exception('Unable to find OpenSSL >= 1.0 headers. (Looked here: {})'.format(', '.join(possible_openssl_prefixes)))
  63. include_dirs = [os.path.join(ssl_prefix, 'include')]
  64. library_dirs = [os.path.join(ssl_prefix, 'lib')]
  65. with open('README.rst', 'r') as fd:
  66. long_description = fd.read()
  67. cmdclass = versioneer.get_cmdclass()
  68. cmdclass.update({'build_ext': build_ext, 'sdist': Sdist})
  69. ext_modules = [
  70. Extension('attic.crypto', [crypto_source], libraries=['crypto'], include_dirs=include_dirs, library_dirs=library_dirs),
  71. Extension('attic.chunker', [chunker_source]),
  72. Extension('attic.hashindex', [hashindex_source])
  73. ]
  74. if platform == 'Linux':
  75. ext_modules.append(Extension('attic.platform_linux', [platform_linux_source], libraries=['acl']))
  76. elif platform == 'FreeBSD':
  77. ext_modules.append(Extension('attic.platform_freebsd', [platform_freebsd_source]))
  78. elif platform == 'Darwin':
  79. ext_modules.append(Extension('attic.platform_darwin', [platform_darwin_source]))
  80. setup(
  81. name='Attic',
  82. version=versioneer.get_version(),
  83. author='Jonas Borgstrom',
  84. author_email='jonas@borgstrom.se',
  85. url='https://attic-backup.org/',
  86. description='Deduplicated backups',
  87. long_description=long_description,
  88. license='BSD',
  89. platforms=['Linux', 'MacOS X'],
  90. classifiers=[
  91. 'Development Status :: 4 - Beta',
  92. 'Environment :: Console',
  93. 'Intended Audience :: System Administrators',
  94. 'License :: OSI Approved :: BSD License',
  95. 'Operating System :: POSIX :: BSD :: FreeBSD',
  96. 'Operating System :: MacOS :: MacOS X',
  97. 'Operating System :: POSIX :: Linux',
  98. 'Programming Language :: Python',
  99. 'Topic :: Security :: Cryptography',
  100. 'Topic :: System :: Archiving :: Backup',
  101. ],
  102. packages=['attic', 'attic.testsuite'],
  103. scripts=['scripts/attic'],
  104. cmdclass=cmdclass,
  105. ext_modules=ext_modules,
  106. install_requires=['msgpack-python']
  107. )