setup.py 4.0 KB

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