forked from kytos/python-openflow
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
178 lines (138 loc) · 4.94 KB
/
setup.py
File metadata and controls
178 lines (138 loc) · 4.94 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""Setup script.
Run "python3 setup --help-commands" to list all available commands and their
descriptions.
"""
import sys
from abc import abstractmethod
# Disabling checks due to https://github.com/PyCQA/pylint/issues/73
# pylint: disable=import-error,no-name-in-module,unspecified-encoding
# pylint: disable=consider-using-with
# 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.
"""
def run_command(self, command):
"""Run another command with same __init__ arguments."""
command(*self.__args, **self.__kwargs).run()
def initialize_options(self):
"""Set default values for options."""
def finalize_options(self):
"""Post-process options."""
# pylint: disable=attribute-defined-outside-init, abstract-method
class TestCommand(Command):
"""Test tags decorators."""
user_options = [
("k=", None, "Specify a pytest -k expression."),
]
def get_args(self):
"""Return args to be used in test command."""
if self.k:
return f"-k '{self.k}'"
return ""
def initialize_options(self):
"""Set default size and type args."""
self.k = ""
def finalize_options(self):
"""Post-process."""
pass
class Cleaner(SimpleCommand):
"""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."""
call('make clean', shell=True)
class Test(TestCommand):
"""Run all tests."""
description = "run tests and display results"
def run(self):
"""Run tests."""
cmd = f"python3 -m pytest tests/ {self.get_args()}"
try:
check_call(cmd, shell=True)
except CalledProcessError as exc:
print(exc)
print('Unit tests failed. Fix the errors above and try again.')
sys.exit(-1)
class TestCoverage(Test):
"""Display test coverage."""
description = "run tests and display code coverage"
def run(self):
"""Run tests quietly and display coverage report."""
cmd = f"python3 -m pytest --cov=. tests/ {self.get_args()}"
try:
check_call(cmd, shell=True)
except CalledProcessError as exc:
print(exc)
print('Coverage tests failed. Fix the errors above and try again.')
sys.exit(-1)
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 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.')
sys.exit(-1)
setup(name='python-openflow',
version=__version__,
description='Library to parse and generate OpenFlow messages',
long_description=open("README.rst", "r").read(),
url='http://github.com/kytos/python-openflow',
author='Kytos Team',
author_email='devel@lists.kytos.io',
license='MIT',
test_suite='tests',
include_package_data=True,
extras_require={'dev': [
'pip-tools >= 2.0',
'pytest==8.0.1',
'pytest-cov==4.1.0',
'pytest-asyncio==0.23.5',
'black==24.2.0',
'isort==5.13.2',
'pylint==3.1.0',
'pycodestyle==2.11.1',
'yala==3.2.0',
'tox==4.13.0',
'virtualenv==20.25.1',
]},
packages=find_packages(exclude=['tests']),
cmdclass={
'clean': Cleaner,
'coverage': TestCoverage,
'doctest': DocTest,
'lint': Linter,
'test': Test
},
zip_safe=False,
classifiers=[
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.11',
'Topic :: System :: Networking',
'Topic :: Software Development :: Libraries'
])