setup.py
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Tue, 09 Aug 2011 09:43:26 +0200
changeset 7896 4c954e1e73ef
parent 7879 9aae456abab5
child 8695 358d8bed9626
permissions -rw-r--r--
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
#!/usr/bin/env python
6491
ee9a10b6620e pylint option update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6327
diff changeset
     2
# pylint: disable=W0142,W0403,W0404,W0613,W0622,W0622,W0704,R0904,C0103,E0611
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     3
#
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6836
diff changeset
     4
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
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
     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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
import os
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
import sys
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
import shutil
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
from os.path import isdir, exists, join, walk
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    28
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    29
try:
5512
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    30
    if os.environ.get('NO_SETUPTOOLS'):
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    31
        raise ImportError() # do as there is no setuptools
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    32
    from setuptools import setup
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    33
    from setuptools.command import install_lib
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    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
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    36
    from distutils.core import setup
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    37
    from distutils.command import install_lib
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    38
    USE_SETUPTOOLS = False
6508
38c2ff52cfca [pkg] fix install_data import not present in setuptools
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6506
diff changeset
    39
from distutils.command import install_data
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    40
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
# import required features
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    42
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
    43
     author, author_email
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    44
5329
a8cd0570e3d6 [packaging] setup.py cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5024
diff changeset
    45
long_description = file('README').read()
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    46
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
# import optional features
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    48
import __pkginfo__
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    49
if USE_SETUPTOOLS:
5512
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    50
    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
    51
    for entry in ("__depends__",): # "__recommends__"):
5512
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    52
        requires.update(getattr(__pkginfo__, entry, {}))
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    53
    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
    54
                       for d, v in requires.iteritems()]
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    55
else:
5512
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    56
    install_requires = []
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    57
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    58
distname = getattr(__pkginfo__, 'distname', modname)
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    59
scripts = getattr(__pkginfo__, 'scripts', ())
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    60
include_dirs = getattr(__pkginfo__, 'include_dirs', ())
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
    61
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
    62
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
    63
ext_modules = getattr(__pkginfo__, 'ext_modules', None)
6516
6b2e1e8d3a22 [pkg] use argument *package_data*
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6508
diff changeset
    64
package_data = getattr(__pkginfo__, 'package_data', {})
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
BASE_BLACKLIST = ('CVS', 'debian', 'dist', 'build', '__buildlog')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    67
IGNORED_EXTENSIONS = ('.pyc', '.pyo', '.elc')
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    68
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    69
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
def ensure_scripts(linux_scripts):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
    Creates the proper script names required for each platform
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
    (taken from 4Suite)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
    from distutils import util
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
    if util.get_platform()[:3] == 'win':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
        scripts_ = [script + '.bat' for script in linux_scripts]
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
        scripts_ = linux_scripts
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
    return scripts_
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    81
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    83
def get_packages(directory, prefix):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    84
    """return a list of subpackages for the given directory
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    result = []
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
    for package in os.listdir(directory):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        absfile = join(directory, package)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        if isdir(absfile):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    90
            if exists(join(absfile, '__init__.py')) or \
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    91
                   package in ('test', 'tests'):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    92
                if prefix:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    93
                    result.append('%s.%s' % (prefix, package))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    94
                else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    95
                    result.append(package)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    96
                result += get_packages(absfile, result[-1])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    97
    return result
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    98
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    99
def export(from_dir, to_dir,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
           blacklist=BASE_BLACKLIST,
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
   101
           ignore_ext=IGNORED_EXTENSIONS,
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
   102
           verbose=True):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   103
    """make a mirror of from_dir in to_dir, omitting directories and files
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   104
    listed in the black list
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   106
    def make_mirror(arg, directory, fnames):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
        """walk handler"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
        for norecurs in blacklist:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
            try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
                fnames.remove(norecurs)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
            except ValueError:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   112
                pass
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   113
        for filename in fnames:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   114
            # don't include binary files
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   115
            if filename[-4:] in ignore_ext:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   116
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   117
            if filename[-1] == '~':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   118
                continue
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   119
            src = '%s/%s' % (directory, filename)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   120
            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
   121
            if verbose:
7896
4c954e1e73ef [lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 7879
diff changeset
   122
               sys.stderr.write('%s -> %s\n' % (src, dest))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
            if os.path.isdir(src):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   124
                if not exists(dest):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   125
                    os.mkdir(dest)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   126
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   127
                if exists(dest):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   128
                    os.remove(dest)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   129
                shutil.copy2(src, dest)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   130
    try:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   131
        os.mkdir(to_dir)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   132
    except OSError, ex:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   133
        # file exists ?
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   134
        import errno
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   135
        if ex.errno != errno.EEXIST:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   136
            raise
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   137
    walk(from_dir, make_mirror, None)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   138
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   139
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   140
EMPTY_FILE = '"""generated file, don\'t modify or your data will be lost"""\n'
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   141
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   142
class MyInstallLib(install_lib.install_lib):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   143
    """extend install_lib command to handle  package __init__.py and
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   144
    include_dirs variable if necessary
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   145
    """
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   146
    def run(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   147
        """overridden from install_lib class"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   148
        install_lib.install_lib.run(self)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   149
        # create Products.__init__.py if needed
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   150
        if subpackage_of:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   151
            product_init = join(self.install_dir, subpackage_of, '__init__.py')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   152
            if not exists(product_init):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   153
                self.announce('creating %s' % product_init)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   154
                stream = open(product_init, 'w')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   155
                stream.write(EMPTY_FILE)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   156
                stream.close()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   157
        # manually install included directories if any
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   158
        if include_dirs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   159
            if subpackage_of:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   160
                base = join(subpackage_of, modname)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   161
            else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   162
                base = modname
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   163
            for directory in include_dirs:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   164
                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
   165
                export(directory, dest, verbose=False)
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
   166
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   167
# write required share/cubicweb/cubes/__init__.py
6506
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   168
class MyInstallData(install_data.install_data):
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   169
    """A class That manages data files installation"""
6506
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   170
    def run(self):
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   171
        """overridden from install_data class"""
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   172
        install_data.install_data.run(self)
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   173
        path = join(self.install_dir, 'share', 'cubicweb', 'cubes', '__init__.py')
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   174
        ini = open(path, 'w')
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   175
        ini.write('# Cubicweb cubes directory\n')
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   176
        ini.close()
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   177
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   178
# re-enable copying data files in sys.prefix
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   179
if USE_SETUPTOOLS:
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   180
    # overwrite MyInstallData to use sys.prefix instead of the egg directory
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   181
    MyInstallMoreData = MyInstallData
7879
9aae456abab5 [pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6836
diff changeset
   182
    class MyInstallData(MyInstallMoreData): # pylint: disable=E0102
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   183
        """A class that manages data files installation"""
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   184
        def run(self):
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   185
            _old_install_dir = self.install_dir
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   186
            if self.install_dir.endswith('egg'):
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   187
                self.install_dir = sys.prefix
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   188
            MyInstallMoreData.run(self)
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   189
            self.install_dir = _old_install_dir
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   190
    try:
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   191
        import setuptools.command.easy_install # only if easy_install avaible
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   192
        # monkey patch: Crack SandboxViolation verification
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   193
        from setuptools.sandbox import DirectorySandbox as DS
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   194
        old_ok = DS._ok
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   195
        def _ok(self, path):
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   196
            """Return True if ``path`` can be written during installation."""
6836
fb3633142d8f [pkg] fix small bug appearing on Windows
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6537
diff changeset
   197
            out = old_ok(self, path) # here for side effect from setuptools
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   198
            realpath = os.path.normcase(os.path.realpath(path))
6836
fb3633142d8f [pkg] fix small bug appearing on Windows
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6537
diff changeset
   199
            allowed_path = os.path.normcase(sys.prefix)
fb3633142d8f [pkg] fix small bug appearing on Windows
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6537
diff changeset
   200
            if realpath.startswith(allowed_path):
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   201
                out = True
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   202
            return out
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   203
        DS._ok = _ok
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   204
    except ImportError:
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   205
        pass
6506
c1661ea815dc [packaging] add a __init__.py to cubes directory when installing data
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 6327
diff changeset
   206
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
def install(**kwargs):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   208
    """setup entry point"""
5353
cb8ac7263f8a [packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5329
diff changeset
   209
    if USE_SETUPTOOLS:
cb8ac7263f8a [packaging] fix setup.py for use w/ lgp
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5329
diff changeset
   210
        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
   211
            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
   212
    # 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
   213
    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
   214
        sys.argv.remove('--install-layout=deb')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   215
    if subpackage_of:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   216
        package = subpackage_of + '.' + modname
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   217
        kwargs['package_dir'] = {package : '.'}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   218
        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
   219
        if USE_SETUPTOOLS:
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
   220
            kwargs['namespace_packages'] = [subpackage_of]
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   221
    else:
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   222
        kwargs['package_dir'] = {modname : '.'}
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   223
        packages = [modname] + get_packages(os.getcwd(), modname)
5329
a8cd0570e3d6 [packaging] setup.py cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5024
diff changeset
   224
    if USE_SETUPTOOLS:
5512
e23d681193cd cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   225
        kwargs['install_requires'] = install_requires
6534
eb8dd7b0bd9d [pkg] no zipped egg
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6517
diff changeset
   226
        kwargs['zip_safe'] = False
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   227
    kwargs['packages'] = packages
6516
6b2e1e8d3a22 [pkg] use argument *package_data*
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6508
diff changeset
   228
    kwargs['package_data'] = package_data
5024
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
   229
    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
   230
                 description=description, long_description=long_description,
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
   231
                 author=author, author_email=author_email,
9e718abe3fde add egg support with dependencies auto-installation
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 4721
diff changeset
   232
                 scripts=ensure_scripts(scripts), data_files=data_files,
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   233
                 ext_modules=ext_modules,
6517
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   234
                 cmdclass={'install_lib': MyInstallLib,
c991ad161d8f [pkg] force copying data files in sys.path
Alain Leufroy <alain.leufroy@logilab.fr>
parents: 6516
diff changeset
   235
                           'install_data': MyInstallData},
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
                 **kwargs
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   237
                 )
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
   238
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   239
if __name__ == '__main__' :
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   240
    install()