setup.py
author David Douard <david.douard@logilab.fr>
Wed, 22 Jul 2015 17:03:43 +0200
changeset 11653 18939907a115
parent 11642 3defbb0f147a
permissions -rw-r--r--
[pkg] update to dh9 and dh_python2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
#!/usr/bin/env python
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
#
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
     4
# copyright 2003-2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
     5
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
     6
#
11642
3defbb0f147a Prepare release
Christophe de Vienne <christophe@unlish.com>
parents: 11632
diff changeset
     7
# This file is part of CubicWeb pyramid cube.
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
#
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
# CubicWeb is free software: you can redistribute it and/or modify it under the
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
# terms of the GNU Lesser General Public License as published by the Free
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
# Software Foundation, either version 2.1 of the License, or (at your option)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    12
# any later version.
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    13
#
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    16
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
# details.
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    18
#
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
# You should have received a copy of the GNU Lesser General Public License along
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    20
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    21
"""Generic Setup script, takes package info from __pkginfo__.py file
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    22
"""
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    23
__docformat__ = "restructuredtext en"
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    24
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    25
import os
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
import sys
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    27
import shutil
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    28
from os.path import isdir, exists, join, walk, dirname
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    29
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    30
try:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    31
    if os.environ.get('NO_SETUPTOOLS'):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    32
        raise ImportError() # do as there is no setuptools
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    33
    from setuptools import setup
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    34
    from setuptools.command import install_lib
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    35
    USE_SETUPTOOLS = True
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    36
except ImportError:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    37
    from distutils.core import setup
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    38
    from distutils.command import install_lib
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    39
    USE_SETUPTOOLS = False
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    40
from distutils.command import install_data
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    41
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    42
# load metadata from the __pkginfo__.py file so there is no risk of conflict
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    43
# see https://packaging.python.org/en/latest/single_source_version.html
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    44
base_dir = dirname(__file__)
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    45
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    46
pkginfo = {}
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    47
with open(join(base_dir, "__pkginfo__.py")) as f:
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    48
    exec(f.read(), pkginfo)
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    49
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    50
    
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    51
# get required metadatas
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    52
modname = pkginfo['modname']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    53
version = pkginfo['version']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    54
license = pkginfo['license']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    55
description = pkginfo['description']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    56
web = pkginfo['web']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    57
author = pkginfo['author']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    58
author_email = pkginfo['author_email']
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    59
classifiers = pkginfo['classifiers']
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    60
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    61
with open(join(base_dir, 'README')) as f:
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    62
    long_description = f.read()
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    63
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    64
# get optional metadatas
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    65
distname = pkginfo.get('distname', modname)
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    66
scripts = pkginfo.get('scripts', ())
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    67
include_dirs = pkginfo.get('include_dirs', ())
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    68
data_files = pkginfo.get('data_files', None)
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    69
ext_modules = pkginfo.get('ext_modules', None)
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    70
dependency_links = pkginfo.get('dependency_links', ())
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    71
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    72
if USE_SETUPTOOLS:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    73
    requires = {}
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    74
    for entry in ("__depends__",): # "__recommends__"):
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    75
        requires.update(pkginfo.get(entry, {}))
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    76
    install_requires = [("%s %s" % (d, v and v or "")).strip()
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    77
                       for d, v in requires.iteritems()]
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    78
else:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    79
    install_requires = []
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    80
11653
18939907a115 [pkg] update to dh9 and dh_python2
David Douard <david.douard@logilab.fr>
parents: 11642
diff changeset
    81
BASE_BLACKLIST = ('CVS', '.svn', '.hg', '.git', 'debian', 'dist', 'build')
11632
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    82
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc', '~')
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    83
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    84
def ensure_scripts(linux_scripts):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    85
    """
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    86
    Creates the proper script names required for each platform
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    87
    (taken from 4Suite)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    88
    """
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    89
    from distutils import util
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    90
    if util.get_platform()[:3] == 'win':
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    91
        scripts_ = [script + '.bat' for script in linux_scripts]
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    92
    else:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    93
        scripts_ = linux_scripts
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    94
    return scripts_
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    95
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    96
def export(from_dir, to_dir,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    97
           blacklist=BASE_BLACKLIST,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    98
           ignore_ext=IGNORED_EXTENSIONS,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    99
           verbose=True):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   100
    """make a mirror of from_dir in to_dir, omitting directories and files
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   101
    listed in the black list
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   102
    """
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   103
    def make_mirror(arg, directory, fnames):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   104
        """walk handler"""
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   105
        for norecurs in blacklist:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   106
            try:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   107
                fnames.remove(norecurs)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   108
            except ValueError:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   109
                pass
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   110
        for filename in fnames:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   111
            # don't include binary files
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   112
            if filename[-4:] in ignore_ext:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   113
                continue
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   114
            if filename[-1] == '~':
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   115
                continue
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   116
            src = join(directory, filename)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   117
            dest = to_dir + src[len(from_dir):]
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   118
            if verbose:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   119
                sys.stderr.write('%s -> %s\n' % (src, dest))
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   120
            if os.path.isdir(src):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   121
                if not exists(dest):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   122
                    os.mkdir(dest)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   123
            else:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   124
                if exists(dest):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   125
                    os.remove(dest)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   126
                shutil.copy2(src, dest)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   127
    try:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   128
        os.mkdir(to_dir)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   129
    except OSError as ex:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   130
        # file exists ?
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   131
        import errno
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   132
        if ex.errno != errno.EEXIST:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   133
            raise
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   134
    walk(from_dir, make_mirror, None)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   135
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   136
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   137
class MyInstallLib(install_lib.install_lib):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   138
    """extend install_lib command to handle  package __init__.py and
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   139
    include_dirs variable if necessary
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   140
    """
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   141
    def run(self):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   142
        """overridden from install_lib class"""
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   143
        install_lib.install_lib.run(self)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   144
        # manually install included directories if any
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   145
        if include_dirs:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   146
            base = modname
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   147
            for directory in include_dirs:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   148
                dest = join(self.install_dir, base, directory)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   149
                export(directory, dest, verbose=False)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   150
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   151
# re-enable copying data files in sys.prefix
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   152
old_install_data = install_data.install_data
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   153
if USE_SETUPTOOLS:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   154
    # overwrite InstallData to use sys.prefix instead of the egg directory
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   155
    class MyInstallData(old_install_data):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   156
        """A class that manages data files installation"""
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   157
        def run(self):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   158
            _old_install_dir = self.install_dir
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   159
            if self.install_dir.endswith('egg'):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   160
                self.install_dir = sys.prefix
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   161
            old_install_data.run(self)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   162
            self.install_dir = _old_install_dir
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   163
    try:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   164
        import setuptools.command.easy_install # only if easy_install available
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   165
        # monkey patch: Crack SandboxViolation verification
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   166
        from setuptools.sandbox import DirectorySandbox as DS
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   167
        old_ok = DS._ok
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   168
        def _ok(self, path):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   169
            """Return True if ``path`` can be written during installation."""
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   170
            out = old_ok(self, path) # here for side effect from setuptools
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   171
            realpath = os.path.normcase(os.path.realpath(path))
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   172
            allowed_path = os.path.normcase(sys.prefix)
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   173
            if realpath.startswith(allowed_path):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   174
                out = True
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   175
            return out
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   176
        DS._ok = _ok
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   177
    except ImportError:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   178
        pass
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   179
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   180
def install(**kwargs):
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   181
    """setup entry point"""
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   182
    if USE_SETUPTOOLS:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   183
        if '--force-manifest' in sys.argv:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   184
            sys.argv.remove('--force-manifest')
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   185
    # install-layout option was introduced in 2.5.3-1~exp1
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   186
    elif sys.version_info < (2, 5, 4) and '--install-layout=deb' in sys.argv:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   187
        sys.argv.remove('--install-layout=deb')
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   188
    cmdclass = {'install_lib': MyInstallLib}
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   189
    if USE_SETUPTOOLS:
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   190
        kwargs['install_requires'] = install_requires
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   191
        kwargs['dependency_links'] = dependency_links
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   192
        kwargs['zip_safe'] = False
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   193
        cmdclass['install_data'] = MyInstallData
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   194
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   195
    return setup(name = distname,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   196
                 version = version,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   197
                 license = license,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   198
                 description = description,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   199
                 long_description = long_description,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   200
                 author = author,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   201
                 author_email = author_email,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   202
                 url = web,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   203
                 scripts = ensure_scripts(scripts),
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   204
                 data_files = data_files,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   205
                 ext_modules = ext_modules,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   206
                 cmdclass = cmdclass,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   207
                 classifiers = classifiers,
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   208
                 **kwargs
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   209
                 )
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   210
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   211
if __name__ == '__main__' :
b05f361db666 Project structure
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
   212
    install()