-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathsetup.py
146 lines (115 loc) · 4.16 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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Copyright 2017, Ahmed AbouZaid <http://aabouzaid.com/>
# setup.py file is part of Netbox dynamic inventory script.
# https://github.com/AAbouZaid/netbox-as-ansible-inventory
from setuptools.command.test import test as TestCommand
from setuptools import setup, Command
from codecs import open as openc
from os import path
import subprocess
import sys
def open_file(file_name, splitlines=False):
here = path.abspath(path.dirname(__file__))
with openc(path.join(here, file_name), encoding='utf-8') as opened_file:
file_output = opened_file.read().strip()
if splitlines:
file_output = file_output.splitlines()
return file_output
# Get vars from project files.
version = open_file('VERSION')
long_description = open_file('README.rst')
main_requirements = open_file('requirements.txt', splitlines=True)
tests_requirements = open_file('tests/requirements.txt', splitlines=True)
class PyTest(TestCommand):
""" Run tests. """
user_options = [('pytest-args=', 'a', "Arguments to pass to pytest")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def run_tests(self):
import shlex
import pytest
errno = pytest.main(shlex.split(self.pytest_args))
sys.exit(errno)
class Release(Command):
""" Tag, push, and upload to PyPI. """
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Create Git tag.
tag_name = 'v%s' % version
cmd = ['git', 'tag', '-a', tag_name, '-m', 'version %s' % version]
print(' '.join(cmd))
subprocess.check_call(cmd)
# Push Git tag to origin remote.
cmd = ['git', 'push', 'origin', tag_name]
print(' '.join(cmd))
subprocess.check_call(cmd)
# Push branch to origin remote.
cmd = ['git', 'push', 'origin', 'master']
print(' '.join(cmd))
subprocess.check_call(cmd)
# Upload package to PyPI.
cmd = ['python', 'setup.py', 'sdist', 'upload']
print(' '.join(cmd))
subprocess.check_call(cmd)
class Requirements(Command):
""" Install requirements. """
user_options = [('tests-requirement', 't', "Install requirements for unit test.")]
def initialize_options(self):
self.tests_requirement = False
def finalize_options(self):
pass
def run(self):
# Install requirements via pip.
cmd = ['pip', 'install', '-r', 'requirements.txt']
if self.tests_requirement:
cmd += ['-r', 'tests/requirements.txt']
print(' '.join(cmd))
subprocess.check_call(cmd)
setup(
name='ansible-netbox-inventory',
version=version,
description='Ansible dynamic inventory script for Netbox',
long_description=long_description,
url='https://github.com/AAbouZaid/netbox-as-ansible-inventory',
author='Ahmed AbouZaid',
author_email='@'.join(("ahmed.m", "aabouzaid.com")), # To avoid spam.
license='GPLv3',
classifiers=[
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Topic :: Utilities',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Systems Administration',
'Development Status :: 5 - Production/Stable',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
],
keywords=['ansible', 'netbox', 'dynamic', 'inventory'],
packages=['netbox'],
package_data={
'netbox': ['netbox.yml'],
},
install_requires=main_requirements,
extras_require={
'tests': tests_requirements,
},
cmdclass={
'test': PyTest,
'release': Release,
'requirements': Requirements,
},
entry_points={
'console_scripts': ['ansible-netbox-inventory=netbox.netbox:main']
}
)