forked from kytos/python-openflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
144 lines (110 loc) · 4.07 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""Setup script.
Run "python3 setup --help-commands" to list all available commands and their
descriptions.
"""
from abc import abstractmethod
# Disabling checks due to https://github.com/PyCQA/pylint/issues/73
# pylint: disable=import-error,no-name-in-module
from distutils.command.clean import clean
# pylint: enable=import-error,no-name-in-module
from subprocess import CalledProcessError, call, check_call
from setuptools import Command, find_packages, setup
from pyof import __version__
class SimpleCommand(Command):
"""Make Command implementation simpler."""
user_options = []
def __init__(self, *args, **kwargs):
"""Store arguments so it's possible to call other commands later."""
super().__init__(*args, **kwargs)
self.__args = args
self.__kwargs = kwargs
@abstractmethod
def run(self):
"""Run when command is invoked.
Use *call* instead of *check_call* to ignore failures.
"""
pass
def run_command(self, command_class):
"""Run another command with same __init__ arguments."""
command_class(*self.__args, **self.__kwargs).run()
def initialize_options(self):
"""Set defa ult values for options."""
pass
def finalize_options(self):
"""Post-process options."""
pass
class Cleaner(clean):
"""Custom clean command to tidy up the project root."""
description = 'clean build, dist, pyc and egg from package and docs'
def run(self):
"""Clean build, dist, pyc and egg from package and docs."""
super().run()
call('rm -vrf ./build ./dist ./*.pyc ./*.egg-info', shell=True)
call('find . -name __pycache__ -type d | xargs rm -rf', shell=True)
call('test -d docs && make -C docs/ clean', shell=True)
class TestCoverage(SimpleCommand):
"""Display test coverage."""
description = 'run unit tests and display code coverage'
def run(self):
"""Run unittest quietly and display coverage report."""
cmd = 'coverage3 run setup.py test && coverage3 report'
check_call(cmd, shell=True)
class DocTest(SimpleCommand):
"""Run documentation tests."""
description = 'run documentation tests'
def run(self):
"""Run doctests using Sphinx Makefile."""
cmd = 'make -C docs/ default doctest'
check_call(cmd, shell=True)
class CITest(SimpleCommand):
"""Run all CI tests."""
description = 'run all CI tests: unit and doc tests, linter'
def run(self):
"""Run unit tests with coverage, doc tests and linter."""
for command in TestCoverage, DocTest, Linter:
self.run_command(command)
class Linter(SimpleCommand):
"""Lint Python source code."""
description = 'lint Python source code'
def run(self):
"""Run yala."""
print('Yala is running. It may take several seconds...')
try:
check_call('yala pyof setup.py', shell=True)
print('No linter error found.')
except CalledProcessError:
print('Linter check failed. Fix the error(s) above and try again.')
exit(-1)
setup(name='python-openflow',
version=__version__,
description='Library to parse and generate OpenFlow messages',
url='http://github.com/kytos/python-openflow',
author='Kytos Team',
author_email='[email protected]',
license='MIT',
test_suite='tests',
include_package_data=True,
extras_require={
'dev': [
'coverage',
'tox',
'pip-tools',
'yala',
],
},
packages=find_packages(exclude=['tests']),
cmdclass={
'ci': CITest,
'clean': Cleaner,
'coverage': TestCoverage,
'doctest': DocTest,
'lint': Linter
},
zip_safe=False,
classifiers=[
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.6',
'Topic :: System :: Networking',
'Topic :: Software Development :: Libraries'
])