setup.py 4.7 KB

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