setup.py 7.58 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
#
Romain Bignon's avatar
Romain Bignon committed
6
# This file is part of weboob.
7
#
Romain Bignon's avatar
Romain Bignon committed
8
# weboob is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Lesser General Public License as published by
Romain Bignon's avatar
Romain Bignon committed
10
11
12
13
# 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
Romain Bignon's avatar
Romain Bignon committed
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Lesser General Public License for more details.
17
#
18
# You should have received a copy of the GNU Lesser General Public License
Romain Bignon's avatar
Romain Bignon committed
19
# 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
import subprocess
import sys
27
28
from distutils.cmd import Command
from distutils.log import WARN
29

30
31
from setuptools import find_packages, setup

32

33
34
35
PY3 = sys.version_info.major >= 3


36
37
38
39
40
41
42
43
44
45
46
47
48
class BuildQt(Command):
    description = 'build Qt applications'
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        self.announce('Building Qt applications...', WARN)
        make = self.find_executable('make', ('gmake', 'make'))
49
        if not PY3:
50
51
52
53
54
55
56
            pyuic5 = self.find_executable(
                'pyuic5',
                ('python2-pyuic5', 'pyuic5-python2.7', 'pyuic5'))
        else:
            pyuic5 = self.find_executable(
                'pyuic5',
                ('python3-pyuic5', 'pyuic5-python3.7', 'pyuic5-python3.6', 'pyuic5-python3.5', 'pyuic5'))
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        if not pyuic5 or not make:
            print('Install missing component(s) (see above) or disable Qt applications (with --no-qt).',
                  file=sys.stderr)
            sys.exit(1)

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

    @staticmethod
    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
        print('Could not find executable: %s' % name, file=sys.stderr)
83

84

85
def install_weboob(qt, xdg):
86
    scripts = set(os.listdir('scripts'))
87
    packages = set(find_packages(exclude=['modules', 'modules.*']))
88

89
90
    qt_scripts = set(('qboobmsg',
                      'qhavedate',
hydrargyrum's avatar
hydrargyrum committed
91
                      'qgalleroob',
92
                      'qboobtracker',
93
94
95
96
97
98
                      'qvideoob',
                      'weboob-config-qt',
                      'qwebcontentedit',
                      'qflatboob',
                      'qcineoob',
                      'qcookboob',
99
                      'qbooblyrics',
100
                      'qhandjoob'))
101

102
    if not qt:
103
104
105
106
107
108
109
110
111
        scripts = scripts - qt_scripts

    qt_packages = set((
        'weboob.applications.qboobmsg',
        'weboob.applications.qboobmsg.ui',
        'weboob.applications.qcineoob',
        'weboob.applications.qcineoob.ui',
        'weboob.applications.qcookboob',
        'weboob.applications.qcookboob.ui',
112
113
        'weboob.applications.qbooblyrics',
        'weboob.applications.qbooblyrics.ui',
114
115
116
117
118
119
120
121
122
123
124
        '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',
hydrargyrum's avatar
hydrargyrum committed
125
        'weboob.applications.qflatboob.ui',
126
127
        'weboob.applications.qboobtracker',
        'weboob.applications.qboobtracker.ui',
hydrargyrum's avatar
hydrargyrum committed
128
129
        'weboob.applications.qgalleroob',
        'weboob.applications.qgalleroob.ui',
130
131
    ))

132
    if not qt:
133
134
135
136
137
        packages = packages - qt_packages

    data_files = [
        ('share/man/man1', glob.glob('man/*')),
    ]
138
    if xdg:
139
140
141
142
143
144
145
146
        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',
147
        'cssselect',
148
        'requests>=2.0.0',
149
150
        'python-dateutil',
        'PyYAML',
151
        'html2text>=3.200',
152
        'six',
153
        'unidecode',
154
        'Pillow',
155
        'futures; python_version < "3.2"',
156
157
    ]

158
159
160
161
162
163
164
    try:
        if sys.argv[1] == 'requirements':
            print('\n'.join(requirements))
            sys.exit(0)
    except IndexError:
        pass

165
166
    setup(
        name='weboob',
Romain Bignon's avatar
Romain Bignon committed
167
        version='1.6',
168
        description='Weboob, Web Outside Of Browsers',
169
        long_description=open('README.md').read(),
170
171
172
173
174
        author='Romain Bignon',
        author_email='weboob@weboob.org',
        maintainer='Romain Bignon',
        maintainer_email='romain@weboob.org',
        url='http://weboob.org/',
175
        license='GNU LGPL 3',
176
177
178
        classifiers=[
            'Environment :: Console',
            'Environment :: X11 Applications :: Qt',
179
            'License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)',
Laurent Bachelier's avatar
Laurent Bachelier committed
180
181
            'Programming Language :: Python',
            'Programming Language :: Python :: 2',
182
            'Programming Language :: Python :: 2.7',
Laurent Bachelier's avatar
Laurent Bachelier committed
183
184
185
186
            'Programming Language :: Python :: 3',
            'Programming Language :: Python :: 3.5',
            'Programming Language :: Python :: 3.6',
            'Programming Language :: Python :: 3.7',
187
188
189
            'Programming Language :: Python',
            'Topic :: Communications :: Email',
            'Topic :: Internet :: WWW/HTTP',
Laurent Bachelier's avatar
Laurent Bachelier committed
190
191
192
193
            'Topic :: Internet :: WWW/HTTP :: Browsers',
            'Topic :: Software Development :: Libraries :: Application Frameworks',
            'Topic :: Software Development :: Libraries :: Python Modules',
            'Topic :: Text Processing :: Markup :: HTML',
194
195
196
197
198
199
200
        ],

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

        install_requires=requirements,
201
202
203
204
205
206
207
        python_requires='>=2.7',
        tests_require=[
            'flake8',
            'nose',
            'xunitparser',
            'coverage',
        ],
208
209
210
        cmdclass={
            'build_qt': BuildQt,
        },
211
212
    )

213

214
215
216
217
218
219
220
221
222
223
224
225
226
def extract_args(args, options, optlist):
    for option in optlist:
        yes = '--%s' % option
        no = '--no-%s' % option
        if yes in args and no in args:
            print('%s and %s options are incompatible' % (yes, no), file=sys.stderr)
            sys.exit(1)
        if yes in args:
            args.remove(yes)
            options[option] = True
        elif no in args:
            args.remove(no)
            options[option] = False
227

228

229
230
231
232
if os.getenv('WEBOOB_SETUP'):
    args = os.getenv('WEBOOB_SETUP').split()
else:
    args = sys.argv[1:]
233
234
235
236
237

options = {'qt': False, 'xdg': True}
extract_args(args, options, ('qt', 'xdg'))

if options['qt']:
238
239
240
    args.insert(0, 'build_qt')


241
sys.argv = [sys.argv[0]] + args
Christophe Benz's avatar
Christophe Benz committed
242

243
install_weboob(**options)