|
4 | 4 | See https://www.python-ldap.org/ for details.
|
5 | 5 | """
|
6 | 6 |
|
7 |
| -has_setuptools = False |
| 7 | +import sys |
| 8 | +import os |
| 9 | +import pprint |
| 10 | +from ConfigParser import ConfigParser |
| 11 | + |
| 12 | +# Python 2.3.6+ and setuptools are needed to build eggs, so |
| 13 | +# let's handle setuptools' additional keyword arguments to |
| 14 | +# setup() in a fashion that doesn't break compatibility to |
| 15 | +# distutils. This still allows 'normal' builds where either |
| 16 | +# Python > 2.3.5 or setuptools (or both ;o) are not available. |
8 | 17 | try:
|
9 |
| - from setuptools import setup, Extension |
10 |
| - has_setuptools = True |
| 18 | + from setuptools import setup, Extension |
11 | 19 | except ImportError:
|
12 |
| - from distutils.core import setup, Extension |
13 |
| - |
14 |
| -from ConfigParser import ConfigParser |
15 |
| -import sys,os,time |
| 20 | + from distutils.core import setup, Extension |
| 21 | + setup_kwargs = dict() |
| 22 | +else: |
| 23 | + setup_kwargs = dict( |
| 24 | + include_package_data=True, |
| 25 | + install_requires=['setuptools'], |
| 26 | + zip_safe=False |
| 27 | + ) |
16 | 28 |
|
17 | 29 | sys.path.insert(0, os.path.join(os.getcwd(), 'Lib/ldap'))
|
18 | 30 | import pkginfo
|
19 | 31 |
|
20 |
| -#-- A class describing the features and requirements of OpenLDAP 2.0 |
21 |
| -class OpenLDAP2: |
22 |
| - library_dirs = [] |
23 |
| - include_dirs = [] |
24 |
| - extra_compile_args = [] |
25 |
| - extra_link_args = [] |
26 |
| - extra_objects = [] |
27 |
| - libs = ['ldap', 'lber'] |
28 |
| - defines = [ ] |
29 |
| - extra_files = [] |
30 | 32 |
|
31 |
| -LDAP_CLASS = OpenLDAP2 |
| 33 | +class OpenLDAP2BuildConfig: |
| 34 | + """ |
| 35 | + class describing the features and requirements of OpenLDAP 2.x |
| 36 | + """ |
| 37 | + |
| 38 | + def __init__(self, meta_defines): |
| 39 | + self.library_dirs = [] |
| 40 | + self.include_dirs = [] |
| 41 | + self.extra_compile_args = [] |
| 42 | + self.extra_link_args = [] |
| 43 | + self.extra_objects = [] |
| 44 | + self.libs = ['ldap', 'lber'] |
| 45 | + self.defines = [] |
| 46 | + self.extra_files = [] |
| 47 | + #-- Read the [_ldap] section of setup.cfg |
| 48 | + cfg = ConfigParser() |
| 49 | + cfg.read('setup.cfg') |
| 50 | + _ldap_cfg = dict(cfg.items('_ldap')) |
| 51 | + for name, value in _ldap_cfg.items(): |
| 52 | + _ldap_cfg[name] = filter(None, value.split(' ')) |
| 53 | + # split values of extra_files |
| 54 | + if 'extra_files' in _ldap_cfg: |
| 55 | + for i in range(len(_ldap_cfg['extra_files'])): |
| 56 | + destdir, origfiles = self.extra_files[i].split(':') |
| 57 | + origfileslist = origfiles.split(',') |
| 58 | + _ldap_cfg['extra_files'][i] = (destdir, origfileslist) |
| 59 | + #pprint.pprint(_ldap_cfg) |
| 60 | + for name, val in _ldap_cfg.items(): |
| 61 | + setattr(self, name, val) |
| 62 | + if 'ldap_r' in self.libs or 'oldap_r' in self.libs: |
| 63 | + self.defines.append('HAVE_LIBLDAP_R') |
| 64 | + if 'sasl' in self.libs or 'sasl2' in self.libs or 'libsasl' in self.libs: |
| 65 | + self.defines.append('HAVE_SASL') |
| 66 | + if 'ssl' in self.libs and 'crypto' in self.libs: |
| 67 | + self.defines.append('HAVE_TLS') |
| 68 | + self.define_macros = [ |
| 69 | + (defm,) |
| 70 | + for defm in set(self.defines) |
| 71 | + ] |
| 72 | + self.define_macros.extend(meta_defines) |
| 73 | + self.include_dirs.insert(0, 'Modules') |
| 74 | + if sys.platform.startswith("win"): |
| 75 | + self.library_dirs = [] |
32 | 76 |
|
33 |
| -#-- Read the [_ldap] section of setup.cfg |
34 |
| -cfg = ConfigParser() |
35 |
| -cfg.read('setup.cfg') |
36 |
| -if cfg.has_section('_ldap'): |
37 |
| - for name in dir(LDAP_CLASS): |
38 |
| - if cfg.has_option('_ldap', name): |
39 |
| - setattr(LDAP_CLASS, name, cfg.get('_ldap', name).split()) |
40 | 77 |
|
41 |
| -for i in range(len(LDAP_CLASS.defines)): |
42 |
| - LDAP_CLASS.defines[i]=((LDAP_CLASS.defines[i],None)) |
| 78 | +LDAP_CLASS = OpenLDAP2BuildConfig( |
| 79 | + [ |
| 80 | + ('LDAPMODULE_VERSION', pkginfo.__version__), |
| 81 | + ('LDAPMODULE_AUTHOR', pkginfo.__author__), |
| 82 | + ('LDAPMODULE_LICENSE', pkginfo.__license__), |
| 83 | + ], |
| 84 | +) |
43 | 85 |
|
44 |
| -for i in range(len(LDAP_CLASS.extra_files)): |
45 |
| - destdir, origfiles = LDAP_CLASS.extra_files[i].split(':') |
46 |
| - origfileslist = origfiles.split(',') |
47 |
| - LDAP_CLASS.extra_files[i]=(destdir, origfileslist) |
| 86 | +pprint.pprint(LDAP_CLASS.__dict__) |
48 | 87 |
|
49 |
| -#-- Let distutils/setuptools do the rest |
50 |
| -name = 'python-ldap' |
51 | 88 |
|
52 |
| -# Python 2.3.6+ and setuptools are needed to build eggs, so |
53 |
| -# let's handle setuptools' additional keyword arguments to |
54 |
| -# setup() in a fashion that doesn't break compatibility to |
55 |
| -# distutils. This still allows 'normal' builds where either |
56 |
| -# Python > 2.3.5 or setuptools (or both ;o) are not available. |
57 |
| -kwargs = dict() |
58 |
| -if has_setuptools: |
59 |
| - kwargs = dict( |
60 |
| - include_package_data = True, |
61 |
| - install_requires = ['setuptools'], |
62 |
| - zip_safe = False |
63 |
| - ) |
| 89 | +#-- Let distutils/setuptools do the rest |
64 | 90 |
|
65 | 91 | setup(
|
66 |
| - #-- Package description |
67 |
| - name = name, |
68 |
| - license=pkginfo.__license__, |
69 |
| - version=pkginfo.__version__, |
70 |
| - description = 'Python modules for implementing LDAP clients', |
71 |
| - long_description = """python-ldap: |
72 |
| - python-ldap provides an object-oriented API to access LDAP directory servers |
73 |
| - from Python programs. Mainly it wraps the OpenLDAP 2.x libs for that purpose. |
74 |
| - Additionally the package contains modules for other LDAP-related stuff |
75 |
| - (e.g. processing LDIF, LDAPURLs, LDAPv3 schema, LDAPv3 extended operations |
76 |
| - and controls, etc.). |
77 |
| - """, |
78 |
| - author = pkginfo.__author__, |
79 |
| - author_email = 'python-ldap@python.org', |
80 |
| - url = 'https://www.python-ldap.org/', |
81 |
| - download_url = 'https://pypi.python.org/pypi/python-ldap/', |
82 |
| - classifiers = [ |
83 |
| - 'Development Status :: 5 - Production/Stable', |
84 |
| - 'Intended Audience :: Developers', |
85 |
| - 'Intended Audience :: System Administrators', |
86 |
| - 'Operating System :: OS Independent', |
87 |
| - 'Operating System :: MacOS :: MacOS X', |
88 |
| - 'Operating System :: Microsoft :: Windows', |
89 |
| - 'Operating System :: POSIX', |
90 |
| - 'Programming Language :: C', |
91 |
| - 'Programming Language :: Python', |
92 |
| - 'Programming Language :: Python :: 2', |
93 |
| - 'Topic :: Database', |
94 |
| - 'Topic :: Internet', |
95 |
| - 'Topic :: Software Development :: Libraries :: Python Modules', |
96 |
| - 'Topic :: System :: Systems Administration :: Authentication/Directory :: LDAP', |
97 |
| - 'License :: OSI Approved :: Python Software Foundation License', |
98 |
| - ], |
99 |
| - #-- C extension modules |
100 |
| - ext_modules = [ |
101 |
| - Extension( |
102 |
| - '_ldap', |
103 |
| - [ |
104 |
| - 'Modules/LDAPObject.c', |
105 |
| - 'Modules/ldapcontrol.c', |
106 |
| - 'Modules/common.c', |
107 |
| - 'Modules/constants.c', |
108 |
| - 'Modules/errors.c', |
109 |
| - 'Modules/functions.c', |
110 |
| - 'Modules/ldapmodule.c', |
111 |
| - 'Modules/message.c', |
112 |
| - 'Modules/options.c', |
113 |
| - 'Modules/berval.c', |
114 |
| - ], |
115 |
| - libraries = LDAP_CLASS.libs, |
116 |
| - include_dirs = ['Modules'] + LDAP_CLASS.include_dirs, |
117 |
| - library_dirs = LDAP_CLASS.library_dirs, |
118 |
| - extra_compile_args = LDAP_CLASS.extra_compile_args, |
119 |
| - extra_link_args = LDAP_CLASS.extra_link_args, |
120 |
| - extra_objects = LDAP_CLASS.extra_objects, |
121 |
| - runtime_library_dirs = (not sys.platform.startswith("win"))*LDAP_CLASS.library_dirs, |
122 |
| - define_macros = LDAP_CLASS.defines + \ |
123 |
| - ('ldap_r' in LDAP_CLASS.libs or 'oldap_r' in LDAP_CLASS.libs)*[('HAVE_LIBLDAP_R',None)] + \ |
124 |
| - ('sasl' in LDAP_CLASS.libs or 'sasl2' in LDAP_CLASS.libs or 'libsasl' in LDAP_CLASS.libs)*[('HAVE_SASL',None)] + \ |
125 |
| - ('ssl' in LDAP_CLASS.libs and 'crypto' in LDAP_CLASS.libs)*[('HAVE_TLS',None)] + \ |
126 |
| - [ |
127 |
| - ('LDAPMODULE_VERSION', pkginfo.__version__), |
128 |
| - ('LDAPMODULE_AUTHOR', pkginfo.__author__), |
129 |
| - ('LDAPMODULE_LICENSE', pkginfo.__license__), |
130 |
| - ] |
131 |
| - ), |
132 |
| - ], |
133 |
| - #-- Python "stand alone" modules |
134 |
| - py_modules = [ |
135 |
| - 'ldapurl', |
136 |
| - 'ldif', |
137 |
| - 'ldap', |
138 |
| - 'slapdtest', |
139 |
| - 'ldap.async', |
140 |
| - 'ldap.controls', |
141 |
| - 'ldap.controls.deref', |
142 |
| - 'ldap.controls.libldap', |
143 |
| - 'ldap.controls.openldap', |
144 |
| - 'ldap.controls.ppolicy', |
145 |
| - 'ldap.controls.psearch', |
146 |
| - 'ldap.controls.pwdpolicy', |
147 |
| - 'ldap.controls.readentry', |
148 |
| - 'ldap.controls.sessiontrack', |
149 |
| - 'ldap.controls.simple', |
150 |
| - 'ldap.controls.sss', |
151 |
| - 'ldap.controls.vlv', |
152 |
| - 'ldap.cidict', |
153 |
| - 'ldap.dn', |
154 |
| - 'ldap.extop', |
155 |
| - 'ldap.extop.dds', |
156 |
| - 'ldap.filter', |
157 |
| - 'ldap.functions', |
158 |
| - 'ldap.ldapobject', |
159 |
| - 'ldap.ldapobject.simple', |
160 |
| - 'ldap.ldapobject.reconnect', |
161 |
| - 'ldap.logger', |
162 |
| - 'ldap.modlist', |
163 |
| - 'ldap.pkginfo', |
164 |
| - 'ldap.resiter', |
165 |
| - 'ldap.sasl', |
166 |
| - 'ldap.schema', |
167 |
| - 'ldap.schema.models', |
168 |
| - 'ldap.schema.subentry', |
169 |
| - 'ldap.schema.tokenizer', |
170 |
| - 'ldap.syncrepl', |
171 |
| - ], |
172 |
| - package_dir = {'': 'Lib',}, |
173 |
| - data_files = LDAP_CLASS.extra_files, |
174 |
| - test_suite = 'Tests', |
175 |
| - **kwargs |
| 92 | + name='python-ldap', |
| 93 | + license=pkginfo.__license__, |
| 94 | + version=pkginfo.__version__, |
| 95 | + description='Python modules for implementing LDAP clients', |
| 96 | + long_description="""python-ldap: |
| 97 | + python-ldap provides an object-oriented API to access LDAP directory servers |
| 98 | + from Python programs. Mainly it wraps the OpenLDAP 2.x libs for that purpose. |
| 99 | + Additionally the package contains modules for other LDAP-related stuff |
| 100 | + (e.g. processing LDIF, LDAPURLs, LDAPv3 schema, LDAPv3 extended operations |
| 101 | + and controls, etc.). |
| 102 | + """, |
| 103 | + author=pkginfo.__author__, |
| 104 | + author_email='python-ldap@python.org', |
| 105 | + url='https://www.python-ldap.org/', |
| 106 | + download_url='https://pypi.python.org/pypi/python-ldap/', |
| 107 | + classifiers=[ |
| 108 | + 'Development Status :: 5 - Production/Stable', |
| 109 | + 'Intended Audience :: Developers', |
| 110 | + 'Intended Audience :: System Administrators', |
| 111 | + 'Operating System :: OS Independent', |
| 112 | + 'Operating System :: MacOS :: MacOS X', |
| 113 | + 'Operating System :: Microsoft :: Windows', |
| 114 | + 'Operating System :: POSIX', |
| 115 | + 'Programming Language :: C', |
| 116 | + 'Programming Language :: Python', |
| 117 | + 'Programming Language :: Python :: 2', |
| 118 | + 'Topic :: Database', |
| 119 | + 'Topic :: Internet', |
| 120 | + 'Topic :: Software Development :: Libraries :: Python Modules', |
| 121 | + 'Topic :: System :: Systems Administration :: Authentication/Directory :: LDAP', |
| 122 | + 'License :: OSI Approved :: Python Software Foundation License', |
| 123 | + ], |
| 124 | + #-- C extension modules |
| 125 | + ext_modules=[ |
| 126 | + Extension( |
| 127 | + '_ldap', |
| 128 | + [ |
| 129 | + 'Modules/LDAPObject.c', |
| 130 | + 'Modules/ldapcontrol.c', |
| 131 | + 'Modules/common.c', |
| 132 | + 'Modules/constants.c', |
| 133 | + 'Modules/errors.c', |
| 134 | + 'Modules/functions.c', |
| 135 | + 'Modules/ldapmodule.c', |
| 136 | + 'Modules/message.c', |
| 137 | + 'Modules/options.c', |
| 138 | + 'Modules/berval.c', |
| 139 | + ], |
| 140 | + libraries=LDAP_CLASS.libs, |
| 141 | + include_dirs=LDAP_CLASS.include_dirs, |
| 142 | + library_dirs=LDAP_CLASS.library_dirs, |
| 143 | + extra_compile_args=LDAP_CLASS.extra_compile_args, |
| 144 | + extra_link_args=LDAP_CLASS.extra_link_args, |
| 145 | + extra_objects=LDAP_CLASS.extra_objects, |
| 146 | + runtime_library_dirs=LDAP_CLASS.library_dirs, |
| 147 | + define_macros=LDAP_CLASS.define_macros, |
| 148 | + ), |
| 149 | + ], |
| 150 | + #-- Python "stand alone" modules |
| 151 | + py_modules=[ |
| 152 | + 'ldapurl', |
| 153 | + 'ldif', |
| 154 | + 'ldap', |
| 155 | + 'slapdtest', |
| 156 | + 'ldap.async', |
| 157 | + 'ldap.controls', |
| 158 | + 'ldap.controls.deref', |
| 159 | + 'ldap.controls.libldap', |
| 160 | + 'ldap.controls.openldap', |
| 161 | + 'ldap.controls.ppolicy', |
| 162 | + 'ldap.controls.psearch', |
| 163 | + 'ldap.controls.pwdpolicy', |
| 164 | + 'ldap.controls.readentry', |
| 165 | + 'ldap.controls.sessiontrack', |
| 166 | + 'ldap.controls.simple', |
| 167 | + 'ldap.controls.sss', |
| 168 | + 'ldap.controls.vlv', |
| 169 | + 'ldap.cidict', |
| 170 | + 'ldap.dn', |
| 171 | + 'ldap.extop', |
| 172 | + 'ldap.extop.dds', |
| 173 | + 'ldap.filter', |
| 174 | + 'ldap.functions', |
| 175 | + 'ldap.ldapobject', |
| 176 | + 'ldap.ldapobject.simple', |
| 177 | + 'ldap.ldapobject.reconnect', |
| 178 | + 'ldap.logger', |
| 179 | + 'ldap.modlist', |
| 180 | + 'ldap.pkginfo', |
| 181 | + 'ldap.resiter', |
| 182 | + 'ldap.sasl', |
| 183 | + 'ldap.schema', |
| 184 | + 'ldap.schema.models', |
| 185 | + 'ldap.schema.subentry', |
| 186 | + 'ldap.schema.tokenizer', |
| 187 | + 'ldap.syncrepl', |
| 188 | + ], |
| 189 | + package_dir={'': 'Lib'}, |
| 190 | + data_files=LDAP_CLASS.extra_files, |
| 191 | + test_suite='Tests', |
| 192 | + **setup_kwargs |
176 | 193 | )
|
0 commit comments