root / logilab.pylintinstaller / logilab / common / setup.py

Revision 202:d67e86292521, 5.7 kB (checked in by tziade@…, 9 months ago)

added logilab.pylintinstaller

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