22 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 |
23 |
24 import os |
24 import os |
25 import sys |
25 import sys |
26 import shutil |
26 import shutil |
27 from distutils.core import setup |
|
28 from distutils.command import install_lib |
|
29 from os.path import isdir, exists, join, walk |
27 from os.path import isdir, exists, join, walk |
30 |
28 |
|
29 try: |
|
30 if os.environ.get('NO_SETUPTOOLS'): |
|
31 raise ImportError() # do as there is no setuptools |
|
32 from setuptools import setup |
|
33 from setuptools.command import install_lib |
|
34 USE_SETUPTOOLS = True |
|
35 except ImportError: |
|
36 from distutils.core import setup |
|
37 from distutils.command import install_lib |
|
38 USE_SETUPTOOLS = False |
|
39 |
31 # import required features |
40 # import required features |
32 from __pkginfo__ import modname, version, license, short_desc, long_desc, \ |
41 from __pkginfo__ import modname, version, license, description, web, \ |
33 web, author, author_email |
42 author, author_email |
|
43 |
|
44 if exists('README'): |
|
45 long_description = file('README').read() |
|
46 |
34 # import optional features |
47 # import optional features |
35 try: |
48 import __pkginfo__ |
36 from __pkginfo__ import distname |
49 if USE_SETUPTOOLS: |
37 except ImportError: |
50 requires = {} |
38 distname = modname |
51 for entry in ("__depends__", "__recommends__"): |
39 try: |
52 requires.update(getattr(__pkginfo__, entry, {})) |
40 from __pkginfo__ import scripts |
53 install_requires = [("%s %s" % (d, v and v or "")).strip() |
41 except ImportError: |
54 for d, v in requires.iteritems()] |
42 scripts = [] |
55 else: |
43 try: |
56 install_requires = [] |
44 from __pkginfo__ import data_files |
57 |
45 except ImportError: |
58 distname = getattr(__pkginfo__, 'distname', modname) |
46 data_files = None |
59 scripts = getattr(__pkginfo__, 'scripts', ()) |
47 try: |
60 include_dirs = getattr(__pkginfo__, 'include_dirs', ()) |
48 from __pkginfo__ import subpackage_of |
61 data_files = getattr(__pkginfo__, 'data_files', None) |
49 except ImportError: |
62 subpackage_of = getattr(__pkginfo__, 'subpackage_of', None) |
50 subpackage_of = None |
63 ext_modules = getattr(__pkginfo__, 'ext_modules', None) |
51 try: |
64 |
52 from __pkginfo__ import include_dirs |
|
53 except ImportError: |
|
54 include_dirs = [] |
|
55 try: |
|
56 from __pkginfo__ import ext_modules |
|
57 except ImportError: |
|
58 ext_modules = None |
|
59 |
65 |
60 BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog') |
66 BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog') |
61 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc') |
67 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc') |
62 |
68 |
63 |
69 |
90 result += get_packages(absfile, result[-1]) |
96 result += get_packages(absfile, result[-1]) |
91 return result |
97 return result |
92 |
98 |
93 def export(from_dir, to_dir, |
99 def export(from_dir, to_dir, |
94 blacklist=BASE_BLACKLIST, |
100 blacklist=BASE_BLACKLIST, |
95 ignore_ext=IGNORED_EXTENSIONS): |
101 ignore_ext=IGNORED_EXTENSIONS, |
|
102 verbose=True): |
96 """make a mirror of from_dir in to_dir, omitting directories and files |
103 """make a mirror of from_dir in to_dir, omitting directories and files |
97 listed in the black list |
104 listed in the black list |
98 """ |
105 """ |
99 def make_mirror(arg, directory, fnames): |
106 def make_mirror(arg, directory, fnames): |
100 """walk handler""" |
107 """walk handler""" |
152 base = join(subpackage_of, modname) |
160 base = join(subpackage_of, modname) |
153 else: |
161 else: |
154 base = modname |
162 base = modname |
155 for directory in include_dirs: |
163 for directory in include_dirs: |
156 dest = join(self.install_dir, base, directory) |
164 dest = join(self.install_dir, base, directory) |
157 export(directory, dest) |
165 export(directory, dest, verbose=False) |
158 |
166 |
159 def install(**kwargs): |
167 def install(**kwargs): |
160 """setup entry point""" |
168 """setup entry point""" |
|
169 if not USE_SETUPTOOLS and '--install-layout=deb' in sys.argv and \ |
|
170 sys.versioninfo < (2, 5, 4): |
|
171 sys.argv.remove('--install-layout=deb') |
|
172 print "W: remove '--install-layout=deb' option" |
161 if subpackage_of: |
173 if subpackage_of: |
162 package = subpackage_of + '.' + modname |
174 package = subpackage_of + '.' + modname |
163 kwargs['package_dir'] = {package : '.'} |
175 kwargs['package_dir'] = {package : '.'} |
164 packages = [package] + get_packages(os.getcwd(), package) |
176 packages = [package] + get_packages(os.getcwd(), package) |
|
177 if USE_SETUPTOOLS: |
|
178 kwargs['namespace_packages'] = [subpackage_of] |
165 else: |
179 else: |
166 kwargs['package_dir'] = {modname : '.'} |
180 kwargs['package_dir'] = {modname : '.'} |
167 packages = [modname] + get_packages(os.getcwd(), modname) |
181 packages = [modname] + get_packages(os.getcwd(), modname) |
168 kwargs['packages'] = packages |
182 kwargs['packages'] = packages |
169 return setup(name = distname, |
183 return setup(name=distname, version=version, license=license, url=web, |
170 version = version, |
184 description=description, long_description=long_description, |
171 license =license, |
185 author=author, author_email=author_email, |
172 description = short_desc, |
186 scripts=ensure_scripts(scripts), data_files=data_files, |
173 long_description = long_desc, |
|
174 author = author, |
|
175 author_email = author_email, |
|
176 url = web, |
|
177 scripts = ensure_scripts(scripts), |
|
178 data_files=data_files, |
|
179 ext_modules=ext_modules, |
187 ext_modules=ext_modules, |
|
188 install_requires=install_requires, |
|
189 #dependency_links=["http://alain:alain@intranet.logilab.fr/~alain/"], |
180 cmdclass={'install_lib': MyInstallLib}, |
190 cmdclass={'install_lib': MyInstallLib}, |
181 **kwargs |
191 **kwargs |
182 ) |
192 ) |
183 |
193 |
184 if __name__ == '__main__' : |
194 if __name__ == '__main__' : |