setup.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. min_python = (3, 2)
  11. if sys.version_info < min_python:
  12. print("Attic requires Python %d.%d or later" % min_python)
  13. sys.exit(1)
  14. try:
  15. from setuptools import setup, Extension
  16. except ImportError:
  17. from distutils.core import setup, Extension
  18. crypto_source = 'attic/crypto.pyx'
  19. chunker_source = 'attic/chunker.pyx'
  20. hashindex_source = 'attic/hashindex.pyx'
  21. platform_linux_source = 'attic/platform_linux.pyx'
  22. platform_darwin_source = 'attic/platform_darwin.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', 'attic/platform_darwin.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. platform_darwin_source = platform_darwin_source.replace('.pyx', '.c')
  46. from distutils.command.build_ext import build_ext
  47. if not all(os.path.exists(path) for path in [crypto_source, chunker_source, hashindex_source, platform_linux_source, platform_freebsd_source]):
  48. raise ImportError('The GIT version of Attic needs Cython. Install Cython or use a released version')
  49. def detect_openssl(prefixes):
  50. for prefix in prefixes:
  51. filename = os.path.join(prefix, 'include', 'openssl', 'evp.h')
  52. if os.path.exists(filename):
  53. with open(filename, 'r') as fd:
  54. if 'PKCS5_PBKDF2_HMAC(' in fd.read():
  55. return prefix
  56. possible_openssl_prefixes = ['/usr', '/usr/local', '/usr/local/opt/openssl', '/usr/local/ssl', '/usr/local/openssl', '/usr/local/attic', '/opt/local']
  57. if os.environ.get('ATTIC_OPENSSL_PREFIX'):
  58. possible_openssl_prefixes.insert(0, os.environ.get('ATTIC_OPENSSL_PREFIX'))
  59. ssl_prefix = detect_openssl(possible_openssl_prefixes)
  60. if not ssl_prefix:
  61. raise Exception('Unable to find OpenSSL >= 1.0 headers. (Looked here: {})'.format(', '.join(possible_openssl_prefixes)))
  62. include_dirs = [os.path.join(ssl_prefix, 'include')]
  63. library_dirs = [os.path.join(ssl_prefix, 'lib')]
  64. with open('README.rst', 'r') as fd:
  65. long_description = fd.read()
  66. cmdclass = versioneer.get_cmdclass()
  67. cmdclass.update({'build_ext': build_ext, 'sdist': Sdist})
  68. ext_modules = [
  69. Extension('attic.crypto', [crypto_source], libraries=['crypto'], include_dirs=include_dirs, library_dirs=library_dirs),
  70. Extension('attic.chunker', [chunker_source]),
  71. Extension('attic.hashindex', [hashindex_source])
  72. ]
  73. if sys.platform.startswith('linux'):
  74. ext_modules.append(Extension('attic.platform_linux', [platform_linux_source], libraries=['acl']))
  75. elif sys.platform.startswith('freebsd'):
  76. ext_modules.append(Extension('attic.platform_freebsd', [platform_freebsd_source]))
  77. elif sys.platform == 'darwin':
  78. ext_modules.append(Extension('attic.platform_darwin', [platform_darwin_source]))
  79. setup(
  80. name='Attic',
  81. version=versioneer.get_version(),
  82. author='Jonas Borgstrom',
  83. author_email='jonas@borgstrom.se',
  84. url='https://attic-backup.org/',
  85. description='Deduplicated backups',
  86. long_description=long_description,
  87. license='BSD',
  88. platforms=['Linux', 'MacOS X'],
  89. classifiers=[
  90. 'Development Status :: 4 - Beta',
  91. 'Environment :: Console',
  92. 'Intended Audience :: System Administrators',
  93. 'License :: OSI Approved :: BSD License',
  94. 'Operating System :: POSIX :: BSD :: FreeBSD',
  95. 'Operating System :: MacOS :: MacOS X',
  96. 'Operating System :: POSIX :: Linux',
  97. 'Programming Language :: Python',
  98. 'Topic :: Security :: Cryptography',
  99. 'Topic :: System :: Archiving :: Backup',
  100. ],
  101. packages=['attic', 'attic.testsuite'],
  102. scripts=['scripts/attic'],
  103. cmdclass=cmdclass,
  104. ext_modules=ext_modules,
  105. install_requires=['msgpack-python']
  106. )