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

PyTestCommand   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %
Metric Value
dl 0
loc 7
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A run_tests() 0 5 1
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
54
class PyTestCommand(TestCommand):
55
56
    def run_tests(self):
57
        # import here, cause outside the eggs aren't loaded
58
        import pytest
59
        errno = pytest.main([])
60
        sys.exit(errno)
61
62
63
# Generate API documentation only if we are running on readthedocs.org
64
on_rtd = getenv('READTHEDOCS', None) != None
65
if on_rtd:
66
    call(['sphinx-apidoc', '-f', '-o', 'docs/API/', '.'])
67
68
with open('requirements.txt') as requirements:
69
    required = requirements.read().splitlines()
70
71
with open('test-requirements.txt') as requirements:
72
    test_required = requirements.read().splitlines()
73
74
75
if __name__ == "__main__":
76
    download('http://sourceforge.net/projects/checkstyle/files/checkstyle/'
77
             '6.15/checkstyle-6.15-all.jar',
78
             'bears/java/checkstyle.jar')
79
    data_files = [('.', ['coala.1']), ('.', [Constants.BUS_NAME + '.service'])]
80
81
    setup(name='coala',
82
          version=Constants.VERSION,
83
          description='Code Analysis Application (coala)',
84
          author="The coala developers",
85
          maintainer=["Lasse Schuirmann, Fabian Neuschmidt, Mischa Kr\xfcger"
86
                      if not on_rtd else "L.S., F.N., M.K."],
87
          maintainer_email=('[email protected], '
88
                            '[email protected], '
89
                            '[email protected]'),
90
          url='http://coala.rtfd.org/',
91
          platforms='any',
92
          packages=find_packages(exclude=["build.*", "*.tests.*", "*.tests"]),
93
          install_requires=required,
94
          tests_require=test_required,
95
          package_data={'coalib': ['default_coafile', "VERSION"],
96
                        'bears.java': ['checkstyle.jar', 'google_checks.xml']},
97
          license="AGPL-3.0",
98
          data_files=data_files,
99
          long_description="coala is a simple COde AnaLysis Application. Its "
100
                           "goal is to make static code analysis easy while "
101
                           "remaining completely modular and therefore "
102
                           "extendable and language independent. Code analysis"
103
                           " happens in python scripts while coala manages "
104
                           "these, tries to provide helpful libraries and "
105
                           "provides a user interface. Please visit "
106
                           "http://coala.rtfd.org/ for more information or our"
107
                           "development repository on "
108
                           "https://github.com/coala-analyzer/coala/.",
109
          entry_points={
110
              "console_scripts": [
111
                  "coala = coalib.coala:main",
112
                  "coala-ci = coalib.coala_ci:main",
113
                  "coala-dbus = coalib.coala_dbus:main",
114
                  "coala-json = coalib.coala_json:main",
115
                  "coala-format = coalib.coala_format:main",
116
                  "coala-delete-orig = coalib.coala_delete_orig:main"]},
117
          # from http://pypi.python.org/pypi?%3Aaction=list_classifiers
118
          classifiers=[
119
              'Development Status :: 3 - Alpha',
120
121
              'Environment :: Console',
122
              'Environment :: MacOS X',
123
              'Environment :: Win32 (MS Windows)',
124
              'Environment :: X11 Applications :: Gnome',
125
126
              'Intended Audience :: Science/Research',
127
              'Intended Audience :: Developers',
128
129
              'License :: OSI Approved :: GNU Affero General Public License '
130
              'v3 or later (AGPLv3+)',
131
132
              'Operating System :: OS Independent',
133
134
              'Programming Language :: Python :: Implementation :: CPython',
135
              'Programming Language :: Python :: 3.3',
136
              'Programming Language :: Python :: 3.4',
137
              'Programming Language :: Python :: 3.5',
138
              'Programming Language :: Python :: 3 :: Only',
139
140
              'Topic :: Scientific/Engineering :: Information Analysis',
141
              'Topic :: Software Development :: Quality Assurance',
142
              'Topic :: Text Processing :: Linguistic'],
143
          cmdclass={'build_manpage': BuildManPage,
144
                    'build_dbus': BuildDbusService,
145
                    'build_py': BuildPyCommand,
146
                    'test': PyTestCommand})
147