Completed
Pull Request — master (#1336)
by Abdeali
01:42
created

PyTestCommand.run_tests()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

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