Completed
Pull Request — master (#1284)
by Lasse
01:53
created

download()   A

Complexity

Conditions 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 19
rs 9.2
1
#!/usr/bin/env python3
2
3
from urllib.request import urlopen
4
from shutil import copyfileobj
5
from os.path import exists
6
from sys import stdout
7
from setuptools import setup, find_packages
8
import setuptools.command.build_py
9
10
from coalib import assert_supported_version
11
assert_supported_version()
12
from coalib.misc.BuildManPage import BuildManPage
13
from coalib.output.dbus.BuildDbusService import BuildDbusService
14
from coalib.misc import Constants
15
16
17
def download(url: str, filename: str, overwrite: bool=False):
18
    """
19
    Downloads the given URL to the given filename. If the file exists, it won't
20
    be downloaded.
21
22
    :param url:       A URL to download.
23
    :param filename:  The file to store the downloaded file to.
24
    :param overwrite: Set to True if the file should be downloaded even if it
25
                      already exists.
26
    :return:          The filename.
27
    """
28
    if not exists(filename) or overwrite:
29
        print("Downloading", filename + "...", end='')
30
        stdout.flush()
31
        with urlopen(url) as response, open(filename, 'wb') as out_file:
32
            copyfileobj(response, out_file)
33
        print(" DONE.")
34
35
    return filename
36
37
38
class BuildPyCommand(setuptools.command.build_py.build_py):
39
40
    def run(self):
41
        self.run_command('build_manpage')
42
        self.run_command('build_dbus')
43
        setuptools.command.build_py.build_py.run(self)
44
45
46
with open('requirements.txt') as requirements:
47
    required = requirements.read().splitlines()
48
49
50
if __name__ == "__main__":
51
    maintainers = "Lasse Schuirmann, Fabian Neuschmidt, Mischa Kr\xfcger"
52
    maintainer_mails = ('[email protected], '
53
                        '[email protected], '
54
                        '[email protected]')
55
    data_files = [
56
        ('.', ['coala.1']),
57
        ('.', [Constants.BUS_NAME + '.service']),
58
        ('bears/java', [download('http://repo1.maven.org/maven2/com/puppycrawl/'
59
                                 'tools/checkstyle/6.9/checkstyle-6.9.jar',
60
                                 'bears/java/checkstyle.jar')])]
61
62
    setup(name='coala',
63
          version=Constants.VERSION,
64
          description='Code Analysis Application (coala)',
65
          author="The coala developers",
66
          maintainer=maintainers,
67
          maintainer_email=maintainer_mails,
68
          url='http://coala.rtfd.org/',
69
          platforms='any',
70
          packages=find_packages(exclude=["build.*", "*.tests.*", "*.tests"]),
71
          install_requires=required,
72
          package_data={'coalib': ['default_coafile', "VERSION"]},
73
          license="AGPL v3",
74
          data_files=data_files,
75
          long_description="coala is a simple COde AnaLysis Application. Its "
76
                           "goal is to make static code analysis easy while "
77
                           "remaining completely modular and therefore "
78
                           "extendable and language independent. Code analysis"
79
                           " happens in python scripts while coala manages "
80
                           "these, tries to provide helpful libraries and "
81
                           "provides a user interface. Please visit "
82
                           "http://coala.rtfd.org/ for more information or our"
83
                           "development repository on "
84
                           "https://github.com/coala-analyzer/coala/.",
85
          entry_points={
86
              "console_scripts": [
87
                  "coala = coalib.coala:main",
88
                  "coala-ci = coalib.coala_ci:main",
89
                  "coala-dbus = coalib.coala_dbus:main",
90
                  "coala-json = coalib.coala_json:main",
91
                  "coala-format = coalib.coala_format:main"]},
92
          # from http://pypi.python.org/pypi?%3Aaction=list_classifiers
93
          classifiers=[
94
              'Development Status :: 3 - Alpha',
95
96
              'Environment :: Console',
97
              'Environment :: MacOS X',
98
              'Environment :: Win32 (MS Windows)',
99
              'Environment :: X11 Applications :: Gnome',
100
101
              'Intended Audience :: Science/Research',
102
              'Intended Audience :: Developers',
103
104
              'License :: OSI Approved :: GNU Affero General Public License '
105
              'v3 or later (AGPLv3+)',
106
107
              'Operating System :: OS Independent',
108
109
              'Programming Language :: Python :: Implementation :: CPython',
110
              'Programming Language :: Python :: 3.3',
111
              'Programming Language :: Python :: 3.4',
112
              'Programming Language :: Python :: 3.5',
113
              'Programming Language :: Python :: 3 :: Only',
114
115
              'Topic :: Scientific/Engineering :: Information Analysis',
116
              'Topic :: Software Development :: Quality Assurance',
117
              'Topic :: Text Processing :: Linguistic'],
118
          cmdclass={'build_manpage': BuildManPage,
119
                    'build_dbus': BuildDbusService,
120
                    'build_py': BuildPyCommand})
121