| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/env python |
| 2 # -*- coding: utf-8 -*- |
| 3 # pylint: disable=W0404,W0622,W0704,W0613 |
| 4 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
| 5 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
| 6 # |
| 7 # This file is part of logilab-common. |
| 8 # |
| 9 # logilab-common is free software: you can redistribute it and/or modify it unde
r |
| 10 # the terms of the GNU Lesser General Public License as published by the Free |
| 11 # Software Foundation, either version 2.1 of the License, or (at your option) an
y |
| 12 # later version. |
| 13 # |
| 14 # logilab-common is distributed in the hope that it will be useful, but WITHOUT |
| 15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 16 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 17 # details. |
| 18 # |
| 19 # You should have received a copy of the GNU Lesser General Public License along |
| 20 # with logilab-common. If not, see <http://www.gnu.org/licenses/>. |
| 21 """Generic Setup script, takes package info from __pkginfo__.py file. |
| 22 """ |
| 23 __docformat__ = "restructuredtext en" |
| 24 |
| 25 import os |
| 26 import sys |
| 27 import shutil |
| 28 from os.path import isdir, exists, join |
| 29 |
| 30 try: |
| 31 if os.environ.get('NO_SETUPTOOLS'): |
| 32 raise ImportError() |
| 33 from setuptools import setup |
| 34 from setuptools.command import install_lib |
| 35 USE_SETUPTOOLS = 1 |
| 36 except ImportError: |
| 37 from distutils.core import setup |
| 38 from distutils.command import install_lib |
| 39 USE_SETUPTOOLS = 0 |
| 40 |
| 41 try: |
| 42 # python3 |
| 43 from distutils.command.build_py import build_py_2to3 as build_py |
| 44 except ImportError: |
| 45 # python2.x |
| 46 from distutils.command.build_py import build_py |
| 47 |
| 48 sys.modules.pop('__pkginfo__', None) |
| 49 # import optional features |
| 50 __pkginfo__ = __import__("__pkginfo__") |
| 51 # import required features |
| 52 from __pkginfo__ import modname, version, license, description, \ |
| 53 web, author, author_email |
| 54 |
| 55 distname = getattr(__pkginfo__, 'distname', modname) |
| 56 scripts = getattr(__pkginfo__, 'scripts', []) |
| 57 data_files = getattr(__pkginfo__, 'data_files', None) |
| 58 subpackage_of = getattr(__pkginfo__, 'subpackage_of', None) |
| 59 include_dirs = getattr(__pkginfo__, 'include_dirs', []) |
| 60 ext_modules = getattr(__pkginfo__, 'ext_modules', None) |
| 61 install_requires = getattr(__pkginfo__, 'install_requires', None) |
| 62 dependency_links = getattr(__pkginfo__, 'dependency_links', []) |
| 63 classifiers = getattr(__pkginfo__, 'classifiers', []) |
| 64 |
| 65 STD_BLACKLIST = ('CVS', '.svn', '.hg', 'debian', 'dist', 'build') |
| 66 |
| 67 IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~') |
| 68 |
| 69 if exists('README'): |
| 70 long_description = open('README').read() |
| 71 else: |
| 72 long_description = '' |
| 73 |
| 74 def ensure_scripts(linux_scripts): |
| 75 """Creates the proper script names required for each platform |
| 76 (taken from 4Suite) |
| 77 """ |
| 78 from distutils import util |
| 79 if util.get_platform()[:3] == 'win': |
| 80 scripts_ = [script + '.bat' for script in linux_scripts] |
| 81 else: |
| 82 scripts_ = linux_scripts |
| 83 return scripts_ |
| 84 |
| 85 def get_packages(directory, prefix): |
| 86 """return a list of subpackages for the given directory""" |
| 87 result = [] |
| 88 for package in os.listdir(directory): |
| 89 absfile = join(directory, package) |
| 90 if isdir(absfile): |
| 91 if exists(join(absfile, '__init__.py')) or \ |
| 92 package in ('test', 'tests'): |
| 93 if prefix: |
| 94 result.append('%s.%s' % (prefix, package)) |
| 95 else: |
| 96 result.append(package) |
| 97 result += get_packages(absfile, result[-1]) |
| 98 return result |
| 99 |
| 100 EMPTY_FILE = '''"""generated file, don't modify or your data will be lost""" |
| 101 try: |
| 102 __import__('pkg_resources').declare_namespace(__name__) |
| 103 except ImportError: |
| 104 pass |
| 105 ''' |
| 106 |
| 107 class MyInstallLib(install_lib.install_lib): |
| 108 """extend install_lib command to handle package __init__.py and |
| 109 include_dirs variable if necessary |
| 110 """ |
| 111 def run(self): |
| 112 """overridden from install_lib class""" |
| 113 install_lib.install_lib.run(self) |
| 114 # create Products.__init__.py if needed |
| 115 if subpackage_of: |
| 116 product_init = join(self.install_dir, subpackage_of, '__init__.py') |
| 117 if not exists(product_init): |
| 118 self.announce('creating %s' % product_init) |
| 119 stream = open(product_init, 'w') |
| 120 stream.write(EMPTY_FILE) |
| 121 stream.close() |
| 122 # manually install included directories if any |
| 123 if include_dirs: |
| 124 if subpackage_of: |
| 125 base = join(subpackage_of, modname) |
| 126 else: |
| 127 base = modname |
| 128 for directory in include_dirs: |
| 129 dest = join(self.install_dir, base, directory) |
| 130 shutil.rmtree(dest, ignore_errors=True) |
| 131 shutil.copytree(directory, dest) |
| 132 |
| 133 def install(**kwargs): |
| 134 """setup entry point""" |
| 135 if USE_SETUPTOOLS: |
| 136 if '--force-manifest' in sys.argv: |
| 137 sys.argv.remove('--force-manifest') |
| 138 # install-layout option was introduced in 2.5.3-1~exp1 |
| 139 elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv: |
| 140 sys.argv.remove('--install-layout=deb') |
| 141 if subpackage_of: |
| 142 package = subpackage_of + '.' + modname |
| 143 kwargs['package_dir'] = {package : '.'} |
| 144 packages = [package] + get_packages(os.getcwd(), package) |
| 145 if USE_SETUPTOOLS: |
| 146 kwargs['namespace_packages'] = [subpackage_of] |
| 147 else: |
| 148 kwargs['package_dir'] = {modname : '.'} |
| 149 packages = [modname] + get_packages(os.getcwd(), modname) |
| 150 if USE_SETUPTOOLS and install_requires: |
| 151 kwargs['install_requires'] = install_requires |
| 152 kwargs['dependency_links'] = dependency_links |
| 153 kwargs['packages'] = packages |
| 154 return setup(name = distname, |
| 155 version = version, |
| 156 license = license, |
| 157 description = description, |
| 158 long_description = long_description, |
| 159 classifiers = classifiers, |
| 160 author = author, |
| 161 author_email = author_email, |
| 162 url = web, |
| 163 scripts = ensure_scripts(scripts), |
| 164 data_files = data_files, |
| 165 ext_modules = ext_modules, |
| 166 cmdclass = {'install_lib': MyInstallLib, |
| 167 'build_py': build_py}, |
| 168 **kwargs |
| 169 ) |
| 170 |
| 171 if __name__ == '__main__' : |
| 172 install() |
| OLD | NEW |