forked from kytos-ng/kytos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
240 lines (190 loc) · 7.27 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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
"""Setup script.
Run "python3 setup.py --help-commands" to list all available commands and their
descriptions.
"""
import os
import re
import sys
from abc import abstractmethod
# Disabling checks due to https://github.com/PyCQA/pylint/issues/73
from pathlib import Path
from subprocess import CalledProcessError, call, check_call
try:
# Check if pip is installed
# pylint: disable=unused-import
import pip # noqa
from setuptools import Command, find_packages, setup
from setuptools.command.egg_info import egg_info
except ModuleNotFoundError:
print('Please install python3-pip and run setup.py again.')
sys.exit(-1)
BASE_ENV = Path(os.environ.get('VIRTUAL_ENV', '/'))
ETC_FILES = []
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 initialize_options(self):
"""Set default values for options."""
def finalize_options(self):
"""Post-process options."""
class EggInfo(egg_info):
"""Prepare files to be packed."""
def run(self):
"""Build css."""
self._install_deps_wheels()
super().run()
@staticmethod
def _install_deps_wheels():
"""Python wheels are much faster (no compiling)."""
print('Installing dependencies...')
check_call([sys.executable, '-m', 'pip', 'install', '-r',
'requirements/run.txt'])
# 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):
"""Code linters."""
description = 'Lint Python source code'
def run(self):
"""Run yala."""
print('Yala is running. It may take several seconds...')
try:
check_call('yala setup.py kytos tests', shell=True)
print('No linter error found.')
except CalledProcessError:
print('Linter check failed. Fix the error(s) above and try again.')
sys.exit(-1)
# class InstallMode(install):
# """Class used to overwrite the default installation using setuptools."""
# def run(self):
# """Install the package in install mode.
# super().run() does not install dependencies when running
# ``python setup.py install`` (pypa/setuptools#456).
# """
# if 'bdist_wheel' in sys.argv:
# # do not use eggs, but wheels
# super().run()
# else:
# # force install of deps' eggs during setup.py install
# self.do_egg_install()
# class DevelopMode(develop):
# """Recommended setup for developers.
#
# The following feature are temporarily remove from code:
# Instead of copying the files to the expected directories, a symlink is
# created on the system aiming the current source code.
# """
#
# def run(self):
# """Install the package in a developer mode."""
# super().run()
# We are parsing the metadata file as if it was a text file because if we
# import it as a python module, necessarily the kytos.core module would be
# initialized, which means that kyots/core/__init__.py would be run and, then,
# kytos.core.controller.Controller would be called and it will try to import
# some modules that are dependencies from this project and that were not yet
# installed, since the requirements installation from this project hasn't yet
# happened.
META_FILE = open("kytos/core/metadata.py").read()
METADATA = dict(re.findall(r"(__[a-z]+__)\s*=\s*'([^']+)'", META_FILE))
setup(name='kytos',
version=METADATA.get('__version__'),
description=METADATA.get('__description__'),
long_description=open("README.pypi.rst", "r").read(),
long_description_content_type='text/x-rst',
url=METADATA.get('__url__'),
author=METADATA.get('__author__'),
author_email=METADATA.get('__author_email__'),
license=METADATA.get('__license__'),
test_suite='tests',
scripts=['bin/kytosd'],
include_package_data=True,
data_files=[(os.path.join(BASE_ENV, 'etc/kytos'), ETC_FILES)],
packages=find_packages(exclude=['tests']),
install_requires=[line.strip()
for line in open("requirements/run.txt").readlines()
if not line.startswith('#')],
extras_require={'dev': ['pip-tools >= 2.0', 'pytest==7.0.0',
'pytest-cov==3.0.0', 'pytest', 'yala', 'tox']},
cmdclass={
'clean': Cleaner,
'coverage': TestCoverage,
'doctest': DocTest,
'egg_info': EggInfo,
'lint': Linter,
'test': Test
},
zip_safe=False,
classifiers=[
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: System :: Networking',
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: No Input/Output (Daemon)',
])