forked from ansible/tower-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
164 lines (144 loc) · 5.52 KB
/
Copy pathsetup.py
File metadata and controls
164 lines (144 loc) · 5.52 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
#!/usr/bin/env python
# Copyright 2013-2015, Ansible, Inc.
# Michael DeHaan <michael@ansible.com>
# Luke Sneeringer <lsneeringer@ansible.com>
# 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 os
import re
import sys
from distutils.core import setup
from os.path import dirname, realpath
from os import sep
from setuptools import find_packages
from setuptools.command.test import test as TestCommand
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 open(filename, 'r') as f:
file_contents.append(f.read())
return "\n\n".join(file_contents)
setup(
# Basic metadata
name='ansible-tower-cli',
version=open('VERSION').read().strip(),
author='Luke Sneeringer',
author_email='lsneeringer@ansible.com',
url='https://github.com/ansible/tower-cli',
# Additional information
description='A CLI tool for Ansible Tower.',
long_description=combine_files('README.rst', 'HISTORY.rst'),
license='Apache 2.0',
# How to do the install
install_requires=parse_requirements('requirements.txt'),
provides=[
'tower_cli',
],
package_dir={
'tower_cli': 'lib/tower_cli',
},
packages=[i for i in find_packages('lib') if i.startswith('tower_cli')],
scripts=[
'bin/tower-cli',
],
# How to do the tests
tests_require=['tox'],
cmdclass={'test': Tox },
# Data files
package_data={
'tower_cli': ['VERSION'],
},
# 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.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: System :: Software Distribution',
'Topic :: System :: Systems Administration',
],
)