setup.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. import os
  4. from setuptools import setup
  5. import compiler
  6. with open('requirements.txt') as requirements:
  7. requires = [line.strip() for line in requirements if line.strip()]
  8. path = os.path.dirname(__file__)
  9. desc_fd = os.path.join(path, 'README.rst')
  10. hist_fd = os.path.join(path, 'HISTORY.rst')
  11. long_desc = ''
  12. short_desc = 'A Kerberos authentication handler for python-requests'
  13. if os.path.isfile(desc_fd):
  14. long_desc = open(desc_fd).read()
  15. if os.path.isfile(hist_fd):
  16. long_desc = '\n\n'.join([long_desc, open(hist_fd).read()])
  17. # It seems like per the requests module, we'd like to get the version
  18. # from __init__.py however, __init__.py will import the kerberos
  19. # module. The kerberos module may not be installed - and when it's
  20. # not, it's pulled in by the requirements.txt. When it's being
  21. # installed, however, this setup.py is evaluated before the
  22. # kerberos.so module is built and installed, and this bombs.
  23. #
  24. # To fix this, we can use the compiler module to parse __init__.py,
  25. # and as long as __version__ is defined as a constant so that we
  26. # don't have to evaluate it to get the value, we can do some dubious
  27. # groping arond the AST and get the version from that
  28. parsed = compiler.parseFile('requests_kerberos/__init__.py')
  29. for n in parsed.getChildNodes()[0]:
  30. if 'nodes' in dir(n):
  31. if n.nodes[0].name == '__version__':
  32. my_version = n.expr.value
  33. setup(
  34. name='requests-kerberos',
  35. description=short_desc,
  36. long_description=long_desc,
  37. url='https://github.com/requests/requests-kerberos',
  38. packages=['requests_kerberos'],
  39. package_data={'': ['LICENSE', 'AUTHORS']},
  40. include_package_data=True,
  41. version = my_version,
  42. install_requires=requires,
  43. )