Completed
Pull Request — master (#1487)
by Lasse
01:38
created

BuildDocsCommand.run()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 3
rs 10
1
#!/usr/bin/env python3
2
3
import locale
4
import sys
5
from os import getenv
6
from os.path import exists
7
from shutil import copyfileobj
8
from subprocess import call
9
from urllib.request import urlopen
10
11
# Start ignoring PyImportSortBear as imports below may yield syntax errors
12
from coalib import assert_supported_version
13
14
assert_supported_version()
15
# Stop ignoring
16
17
import setuptools.command.build_py
18
from coalib.misc import Constants
19
from coalib.misc.BuildManPage import BuildManPage
20
from coalib.output.dbus.BuildDbusService import BuildDbusService
21
from setuptools import find_packages, setup
22
from setuptools.command.test import test as TestCommand
23
24
try:
25
    locale.getlocale()
26
except (ValueError, UnicodeError):
27
    locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
28
29
30
def download(url, filename, overwrite=False):
31
    """
32
    Downloads the given URL to the given filename. If the file exists, it won't
33
    be downloaded.
34
35
    :param url:       A URL to download.
36
    :param filename:  The file to store the downloaded file to.
37
    :param overwrite: Set to True if the file should be downloaded even if it
38
                      already exists.
39
    :return:          The filename.
40
    """
41
    if not exists(filename) or overwrite:
42
        print("Downloading", filename + "...")
43
        with urlopen(url) as response, open(filename, 'wb') as out_file:
44
            copyfileobj(response, out_file)
45
        print("DONE.")
46
47
    return filename
48
49
50
class BuildPyCommand(setuptools.command.build_py.build_py):
51
52
    def run(self):
53
        self.run_command('build_manpage')
54
        self.run_command('build_dbus')
55
        setuptools.command.build_py.build_py.run(self)
56
57
58
class PyTestCommand(TestCommand):
59
60
    def run_tests(self):
61
        # import here, cause outside the eggs aren't loaded
62
        import pytest
63
        errno = pytest.main([])
64
        sys.exit(errno)
65
66
67
class BuildDocsCommand(setuptools.command.build_py.build_py):
68
69
    def run(self):
70
        call(['sphinx-apidoc', '-f', '-o', 'docs/API/', '.'])
71
        call(['make', '-C', 'docs', 'html'])
72
73
74
# Generate API documentation only if we are running on readthedocs.org
75
on_rtd = getenv('READTHEDOCS', None) != None
76
if on_rtd:
77
    call(['sphinx-apidoc', '-f', '-o', 'docs/API/', '.'])
78
79
with open('requirements.txt') as requirements:
80
    required = requirements.read().splitlines()
81
82
with open('test-requirements.txt') as requirements:
83
    test_required = requirements.read().splitlines()
84
85
86
if __name__ == "__main__":
87
    download('http://sourceforge.net/projects/checkstyle/files/checkstyle/'
88
             '6.15/checkstyle-6.15-all.jar',
89
             'bears/java/checkstyle.jar')
90
    data_files = [('.', ['coala.1']), ('.', [Constants.BUS_NAME + '.service'])]
91
92
    setup(name='coala',
93
          version=Constants.VERSION,
94
          description='Code Analysis Application (coala)',
95
          author="The coala developers",
96
          maintainer=["Lasse Schuirmann, Fabian Neuschmidt, Mischa Kr\xfcger"
97
                      if not on_rtd else "L.S., F.N., M.K."],
98
          maintainer_email=('[email protected], '
99
                            '[email protected], '
100
                            '[email protected]'),
101
          url='http://coala.rtfd.org/',
102
          platforms='any',
103
          packages=find_packages(exclude=["build.*", "*.tests.*", "*.tests"]),
104
          install_requires=required,
105
          tests_require=test_required,
106
          package_data={'coalib': ['default_coafile', "VERSION"],
107
                        'bears.java': ['checkstyle.jar', 'google_checks.xml']},
108
          license="AGPL-3.0",
109
          data_files=data_files,
110
          long_description="coala is a simple COde AnaLysis Application. Its "
111
                           "goal is to make static code analysis easy while "
112
                           "remaining completely modular and therefore "
113
                           "extendable and language independent. Code analysis"
114
                           " happens in python scripts while coala manages "
115
                           "these, tries to provide helpful libraries and "
116
                           "provides a user interface. Please visit "
117
                           "http://coala.rtfd.org/ for more information or "
118
                           "our development repository on "
119
                           "https://github.com/coala-analyzer/coala/.",
120
          entry_points={
121
              "console_scripts": [
122
                  "coala = coalib.coala:main",
123
                  "coala-ci = coalib.coala_ci:main",
124
                  "coala-dbus = coalib.coala_dbus:main",
125
                  "coala-json = coalib.coala_json:main",
126
                  "coala-format = coalib.coala_format:main",
127
                  "coala-delete-orig = coalib.coala_delete_orig:main"]},
128
          # from http://pypi.python.org/pypi?%3Aaction=list_classifiers
129
          classifiers=[
130
              'Development Status :: 4 - Beta',
131
132
              'Environment :: Console',
133
              'Environment :: MacOS X',
134
              'Environment :: Win32 (MS Windows)',
135
              'Environment :: X11 Applications :: Gnome',
136
137
              'Intended Audience :: Science/Research',
138
              'Intended Audience :: Developers',
139
140
              'License :: OSI Approved :: GNU Affero General Public License '
141
              'v3 or later (AGPLv3+)',
142
143
              'Operating System :: OS Independent',
144
145
              'Programming Language :: Python :: Implementation :: CPython',
146
              'Programming Language :: Python :: 3.3',
147
              'Programming Language :: Python :: 3.4',
148
              'Programming Language :: Python :: 3.5',
149
              'Programming Language :: Python :: 3 :: Only',
150
151
              'Topic :: Scientific/Engineering :: Information Analysis',
152
              'Topic :: Software Development :: Quality Assurance',
153
              'Topic :: Text Processing :: Linguistic'],
154
          cmdclass={'build_manpage': BuildManPage,
155
                    'build_dbus': BuildDbusService,
156
                    'build_py': BuildPyCommand,
157
                    'docs': BuildDocsCommand,
158
                    'test': PyTestCommand})
159