forked from eucalyptus/euca2ools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
144 lines (129 loc) · 6.33 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
# Copyright 2009-2013 Eucalyptus Systems, Inc.
#
# Redistribution and use of this software in source and binary forms,
# with or without modification, are permitted provided that the following
# conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from distutils.command.build_py import build_py
from distutils.command.build_scripts import build_scripts
from distutils.command.install_scripts import install_scripts
from distutils.command.sdist import sdist
import glob
import os.path
import re
from setuptools import find_packages, setup
from euca2ools import __version__
# Cheap hack: install symlinks separately from regular files.
# cmd.copy_tree accepts a preserve_symlinks option, but when we call
# ``setup.py install'' more than once the method fails when it encounters
# symlinks that are already there.
class build_scripts_except_symlinks(build_scripts):
'''Like build_scripts, but ignoring symlinks'''
def copy_scripts(self):
orig_scripts = self.scripts
self.scripts = [script for script in self.scripts
if not os.path.islink(script)]
build_scripts.copy_scripts(self)
self.scripts = orig_scripts
class install_scripts_and_symlinks(install_scripts):
'''Like install_scripts, but also replicating nonexistent symlinks'''
def run(self):
install_scripts.run(self)
# Replicate symlinks if they don't exist
for script in self.distribution.scripts:
if os.path.islink(script):
target = os.readlink(script)
newlink = os.path.join(self.install_dir, os.path.basename(script))
if not os.path.exists(newlink):
os.symlink(target, newlink)
class build_py_with_git_version(build_py):
'''Like build_py, but also hardcoding the version in __init__.__version__
so it's consistent even outside of the source tree'''
def build_module(self, module, module_file, package):
build_py.build_module(self, module, module_file, package)
print module, module_file, package
if module == '__init__' and '.' not in package:
version_line = "__version__ = '{0}'\n".format(__version__)
old_init_name = self.get_module_outfile(self.build_lib, (package,),
module)
new_init_name = old_init_name + '.new'
with open(new_init_name, 'w') as new_init:
with open(old_init_name) as old_init:
for line in old_init:
if line.startswith('__version__ ='):
new_init.write(version_line)
else:
new_init.write(line)
new_init.flush()
os.rename(new_init_name, old_init_name)
class sdist_with_git_version(sdist):
'''Like sdist, but also hardcoding the version in __init__.__version__ so
it's consistent even outside of the source tree'''
def make_release_tree(self, base_dir, files):
sdist.make_release_tree(self, base_dir, files)
version_line = "__version__ = '{0}'\n".format(__version__)
old_init_name = os.path.join(base_dir, 'euca2ools/__init__.py')
new_init_name = old_init_name + '.new'
with open(new_init_name, 'w') as new_init:
with open(old_init_name) as old_init:
for line in old_init:
if line.startswith('__version__ ='):
new_init.write(version_line)
else:
new_init.write(line)
new_init.flush()
os.rename(new_init_name, old_init_name)
setup(name="euca2ools",
version=__version__,
description="Eucalyptus Command Line Tools",
long_description="Eucalyptus Command Line Tools",
author="Eucalyptus Systems, Inc.",
author_email="[email protected]",
url="http://www.eucalyptus.com",
scripts=sum((glob.glob('bin/euare-*'),
glob.glob('bin/euca-*'),
glob.glob('bin/eulb-*'),
glob.glob('bin/euscale-*'),
glob.glob('bin/eustore-*'),
glob.glob('bin/euwatch-*')),
[]),
data_files=[('share/man/man1', glob.glob('man/*.1'))],
packages=find_packages(),
install_requires=['lxml',
'requestbuilder',
'requests',
'six'],
license='BSD (Simplified)',
platforms='Posix; MacOS X',
classifiers=['Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Simplified BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Internet'],
cmdclass={'build_py': build_py_with_git_version,
'build_scripts': build_scripts_except_symlinks,
'install_scripts': install_scripts_and_symlinks,
'sdist': sdist_with_git_version})