setup.py 4.4 KB

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