setup.py 7.44 KB
Newer Older
Christophe Benz's avatar
Christophe Benz committed
1 2 3
#! /usr/bin/env python
# -*- coding: utf-8 -*-

4
# Copyright(C) 2010-2014 Christophe Benz, Laurent Bachelier
5
#
6
# This file is part of weboob.
7
#
8 9 10 11 12 13
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15 16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
17
#
18 19
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
20

21
from __future__ import print_function
Christophe Benz's avatar
Christophe Benz committed
22

23
import glob
Christophe Benz's avatar
Christophe Benz committed
24
import os
25 26 27
import subprocess
import sys

28 29
from setuptools import find_packages, setup

30

31 32 33 34 35 36 37 38 39 40 41 42
def find_executable(name, names):
    envname = '%s_EXECUTABLE' % name.upper()
    if os.getenv(envname):
        return os.getenv(envname)
    paths = os.getenv('PATH', os.defpath).split(os.pathsep)
    exts = os.getenv('PATHEXT', os.pathsep).split(os.pathsep)
    for name in names:
        for path in paths:
            for ext in exts:
                fpath = os.path.join(path, name) + ext
                if os.path.exists(fpath) and os.access(fpath, os.X_OK):
                    return fpath
Romain Bignon's avatar
Romain Bignon committed
43
    print('Could not find executable: %s' % name, file=sys.stderr)
44

45

46
def build_qt():
Romain Bignon's avatar
Romain Bignon committed
47
    print('Building Qt applications...', file=sys.stderr)
48
    make = find_executable('make', ('gmake', 'make'))
49
    pyuic5 = find_executable('pyuic5', ('python2-pyuic5', 'pyuic5-python2.7', 'pyuic5'))
50
    if not pyuic5 or not make:
Romain Bignon's avatar
Romain Bignon committed
51
        print('Install missing component(s) (see above) or disable Qt applications (with --no-qt).', file=sys.stderr)
52
        sys.exit(1)
53

54 55 56 57 58
    subprocess.check_call(
        [make,
         '-f', 'build.mk',
         '-s', '-j2',
         'all',
59
         'PYUIC=%s%s' % (pyuic5, ' WIN32=1' if sys.platform == 'win32' else '')])
60

61

62 63
def install_weboob():
    scripts = set(os.listdir('scripts'))
64
    packages = set(find_packages(exclude=['modules', 'modules.*']))
65 66

    hildon_scripts = set(('masstransit',))
67 68
    qt_scripts = set(('qboobmsg',
                      'qhavedate',
Vincent A's avatar
Vincent A committed
69
                      'qgalleroob',
70 71 72 73 74 75
                      'qvideoob',
                      'weboob-config-qt',
                      'qwebcontentedit',
                      'qflatboob',
                      'qcineoob',
                      'qcookboob',
76
                      'qbooblyrics',
77
                      'qhandjoob'))
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    if not options.hildon:
        scripts = scripts - hildon_scripts
    if options.qt:
        build_qt()
    else:
        scripts = scripts - qt_scripts

    hildon_packages = set((
        'weboob.applications.masstransit',
    ))
    qt_packages = set((
        'weboob.applications.qboobmsg',
        'weboob.applications.qboobmsg.ui',
        'weboob.applications.qcineoob',
        'weboob.applications.qcineoob.ui',
        'weboob.applications.qcookboob',
        'weboob.applications.qcookboob.ui',
96 97
        'weboob.applications.qbooblyrics',
        'weboob.applications.qbooblyrics.ui',
98 99 100 101 102 103 104 105 106 107 108
        'weboob.applications.qhandjoob',
        'weboob.applications.qhandjoob.ui',
        'weboob.applications.qhavedate',
        'weboob.applications.qhavedate.ui',
        'weboob.applications.qvideoob',
        'weboob.applications.qvideoob.ui',
        'weboob.applications.qweboobcfg',
        'weboob.applications.qweboobcfg.ui',
        'weboob.applications.qwebcontentedit',
        'weboob.applications.qwebcontentedit.ui'
        'weboob.applications.qflatboob',
Vincent A's avatar
Vincent A committed
109 110 111
        'weboob.applications.qflatboob.ui',
        'weboob.applications.qgalleroob',
        'weboob.applications.qgalleroob.ui',
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    ))

    if not options.hildon:
        packages = packages - hildon_packages
    if not options.qt:
        packages = packages - qt_packages

    data_files = [
        ('share/man/man1', glob.glob('man/*')),
    ]
    if options.xdg:
        data_files.extend([
            ('share/applications', glob.glob('desktop/*')),
            ('share/icons/hicolor/64x64/apps', glob.glob('icons/*')),
        ])

    # Do not put PyQt, it does not work properly.
    requirements = [
        'lxml',
131
        'cssselect',
132
        'requests>=2.0.0',
133 134
        'python-dateutil',
        'PyYAML',
135
        'html2text>=3.200',
136
        'six',
137
        'unidecode',
138 139 140 141 142 143
    ]
    try:
        import Image
    except ImportError:
        requirements.append('Pillow')
    else:
144 145
        # detect Pillow-only feature, or weird Debian stuff
        if hasattr(Image, 'alpha_composite') or 'PILcompat' in Image.__file__:
146
            requirements.append('Pillow')
147 148
        else:
            requirements.append('PIL')
149

150 151 152 153 154 155
    if sys.version_info < (3, 0):
        requirements.append('mechanize')

    if sys.version_info < (3, 2):
        requirements.append('futures')

156 157
    if sys.version_info < (2, 7):
        print('Python older than 2.7 is not supported.', file=sys.stderr)
158 159 160 161 162
        sys.exit(1)

    if not options.deps:
        requirements = []

163 164 165 166 167 168 169
    try:
        if sys.argv[1] == 'requirements':
            print('\n'.join(requirements))
            sys.exit(0)
    except IndexError:
        pass

170 171
    setup(
        name='weboob',
Florent Fourcot's avatar
Florent Fourcot committed
172
        version='1.4',
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        description='Weboob, Web Outside Of Browsers',
        long_description=open('README').read(),
        author='Romain Bignon',
        author_email='weboob@weboob.org',
        maintainer='Romain Bignon',
        maintainer_email='romain@weboob.org',
        url='http://weboob.org/',
        license='GNU AGPL 3',
        classifiers=[
            'Environment :: Console',
            'Environment :: X11 Applications :: Qt',
            'License :: OSI Approved :: GNU Affero General Public License v3',
            'Programming Language :: Python :: 2.7',
            'Programming Language :: Python',
            'Topic :: Communications :: Email',
            'Topic :: Internet :: WWW/HTTP',
        ],

        packages=packages,
        scripts=[os.path.join('scripts', script) for script in scripts],
        data_files=data_files,

        install_requires=requirements,
196 197 198 199 200 201 202
        python_requires='>=2.7',
        tests_require=[
            'flake8',
            'nose',
            'xunitparser',
            'coverage',
        ],
203 204
    )

205

206
class Options(object):
207
    hildon = False
Romain Bignon's avatar
Romain Bignon committed
208
    qt = False
209
    xdg = True
210
    deps = True
211

212 213 214
options = Options()

args = list(sys.argv)
215
if '--hildon' in args and '--no-hildon' in args:
Romain Bignon's avatar
Romain Bignon committed
216
    print('--hildon and --no-hildon options are incompatible', file=sys.stderr)
217
    sys.exit(1)
218
if '--qt' in args and '--no-qt' in args:
Romain Bignon's avatar
Romain Bignon committed
219
    print('--qt and --no-qt options are incompatible', file=sys.stderr)
220
    sys.exit(1)
221
if '--xdg' in args and '--no-xdg' in args:
Romain Bignon's avatar
Romain Bignon committed
222
    print('--xdg and --no-xdg options are incompatible', file=sys.stderr)
223
    sys.exit(1)
224

225
if '--hildon' in args or os.environ.get('HILDON') == 'true':
226
    options.hildon = True
227 228
    if '--hildon' in args:
        args.remove('--hildon')
229 230 231 232
elif '--no-hildon' in args:
    options.hildon = False
    args.remove('--no-hildon')

233 234 235 236 237 238 239
if '--qt' in args:
    options.qt = True
    args.remove('--qt')
elif '--no-qt' in args:
    options.qt = False
    args.remove('--no-qt')

240 241 242 243 244 245 246
if '--xdg' in args:
    options.xdg = True
    args.remove('--xdg')
elif '--no-xdg' in args:
    options.xdg = False
    args.remove('--no-xdg')

247 248 249 250
if '--nodeps' in args:
    options.deps = False
    args.remove('--nodeps')

251
sys.argv = args
Christophe Benz's avatar
Christophe Benz committed
252

253
install_weboob()