logilab/doctools
view setup.py @ 0:cc367abb080e
forget the past.
forget the past.
| author | root |
|---|---|
| date | Wed, 26 Apr 2006 10:48:09 +0000 |
| parents | |
| children | 0a55df1f447a |
line source
1 #!/usr/bin/env python
2 # pylint: disable-msg=W0142, W0403,W0404, W0613,W0622,W0622, W0704, R0904
3 #
4 # Copyright (c) 2003 LOGILAB S.A. (Paris, FRANCE).
5 # http://www.logilab.fr/ -- mailto:contact@logilab.fr
6 #
7 # This program is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # this program; if not, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 """ Generic Setup script, takes package info from __pkginfo__.py file """
21 __revision__ = '$Id: setup.py,v 1.7 2005-03-29 12:17:21 syt Exp $'
23 from __future__ import nested_scopes
24 import os
25 import sys
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
31 # import required features
32 from __pkginfo__ import modname, version, license, short_desc, long_desc, \
33 web, author, author_email
34 # import optional features
35 try:
36 from __pkginfo__ import distname
37 except ImportError:
38 distname = modname
39 try:
40 from __pkginfo__ import scripts
41 except ImportError:
42 scripts = []
43 try:
44 from __pkginfo__ import data_files
45 except ImportError:
46 data_files = None
47 try:
48 from __pkginfo__ import subpackage_of
49 except ImportError:
50 subpackage_of = None
51 try:
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
60 BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
61 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
64 def ensure_scripts(linux_scripts):
65 """
66 Creates the proper script names required for each platform
67 (taken from 4Suite)
68 """
69 from distutils import util
70 if util.get_platform()[:3] == 'win':
71 scripts_ = [script + '.bat' for script in linux_scripts]
72 else:
73 scripts_ = linux_scripts
74 return scripts_
77 def get_packages(directory, prefix):
78 """return a list of subpackages for the given directory
79 """
80 result = []
81 for package in os.listdir(directory):
82 absfile = join(directory, package)
83 if isdir(absfile):
84 if exists(join(absfile, '__init__.py')) or \
85 package in ('test', 'tests'):
86 if prefix:
87 result.append('%s.%s' % (prefix, package))
88 else:
89 result.append(package)
90 result += get_packages(absfile, result[-1])
91 return result
93 def export(from_dir, to_dir,
94 blacklist=BASE_BLACKLIST,
95 ignore_ext=IGNORED_EXTENSIONS):
96 """make a mirror of from_dir in to_dir, omitting directories and files
97 listed in the black list
98 """
99 def make_mirror(arg, directory, fnames):
100 """walk handler"""
101 for norecurs in blacklist:
102 try:
103 fnames.remove(norecurs)
104 except ValueError:
105 pass
106 for filename in fnames:
107 # don't include binary files
108 if filename[-4:] in ignore_ext:
109 continue
110 if filename[-1] == '~':
111 continue
112 src = '%s/%s' % (directory, filename)
113 dest = to_dir + src[len(from_dir):]
114 print >> sys.stderr, src, '->', dest
115 if os.path.isdir(src):
116 if not exists(dest):
117 os.mkdir(dest)
118 else:
119 if exists(dest):
120 os.remove(dest)
121 shutil.copy2(src, dest)
122 try:
123 os.mkdir(to_dir)
124 except OSError, ex:
125 # file exists ?
126 import errno
127 if ex.errno != errno.EEXIST:
128 raise
129 walk(from_dir, make_mirror, None)
132 EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n'
134 class MyInstallLib(install_lib.install_lib):
135 """extend install_lib command to handle package __init__.py and
136 include_dirs variable if necessary
137 """
138 def run(self):
139 """overriden from install_lib class"""
140 install_lib.install_lib.run(self)
141 # create Products.__init__.py if needed
142 if subpackage_of:
143 product_init = join(self.install_dir, subpackage_of, '__init__.py')
144 if not exists(product_init):
145 self.announce('creating %s' % product_init)
146 stream = open(product_init, 'w')
147 stream.write(EMPTY_FILE)
148 stream.close()
149 # manually install included directories if any
150 if include_dirs:
151 if subpackage_of:
152 base = join(subpackage_of, modname)
153 else:
154 base = modname
155 for directory in include_dirs:
156 dest = join(self.install_dir, base, directory)
157 export(directory, dest)
159 def install(**kwargs):
160 """setup entry point"""
161 if subpackage_of:
162 package = subpackage_of + '.' + modname
163 kwargs['package_dir'] = {package : '.'}
164 packages = [package] + get_packages(os.getcwd(), package)
165 else:
166 kwargs['package_dir'] = {modname : '.'}
167 packages = [modname] + get_packages(os.getcwd(), modname)
168 kwargs['packages'] = packages
169 return setup(name = distname,
170 version = version,
171 license =license,
172 description = short_desc,
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,
180 cmdclass={'install_lib': MyInstallLib},
181 **kwargs
182 )
184 if __name__ == '__main__' :
185 install()
