forked from wjlester/cot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
224 lines (195 loc) · 7.64 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python
#
# setup.py - installer script for COT package
#
# April 2014, Glenn F. Matthews
# Copyright (c) 2014-2019 the COT project developers.
# See the COPYRIGHT.txt file at the top-level directory of this distribution
# and at https://github.com/glennmatthews/cot/blob/master/COPYRIGHT.txt.
#
# This file is part of the Common OVF Tool (COT) project.
# It is subject to the license terms in the LICENSE.txt file found in the
# top-level directory of this distribution and at
# https://github.com/glennmatthews/cot/blob/master/LICENSE.txt. No part
# of COT, including this file, may be copied, modified, propagated, or
# distributed except according to the terms contained in the LICENSE.txt file.
"""COT - the Common OVF Tool."""
from __future__ import print_function
# Install setuptools automatically if not already present
try:
from setuptools import setup
except ImportError:
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup
import os.path
import re
from distutils.command.build import build
import versioneer
from setuptools.command.bdist_egg import bdist_egg
# At present setuptools has no way to resolve build-time dependencies.
# Sphinx is needed to regenerate the COT man pages at build time,
# but is not actually a setup requirement or an install requirement.
# See also:
# https://github.com/pypa/pip/issues/2381
# Also, to reduce noise in the repository, we only auto-update the man pages
# if we're working in a release candidate, hotfix, or master branch
GIT_HEAD = os.path.join(os.path.dirname(__file__), ".git", "HEAD")
rebuild_manpages = False
if os.path.exists(GIT_HEAD):
head_data = open(GIT_HEAD).read()
match = re.match(r"ref: refs/heads/(.*)", head_data)
if match:
branch = match.group(1)
print("Current branch is {0}".format(branch))
if any(branch.startswith(pfx) for pfx in ['release',
'hotfix',
'master']):
rebuild_manpages = True
else:
print("COT manual pages will not be automatically rebuilt.")
print("You may run '{0} build_man' to rebuild them manually."
.format(os.path.basename(__file__)))
try:
from sphinx.setup_command import BuildDoc
class BuildMan(BuildDoc):
"""Command to (re)build man pages using Sphinx."""
def initialize_options(self):
"""Set the manpage builder as default."""
BuildDoc.initialize_options(self)
self.builder = 'man'
except ImportError:
from distutils.cmd import Command
import time
class BuildMan(Command):
"""No-op."""
def initialize_options(self):
"""No-op."""
self.config_dir = self.build_dir = None
user_options = []
finalize_options = initialize_options
def run(self):
"""Print a warning message and return."""
print("\033[1;31m")
print("WARNING: Sphinx is not installed.")
print(" As a result, COT cannot update its man pages.")
print(" If you are building for a release, please:")
print(" pip install -r requirements.txt")
print(" pip install 'sphinx>=1.5' sphinx_rtd_theme")
print(" and then rerun this command.")
print("\033[0;0m")
# Give the user time to take notice
time.sleep(10)
print("Continuing...")
README_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'README.rst')
install_requires = [
'argparse',
'colorlog>=2.5.0',
'pyvmomi>=5.5.0.2014.1',
'requests>=2.5.1',
'verboselogs>=1.6',
# http://docs.python-requests.org/en/latest/community/
# faq/#what-are-hostname-doesn-t-match-errors
# COT tends to run into this issue when downloading the VMDKtool source
'pyOpenSSL; python_version < "2.7.9"',
'ndg-httpsclient; python_version < "2.7.9"',
# shutil.disk_usage is standard in 3.3 and later only.
'psutil>=5.6.7; python_version < "3.3"',
# shutil.get_terminal_size is standard in 3.3 and later only.
'backports.shutil_get_terminal_size; python_version < "3.3"',
# enum module is standard in Python 3.4 and later, else use enum34
'enum34; python_version < "3.4"',
]
tests_require = install_requires + ['unittest2', 'mock']
extras_require = {
'tab-completion': ['argcomplete>=1.3.0'],
}
cmdclass = versioneer.get_cmdclass()
cmdclass['build_man'] = BuildMan
if rebuild_manpages:
class BDistEgg(bdist_egg):
"""Custom subclass for the 'bdist_egg' command.
This command is called automatically by 'install', but it doesn't do
sub_commands, so we have to subclass it instead.
"""
def run(self):
"""Call build_man then proceed as normal."""
self.run_command('build_man')
bdist_egg.run(self)
# Ensure that man pages are regenerated whenever build/sdist are run
# setup.py sdist --sub_commands--> build_man
cmdclass['sdist'].sub_commands.insert(0, ('build_man', None))
# setup.py bdist_egg --> run_command(build_man)
cmdclass['bdist_egg'] = BDistEgg
# setup.py bdist_wheel --> run_command(build) --sub_commands--> build_man
build.sub_commands.insert(0, ('build_man', None))
setup(
# Package description
name='cot',
version=versioneer.get_version(),
author='Glenn Matthews',
author_email='glenn@e-dad.net',
url='https://github.com/glennmatthews/cot',
description='Common OVF Tool',
long_description=open(README_FILE).read(),
license='MIT',
# Requirements
test_suite='unittest2.collector',
tests_require=tests_require,
install_requires=install_requires,
extras_require=extras_require,
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4',
# Package contents
cmdclass=cmdclass,
packages=[
'COT',
'COT.commands',
'COT.disks',
'COT.helpers',
'COT.platforms',
'COT.ui',
'COT.vm_description',
'COT.vm_description.ovf',
],
package_data={
'COT': ['docs/man/*'],
},
entry_points={
'console_scripts': [
'cot = COT.ui.cli:main',
],
},
include_package_data=True,
# PyPI search categories
classifiers=[
# Project status
'Development Status :: 5 - Production/Stable',
# Target audience
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Emulators',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Software Distribution',
'Topic :: System :: Systems Administration',
# Licensing
'License :: OSI Approved :: MIT License',
# Environment
'Environment :: Console',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
# Supported versions
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
keywords='virtualization ovf ova esxi vmware vcenter',
)