This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
/
setup.py
194 lines (166 loc) · 6.36 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
#!/usr/bin/env python
# Copyright 2013-2015, Ansible, Inc.
# Michael DeHaan <[email protected]>
# Luke Sneeringer <[email protected]>
# and others
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import os
import sys
import codecs
from distutils.core import setup
from setuptools import find_packages
from setuptools.command.test import test as TestCommand
pkg_name = 'tower_cli'
dashed_name = pkg_name.replace('_', '-')
awx_entry = dashed_name.replace('tower', 'awx')
# Avoid packaging any other API version of tower-cli with current one
# Note: The 0,1 in the format strings are for building el6 rpms with python 2.6.6
exclude_list = ['tests']
primary_install = len(pkg_name.split('_')) == 2
base_name = pkg_name[:9]
if not primary_install:
exclude_list += [base_name, '{0}.*'.format(base_name)]
for v in (1, 2):
if pkg_name.endswith(str(v)):
continue
v_name = '{0}_v{1}'.format(base_name, v)
exclude_list += [v_name, '{0}.*'.format(v_name)]
discovered_packages = find_packages(exclude=exclude_list)
class Tox(TestCommand):
"""The test command should install and then run tox.
Based on http://tox.readthedocs.org/en/latest/example/basic.html
"""
user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.tox_args = ""
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import tox # Import here, because outside eggs aren't loaded.
import shlex
sys.exit(tox.cmdline(args=shlex.split(self.tox_args)))
def parse_requirements(filename):
"""Parse out a list of requirements from the given requirements
requirements file.
"""
reqs = []
version_spec_in_play = None
# Iterate over each line in the requirements file.
for line in open(filename, 'r').read().strip().split('\n'):
# Sanity check: Is this an empty line?
# If so, do nothing.
if not line.strip():
continue
# If this is just a plain requirement (not a comment), then
# add it to the requirements list.
if not line.startswith('#'):
reqs.append(line)
continue
# "Header" comments take the form of "=== Python {op} {version} ===",
# and make the requirement only matter for those versions.
# If this line is a header comment, parse it.
match = re.search(r'^# === [Pp]ython (?P<op>[<>=]{1,2}) '
r'(?P<major>[\d])\.(?P<minor>[\d]+) ===[\s]*$', line)
if match:
version_spec_in_play = match.groupdict()
for key in ('major', 'minor'):
version_spec_in_play[key] = int(version_spec_in_play[key])
continue
# If this is a comment that otherwise looks like a package, then it
# should be a package applying only to the current version spec.
#
# We can identify something that looks like a package by a lack
# of any spaces.
if ' ' not in line[1:].strip() and version_spec_in_play:
package = line[1:].strip()
# Sanity check: Is our version of Python one of the ones currently
# in play?
op = version_spec_in_play['op']
vspec = (version_spec_in_play['major'],
version_spec_in_play['minor'])
if '=' in op and sys.version_info[0:2] == vspec:
reqs.append(package)
elif '>' in op and sys.version_info[0:2] > vspec:
reqs.append(package)
elif '<' in op and sys.version_info[0:2] < vspec:
reqs.append(package)
# Okay, we should have an entire list of requirements now.
return reqs
def combine_files(*args):
"""returns a string of all the strings in *args combined together,
with two line breaks between them"""
file_contents = []
for filename in args:
with codecs.open(filename, mode='r', encoding='utf8') as f:
file_contents.append(f.read())
return "\n\n".join(file_contents)
# Read the constants, for versioning information
constants = {}
exec(
open(os.path.join(pkg_name, 'constants.py')).read(),
constants
)
setup(
# Basic metadata
name='ansible-%s' % dashed_name,
version=constants['VERSION'],
author='Red Hat, Inc.',
author_email='[email protected]',
url='https://github.com/ansible/tower-cli',
# Additional information
description='A CLI tool for Ansible Tower and AWX.',
long_description=combine_files(
'README.rst',
os.path.join('docs', 'source', 'HISTORY.rst')
),
license='Apache 2.0',
# How to do the install
install_requires=parse_requirements('requirements.txt'),
provides=[
pkg_name,
],
entry_points={
'console_scripts': [
'%s=%s.cli.run:cli' % (dashed_name, pkg_name),
'%s=%s.cli.run:cli' % (awx_entry, pkg_name),
],
},
packages=discovered_packages,
include_package_data=True,
# How to do the tests
tests_require=['tox'],
cmdclass={'test': Tox},
# PyPI metadata.
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: System :: Software Distribution',
'Topic :: System :: Systems Administration',
],
zip_safe=False
)