|
1
|
|
|
"""Setup script. |
|
2
|
|
|
|
|
3
|
|
|
Run "python3 setup --help-commands" to list all available commands and their |
|
4
|
|
|
descriptions. |
|
5
|
|
|
""" |
|
6
|
|
|
import os |
|
7
|
|
|
from abc import abstractmethod |
|
8
|
|
|
from subprocess import call |
|
9
|
|
|
from setuptools import Command, find_packages, setup |
|
10
|
|
|
from setuptools.command.develop import develop |
|
11
|
|
|
|
|
12
|
|
|
if 'VIRTUAL_ENV' in os.environ: |
|
13
|
|
|
BASE_ENV = os.environ['VIRTUAL_ENV'] |
|
14
|
|
|
else: |
|
15
|
|
|
BASE_ENV = '/' |
|
16
|
|
|
|
|
17
|
|
|
SKEL_PATH = 'etc/skel' |
|
18
|
|
|
KYTOS_SKEL_PATH = os.path.join(SKEL_PATH, 'kytos') |
|
19
|
|
|
AUTHOR_PATH = os.path.join(KYTOS_SKEL_PATH, 'napp-structure/author') |
|
20
|
|
|
NAPP_PATH = os.path.join(AUTHOR_PATH, 'napp') |
|
21
|
|
|
ETC_FILES = [(os.path.join(BASE_ENV, AUTHOR_PATH), |
|
22
|
|
|
[os.path.join(AUTHOR_PATH, '__init__.py')]), |
|
23
|
|
|
(os.path.join(BASE_ENV, NAPP_PATH), |
|
24
|
|
|
[os.path.join(NAPP_PATH, '__init__.py'), |
|
25
|
|
|
os.path.join(NAPP_PATH, 'kytos.json.template'), |
|
26
|
|
|
os.path.join(NAPP_PATH, 'main.py.template'), |
|
27
|
|
|
os.path.join(NAPP_PATH, 'README.rst.template'), |
|
28
|
|
|
os.path.join(NAPP_PATH, 'settings.py.template')])] |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
class SimpleCommand(Command): |
|
32
|
|
|
"""Make Command implementation simpler.""" |
|
33
|
|
|
|
|
34
|
|
|
user_options = [] |
|
35
|
|
|
|
|
36
|
|
|
@abstractmethod |
|
37
|
|
|
def run(self): |
|
38
|
|
|
"""Run when command is invoked. |
|
39
|
|
|
|
|
40
|
|
|
Use *call* instead of *check_call* to ignore failures. |
|
41
|
|
|
""" |
|
42
|
|
|
pass |
|
43
|
|
|
|
|
44
|
|
|
def initialize_options(self): |
|
45
|
|
|
"""Set defa ult values for options.""" |
|
46
|
|
|
pass |
|
47
|
|
|
|
|
48
|
|
|
def finalize_options(self): |
|
49
|
|
|
"""Post-process options.""" |
|
50
|
|
|
pass |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
class Cleaner(SimpleCommand): |
|
54
|
|
|
"""Custom clean command to tidy up the project root.""" |
|
55
|
|
|
|
|
56
|
|
|
description = 'clean build, dist, pyc and egg from package and docs' |
|
57
|
|
|
|
|
58
|
|
|
def run(self): |
|
59
|
|
|
"""Clean build, dist, pyc and egg from package and docs.""" |
|
60
|
|
|
call('rm -vrf ./build ./dist ./*.egg-info', shell=True) |
|
61
|
|
|
call('find . -name __pycache__ -type d | xargs rm -rf', shell=True) |
|
62
|
|
|
call('make -C docs/ clean', shell=True) |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
class TestCoverage(SimpleCommand): |
|
66
|
|
|
"""Display test coverage.""" |
|
67
|
|
|
|
|
68
|
|
|
description = 'run unit tests and display code coverage' |
|
69
|
|
|
|
|
70
|
|
|
def run(self): |
|
71
|
|
|
"""Run unittest quietly and display coverage report.""" |
|
72
|
|
|
cmd = 'coverage3 run -m unittest discover -qs tests' \ |
|
73
|
|
|
' && coverage3 report' |
|
74
|
|
|
call(cmd, shell=True) |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
class Linter(SimpleCommand): |
|
78
|
|
|
"""Code linters.""" |
|
79
|
|
|
|
|
80
|
|
|
description = 'lint Python source code' |
|
81
|
|
|
|
|
82
|
|
|
def run(self): |
|
83
|
|
|
"""Run pylama.""" |
|
84
|
|
|
print('Pylama is running. It may take several seconds...') |
|
85
|
|
|
call('pylama setup.py tests kytos', shell=True) |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
class DevelopMode(develop): |
|
89
|
|
|
"""Recommended setup for kytos-utils developers. |
|
90
|
|
|
|
|
91
|
|
|
Instead of copying the files to the expected directories, a symlink is |
|
92
|
|
|
created on the system aiming the current source code. |
|
93
|
|
|
""" |
|
94
|
|
|
|
|
95
|
|
|
def run(self): |
|
96
|
|
|
"""Install the package in a developer mode.""" |
|
97
|
|
|
super().run() |
|
98
|
|
|
self._create_data_files_directory() |
|
99
|
|
|
|
|
100
|
|
|
@staticmethod |
|
101
|
|
|
def _create_data_files_directory(): |
|
102
|
|
|
current_directory = os.path.abspath(os.path.dirname(__file__)) |
|
103
|
|
|
|
|
104
|
|
|
etc_dir = os.path.join(BASE_ENV, 'etc') |
|
105
|
|
|
if not os.path.exists(etc_dir): |
|
106
|
|
|
os.mkdir(etc_dir) |
|
107
|
|
|
|
|
108
|
|
|
dst_dir = os.path.join(BASE_ENV, SKEL_PATH) |
|
109
|
|
|
if not os.path.exists(dst_dir): |
|
110
|
|
|
os.mkdir(dst_dir) |
|
111
|
|
|
|
|
112
|
|
|
src = os.path.join(current_directory, KYTOS_SKEL_PATH) |
|
113
|
|
|
dst = os.path.join(BASE_ENV, KYTOS_SKEL_PATH) |
|
114
|
|
|
|
|
115
|
|
|
if not os.path.exists(dst): |
|
116
|
|
|
os.symlink(src, dst) |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
REQS = [i.strip() for i in open("requirements.txt").readlines()] |
|
120
|
|
|
|
|
121
|
|
|
setup(name='kytos-utils', |
|
122
|
|
|
version='2017.1b1', |
|
123
|
|
|
description='Command line utilities to use with Kytos.', |
|
124
|
|
|
url='http://github.com/kytos/kytos-utils', |
|
125
|
|
|
author='Kytos Team', |
|
126
|
|
|
author_email='[email protected]', |
|
127
|
|
|
license='MIT', |
|
128
|
|
|
test_suite='tests', |
|
129
|
|
|
include_package_data=True, |
|
130
|
|
|
scripts=['bin/kytos'], |
|
131
|
|
|
install_requires=REQS, |
|
132
|
|
|
data_files=ETC_FILES, |
|
133
|
|
|
packages=find_packages(exclude=['tests']), |
|
134
|
|
|
cmdclass={ |
|
135
|
|
|
'clean': Cleaner, |
|
136
|
|
|
'coverage': TestCoverage, |
|
137
|
|
|
'develop': DevelopMode, |
|
138
|
|
|
'lint': Linter |
|
139
|
|
|
}, |
|
140
|
|
|
zip_safe=False) |
|
141
|
|
|
|