-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·183 lines (155 loc) · 6.21 KB
/
setup.py
File metadata and controls
executable file
·183 lines (155 loc) · 6.21 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
179
180
181
182
183
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
from setuptools import setup, Command
from setuptools.command.test import test as TestCommand
import versioneer
versioneer.versionfile_source = 'pynetworking/_version.py'
versioneer.versionfile_build = 'pynetworking/_version.py'
versioneer.tag_prefix = 'v' # tags are like v1.2.0
versioneer.parentdir_prefix = 'py-networking-'
# The file 'setup.py' can be used as follows:
#
# - create documentation in .pdf format: python setup.py doc
# - execute the tests that come with PN: python setup.py test
# - start with a clean work environment: python setup.py clean
# - verify the pep8 standard compliance: python setup.py pep8
class ToxCommand(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import tox
errno = tox.cmdline(self.test_args)
sys.exit(errno)
class CleanCommand(Command):
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
os.system('rm -rf ./.coverage ./coverage.* ./coverage-* ./MANIFEST ./.tox ./build ./dist ./*.pyc ./*.tgz ./*.egg ./*.egg-info ./py-networking-* ./doc')
class Pep8Command(Command):
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
os.system('flake8 --max-line-length=160 --exclude=all.py --exclude=build > pep8.result')
if os.path.getsize("./pep8.result") == 0:
print('The PN library is pep8 compliant')
else:
print('The PN library is not pep8 compliant.\nThe inconsistencies are:\n')
os.system('flake8 --max-line-length=160 --exclude=all.py --exclude=build')
os.remove("./pep8.result")
class DocCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from sphinx.application import Sphinx
from sphinx.util.console import darkred
import subprocess
self.source_dir = os.path.abspath('srcdoc')
self.build_dir = os.path.join('./build', 'sphinx')
self.mkpath(self.build_dir)
self.doctree_dir = os.path.join(self.build_dir, 'doctrees')
self.mkpath(self.doctree_dir)
self.builder_target_dir = 'doc'
self.mkpath(self.builder_target_dir)
app = Sphinx(self.source_dir, self.source_dir,
self.build_dir, self.doctree_dir,
'latex', {}, sys.stdout,
freshenv=False)
try:
app.builder.build_update()
except Exception, err:
from docutils.utils import SystemMessage
if isinstance(err, SystemMessage):
sys.stderr, darkred('reST markup error:')
print >>sys.stderr, err.args[0].encode('ascii', 'backslashreplace')
else:
raise
print "Generating PDF"
subprocess.check_output(
"pushd {0} && make all-pdf && popd && cp {0}/*.pdf ./srcdoc".format(self.build_dir, self.build_dir),
stderr=subprocess.STDOUT,
shell=True)
app = Sphinx(self.source_dir, self.source_dir,
'doc', self.doctree_dir,
'html', {}, sys.stdout,
freshenv=True)
try:
app.builder.build_update()
except Exception, err:
from docutils.utils import SystemMessage
if isinstance(err, SystemMessage):
sys.stderr, darkred('reST markup error:')
print >>sys.stderr, err.args[0].encode('ascii', 'backslashreplace')
else:
raise
if os.path.exists('README.rst'):
with open('README.rst') as file:
long_description = file.read()
else:
long_description = 'Library for network programming and automation'
setup(name='py-networking',
version=versioneer.get_version(),
cmdclass=dict(versioneer.get_cmdclass().items() +
{'test': ToxCommand,
'clean': CleanCommand,
'doc': DocCommand,
'pep8': Pep8Command,
}.items()
),
description='Library for network programming and automation',
long_description=long_description,
author='Allied Telesis',
author_email='francesco_salamida@alliedtelesis.com',
license='Apache License 2.0',
packages=['pynetworking',
'pynetworking.features',
'pynetworking.facts',
'pynetworking.system',
'pynetworking.utils',
],
package_data={'pynetworking': ['*.yaml']
},
install_requires=['paramiko',
'PyYAML',
'Jinja2',
'ply',
'pyasn1',
'pyzmq>=14.0.0',
'ordereddict',
'TFTPy',
'pytz',
'pycrypto',
'ecdsa'
],
setup_requires=['sphinx',
'sphinx_rtd_theme'
],
tests_require=['twisted',
'tox'
],
url='http://www.py-networking.com',
classifiers=['Development Status :: 1 - Planning',
'Intended Audience :: System Administrators',
'Intended Audience :: Telecommunications Industry',
'License :: OSI Approved :: Apache Software License',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Networking'
]
)