setup.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. """
  2. setup.py - Setup package with the help Python's DistUtils
  3. See http://www.python-ldap.org/ for details.
  4. $Id: setup.py,v 1.65 2009/10/21 17:32:11 stroeder Exp $
  5. """
  6. has_setuptools = False
  7. try:
  8. from setuptools import setup, Extension
  9. has_setuptools = True
  10. except ImportError:
  11. from distutils.core import setup, Extension
  12. from ConfigParser import ConfigParser
  13. import sys,os,string,time
  14. ##################################################################
  15. # Weird Hack to grab release version of python-ldap from local dir
  16. ##################################################################
  17. exec_startdir = os.path.dirname(os.path.abspath(sys.argv[0]))
  18. package_init_file_name = reduce(os.path.join,[exec_startdir,'Lib','ldap','__init__.py'])
  19. f = open(package_init_file_name,'r')
  20. s = f.readline()
  21. while s:
  22. s = string.strip(s)
  23. if s[0:11]=='__version__':
  24. version = eval(string.split(s,'=')[1])
  25. break
  26. s = f.readline()
  27. f.close()
  28. #-- A class describing the features and requirements of OpenLDAP 2.0
  29. class OpenLDAP2:
  30. library_dirs = []
  31. include_dirs = []
  32. extra_compile_args = []
  33. extra_link_args = []
  34. extra_objects = []
  35. libs = ['ldap', 'lber']
  36. defines = [ ]
  37. extra_files = []
  38. LDAP_CLASS = OpenLDAP2
  39. #-- Read the [_ldap] section of setup.cfg
  40. cfg = ConfigParser()
  41. cfg.read('setup.cfg')
  42. if cfg.has_section('_ldap'):
  43. for name in dir(LDAP_CLASS):
  44. if cfg.has_option('_ldap', name):
  45. print name + ': ' + cfg.get('_ldap', name)
  46. setattr(LDAP_CLASS, name, string.split(cfg.get('_ldap', name)))
  47. for i in range(len(LDAP_CLASS.defines)):
  48. LDAP_CLASS.defines[i]=((LDAP_CLASS.defines[i],None))
  49. for i in range(len(LDAP_CLASS.extra_files)):
  50. destdir, origfiles = string.split(LDAP_CLASS.extra_files[i], ':')
  51. origfileslist = string.split(origfiles, ',')
  52. LDAP_CLASS.extra_files[i]=(destdir, origfileslist)
  53. #-- Let distutils/setuptools do the rest
  54. name = 'python-ldap'
  55. # Python 2.3.6+ and setuptools are needed to build eggs, so
  56. # let's handle setuptools' additional keyword arguments to
  57. # setup() in a fashion that doesn't break compatibility to
  58. # distutils. This still allows 'normal' builds where either
  59. # Python > 2.3.5 or setuptools (or both ;o) are not available.
  60. kwargs = dict()
  61. if has_setuptools:
  62. kwargs = dict(
  63. include_package_data = True,
  64. install_requires = ['setuptools'],
  65. zip_safe = False)
  66. setup(
  67. #-- Package description
  68. name = name,
  69. version = version,
  70. description = 'Various LDAP-related Python modules',
  71. author = 'David Leonard, Michael Stroeder, et al.',
  72. author_email = 'python-ldap-dev@lists.sourceforge.net',
  73. url = 'http://www.python-ldap.org/',
  74. #-- C extension modules
  75. ext_modules = [
  76. Extension(
  77. '_ldap',
  78. [
  79. 'Modules/LDAPObject.c',
  80. 'Modules/ldapcontrol.c',
  81. 'Modules/common.c',
  82. 'Modules/constants.c',
  83. 'Modules/errors.c',
  84. 'Modules/functions.c',
  85. 'Modules/schema.c',
  86. 'Modules/ldapmodule.c',
  87. 'Modules/message.c',
  88. 'Modules/version.c',
  89. 'Modules/options.c',
  90. 'Modules/berval.c',
  91. ],
  92. libraries = LDAP_CLASS.libs,
  93. include_dirs = ['Modules'] + LDAP_CLASS.include_dirs,
  94. library_dirs = LDAP_CLASS.library_dirs,
  95. extra_compile_args = LDAP_CLASS.extra_compile_args,
  96. extra_link_args = LDAP_CLASS.extra_link_args,
  97. extra_objects = LDAP_CLASS.extra_objects,
  98. runtime_library_dirs = (not sys.platform.startswith("win"))*LDAP_CLASS.library_dirs,
  99. define_macros = LDAP_CLASS.defines + \
  100. ('ldap_r' in LDAP_CLASS.libs or 'oldap_r' in LDAP_CLASS.libs)*[('HAVE_LIBLDAP_R',None)] + \
  101. ('sasl' in LDAP_CLASS.libs or 'sasl2' in LDAP_CLASS.libs or 'libsasl' in LDAP_CLASS.libs)*[('HAVE_SASL',None)] + \
  102. ('ssl' in LDAP_CLASS.libs and 'crypto' in LDAP_CLASS.libs)*[('HAVE_TLS',None)] + \
  103. [('LDAPMODULE_VERSION', version)]
  104. ),
  105. ],
  106. #-- Python "stand alone" modules
  107. py_modules = [
  108. 'ldapurl',
  109. 'ldif',
  110. 'dsml',
  111. 'ldap',
  112. 'ldap.async',
  113. 'ldap.controls',
  114. 'ldap.cidict',
  115. 'ldap.dn',
  116. 'ldap.filter',
  117. 'ldap.functions',
  118. 'ldap.ldapobject',
  119. 'ldap.modlist',
  120. 'ldap.resiter',
  121. 'ldap.sasl',
  122. 'ldap.schema',
  123. 'ldap.schema.models',
  124. 'ldap.schema.subentry',
  125. 'ldap.schema.tokenizer',
  126. ],
  127. package_dir = {'': 'Lib',},
  128. data_files = LDAP_CLASS.extra_files,
  129. **kwargs
  130. )