|
1 | 1 | #! /usr/bin/env python |
2 | 2 |
|
3 | | -from setuptools import setup |
| 3 | +from setuptools import setup, Command |
| 4 | +from setuptools.command.test import test as TestCommand |
| 5 | +from subprocess import check_call |
| 6 | +from multiprocessing import cpu_count |
| 7 | +from distutils.spawn import find_executable |
| 8 | + |
| 9 | + |
| 10 | +class Test(TestCommand): |
| 11 | + def run_tests(self): |
| 12 | + check_call(('./cpplint_unittest.py')) |
| 13 | + check_call(('./cpplint_clitest.py')) |
| 14 | + |
| 15 | + |
| 16 | +class Cmd(Command): |
| 17 | + user_options = [ |
| 18 | + ('executable', 'e', 'The executable to use for the command') |
| 19 | + ] |
| 20 | + |
| 21 | + def initialize_options(self): |
| 22 | + self.executable = find_executable(self.executable) |
| 23 | + |
| 24 | + def finalize_options(self): |
| 25 | + pass |
| 26 | + |
| 27 | + def execute(self, *k): |
| 28 | + check_call((self.executable,) + k) |
| 29 | + |
| 30 | + |
| 31 | +class Lint(Cmd): |
| 32 | + description = 'Run linting of the code' |
| 33 | + user_options = Cmd.user_options + [ |
| 34 | + ('jobs', 'j', 'Use multiple processes to speed up the linting') |
| 35 | + ] |
| 36 | + executable = 'pylint' |
| 37 | + |
| 38 | + def initialize_options(self): |
| 39 | + self.jobs = cpu_count() |
| 40 | + |
| 41 | + def finalize_options(self): |
| 42 | + self.jobs = int(self.jobs) |
| 43 | + if self.jobs < 1: |
| 44 | + raise ValueError('Jobs must be one or larger') |
| 45 | + |
| 46 | + def run(self): |
| 47 | + self.execute('-j', str(self.jobs), 'cpplint.py') |
| 48 | + |
| 49 | + |
| 50 | +class Format(Cmd): |
| 51 | + description = 'Formats the code' |
| 52 | + executable = 'yapf' |
| 53 | + |
| 54 | + def run(self): |
| 55 | + self.execute('--parallel', '--in-place', 'cpplint.py') |
| 56 | + |
4 | 57 |
|
5 | 58 | setup(name='cpplint', |
6 | 59 | version='1.3.0', |
|
15 | 68 | url='http://en.wikipedia.org/wiki/Cpplint', |
16 | 69 | download_url='https://github.com/cpplint/cpplint', |
17 | 70 | keywords=['lint', 'python', 'c++'], |
18 | | - maintainer = 'cpplint Developers', |
19 | | - maintainer_email = 'see_github@nospam.com', |
| 71 | + maintainer='cpplint Developers', |
| 72 | + maintainer_email='see_github@nospam.com', |
20 | 73 | classifiers=['Programming Language :: Python', |
21 | 74 | 'Programming Language :: Python :: 2', |
22 | 75 | 'Programming Language :: Python :: 2.7', |
|
38 | 91 | 'flake8', |
39 | 92 | 'yapf', |
40 | 93 | ] |
| 94 | + }, |
| 95 | + cmdclass={ |
| 96 | + 'test': Test, |
| 97 | + 'lint': Lint, |
| 98 | + 'format': Format |
41 | 99 | }) |
0 commit comments