author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 27 Sep 2010 17:14:23 +0200 | |
branch | stable |
changeset 6346 | 1a968e545e4e |
parent 6327 | 73413f2750af |
child 6491 | ee9a10b6620e |
child 6506 | c1661ea815dc |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
# pylint: disable-msg=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611 |
|
3 |
# |
|
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
4 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
5 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
7 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
8 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
9 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
10 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
11 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
12 |
# any later version. |
0 | 13 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
14 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
0 | 15 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
16 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
17 |
# details. |
0 | 18 |
# |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
19 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
20 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
21 |
"""Generic Setup script, takes package info from __pkginfo__.py file |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4721
diff
changeset
|
22 |
""" |
0 | 23 |
|
24 |
import os |
|
25 |
import sys |
|
26 |
import shutil |
|
27 |
from os.path import isdir, exists, join, walk |
|
28 |
||
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
29 |
try: |
5512 | 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 |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
35 |
except ImportError: |
5512 | 36 |
from distutils.core import setup |
37 |
from distutils.command import install_lib |
|
38 |
USE_SETUPTOOLS = False |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
39 |
|
0 | 40 |
# import required features |
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
41 |
from __pkginfo__ import modname, version, license, description, web, \ |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
42 |
author, author_email |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
43 |
|
5329
a8cd0570e3d6
[packaging] setup.py cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5024
diff
changeset
|
44 |
long_description = file('README').read() |
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
45 |
|
0 | 46 |
# import optional features |
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
47 |
import __pkginfo__ |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
48 |
if USE_SETUPTOOLS: |
5512 | 49 |
requires = {} |
6327
73413f2750af
[easy_install] stop installing recommends, user should install them manually if desired (avoid errors on optional packages blocking install)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5512
diff
changeset
|
50 |
for entry in ("__depends__",): # "__recommends__"): |
5512 | 51 |
requires.update(getattr(__pkginfo__, entry, {})) |
52 |
install_requires = [("%s %s" % (d, v and v or "")).strip() |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
53 |
for d, v in requires.iteritems()] |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
54 |
else: |
5512 | 55 |
install_requires = [] |
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
56 |
|
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
57 |
distname = getattr(__pkginfo__, 'distname', modname) |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
58 |
scripts = getattr(__pkginfo__, 'scripts', ()) |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
59 |
include_dirs = getattr(__pkginfo__, 'include_dirs', ()) |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
60 |
data_files = getattr(__pkginfo__, 'data_files', None) |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
61 |
subpackage_of = getattr(__pkginfo__, 'subpackage_of', None) |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
62 |
ext_modules = getattr(__pkginfo__, 'ext_modules', None) |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
63 |
|
0 | 64 |
|
65 |
BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog') |
|
66 |
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc') |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
67 |
|
0 | 68 |
|
69 |
def ensure_scripts(linux_scripts): |
|
70 |
""" |
|
71 |
Creates the proper script names required for each platform |
|
72 |
(taken from 4Suite) |
|
73 |
""" |
|
74 |
from distutils import util |
|
75 |
if util.get_platform()[:3] == 'win': |
|
76 |
scripts_ = [script + '.bat' for script in linux_scripts] |
|
77 |
else: |
|
78 |
scripts_ = linux_scripts |
|
79 |
return scripts_ |
|
80 |
||
81 |
||
82 |
def get_packages(directory, prefix): |
|
83 |
"""return a list of subpackages for the given directory |
|
84 |
""" |
|
85 |
result = [] |
|
86 |
for package in os.listdir(directory): |
|
87 |
absfile = join(directory, package) |
|
88 |
if isdir(absfile): |
|
89 |
if exists(join(absfile, '__init__.py')) or \ |
|
90 |
package in ('test', 'tests'): |
|
91 |
if prefix: |
|
92 |
result.append('%s.%s' % (prefix, package)) |
|
93 |
else: |
|
94 |
result.append(package) |
|
95 |
result += get_packages(absfile, result[-1]) |
|
96 |
return result |
|
97 |
||
98 |
def export(from_dir, to_dir, |
|
99 |
blacklist=BASE_BLACKLIST, |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
100 |
ignore_ext=IGNORED_EXTENSIONS, |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
101 |
verbose=True): |
0 | 102 |
"""make a mirror of from_dir in to_dir, omitting directories and files |
103 |
listed in the black list |
|
104 |
""" |
|
105 |
def make_mirror(arg, directory, fnames): |
|
106 |
"""walk handler""" |
|
107 |
for norecurs in blacklist: |
|
108 |
try: |
|
109 |
fnames.remove(norecurs) |
|
110 |
except ValueError: |
|
111 |
pass |
|
112 |
for filename in fnames: |
|
113 |
# don't include binary files |
|
114 |
if filename[-4:] in ignore_ext: |
|
115 |
continue |
|
116 |
if filename[-1] == '~': |
|
117 |
continue |
|
118 |
src = '%s/%s' % (directory, filename) |
|
119 |
dest = to_dir + src[len(from_dir):] |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
120 |
if verbose: |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
121 |
print >> sys.stderr, src, '->', dest |
0 | 122 |
if os.path.isdir(src): |
123 |
if not exists(dest): |
|
124 |
os.mkdir(dest) |
|
125 |
else: |
|
126 |
if exists(dest): |
|
127 |
os.remove(dest) |
|
128 |
shutil.copy2(src, dest) |
|
129 |
try: |
|
130 |
os.mkdir(to_dir) |
|
131 |
except OSError, ex: |
|
132 |
# file exists ? |
|
133 |
import errno |
|
134 |
if ex.errno != errno.EEXIST: |
|
135 |
raise |
|
136 |
walk(from_dir, make_mirror, None) |
|
137 |
||
138 |
||
139 |
EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n' |
|
140 |
||
141 |
class MyInstallLib(install_lib.install_lib): |
|
142 |
"""extend install_lib command to handle package __init__.py and |
|
143 |
include_dirs variable if necessary |
|
144 |
""" |
|
145 |
def run(self): |
|
146 |
"""overridden from install_lib class""" |
|
147 |
install_lib.install_lib.run(self) |
|
148 |
# create Products.__init__.py if needed |
|
149 |
if subpackage_of: |
|
150 |
product_init = join(self.install_dir, subpackage_of, '__init__.py') |
|
151 |
if not exists(product_init): |
|
152 |
self.announce('creating %s' % product_init) |
|
153 |
stream = open(product_init, 'w') |
|
154 |
stream.write(EMPTY_FILE) |
|
155 |
stream.close() |
|
156 |
# manually install included directories if any |
|
157 |
if include_dirs: |
|
158 |
if subpackage_of: |
|
159 |
base = join(subpackage_of, modname) |
|
160 |
else: |
|
161 |
base = modname |
|
162 |
for directory in include_dirs: |
|
163 |
dest = join(self.install_dir, base, directory) |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
164 |
export(directory, dest, verbose=False) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
165 |
|
0 | 166 |
def install(**kwargs): |
167 |
"""setup entry point""" |
|
5353
cb8ac7263f8a
[packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5329
diff
changeset
|
168 |
if USE_SETUPTOOLS: |
cb8ac7263f8a
[packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5329
diff
changeset
|
169 |
if '--force-manifest' in sys.argv: |
cb8ac7263f8a
[packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5329
diff
changeset
|
170 |
sys.argv.remove('--force-manifest') |
cb8ac7263f8a
[packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5329
diff
changeset
|
171 |
# install-layout option was introduced in 2.5.3-1~exp1 |
cb8ac7263f8a
[packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5329
diff
changeset
|
172 |
elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: |
cb8ac7263f8a
[packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5329
diff
changeset
|
173 |
sys.argv.remove('--install-layout=deb') |
0 | 174 |
if subpackage_of: |
175 |
package = subpackage_of + '.' + modname |
|
176 |
kwargs['package_dir'] = {package : '.'} |
|
177 |
packages = [package] + get_packages(os.getcwd(), package) |
|
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
178 |
if USE_SETUPTOOLS: |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
179 |
kwargs['namespace_packages'] = [subpackage_of] |
0 | 180 |
else: |
181 |
kwargs['package_dir'] = {modname : '.'} |
|
182 |
packages = [modname] + get_packages(os.getcwd(), modname) |
|
5329
a8cd0570e3d6
[packaging] setup.py cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5024
diff
changeset
|
183 |
if USE_SETUPTOOLS: |
5512 | 184 |
kwargs['install_requires'] = install_requires |
0 | 185 |
kwargs['packages'] = packages |
5024
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
186 |
return setup(name=distname, version=version, license=license, url=web, |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
187 |
description=description, long_description=long_description, |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
188 |
author=author, author_email=author_email, |
9e718abe3fde
add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents:
4721
diff
changeset
|
189 |
scripts=ensure_scripts(scripts), data_files=data_files, |
0 | 190 |
ext_modules=ext_modules, |
191 |
cmdclass={'install_lib': MyInstallLib}, |
|
192 |
**kwargs |
|
193 |
) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
194 |
|
0 | 195 |
if __name__ == '__main__' : |
196 |
install() |