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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.
"""
Meta data and helper functions for setup
"""
import sys
import os.path
import fnmatch
try:
from Cython.Distutils import build_ext
have_cython = True
except ImportError:
from setuptools.command.build_ext import build_ext
have_cython = False
if have_cython:
# may need to work around setuptools bug by providing a fake Pyrex
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "fake_pyrex"))
from setuptools.command import test, sdist
from setuptools import Extension
from distutils.core import Distribution
_version = None
class MyDistribution(Distribution):
"""
This seems to be is the only obvious way to add a global option to
distutils.
Provide the ability to disable building the extensions for any called
command.
"""
global_options = Distribution.global_options + [
('disable-ext', None, 'Disable building extensions.')
]
def finalize_options(self):
Distribution.finalize_options(self)
try:
i = self.script_args.index('--disable-ext')
except ValueError:
self.disable_ext = False
else:
self.disable_ext = True
self.script_args.pop(i)
class MyBuildExt(build_ext):
"""
The companion to L{MyDistribution} that checks to see if building the
extensions are disabled.
"""
def build_extension(self, ext):
if self.distribution.disable_ext:
return
return build_ext.build_extension(self, ext)
def build_extensions(self):
if self.distribution.disable_ext:
return
return build_ext.build_extensions(self)
class MySDist(sdist.sdist):
"""
We generate the Cython code for a source distribution
"""
def cythonise(self):
ext = MyBuildExt(self.distribution)
ext.initialize_options()
ext.finalize_options()
ext.check_extensions_list(ext.extensions)
for e in ext.extensions:
e.sources = ext.cython_sources(e.sources, e)
def run(self):
if not have_cython:
print('ERROR - Cython is required to build source distributions')
raise SystemExit(1)
self.cythonise()
return sdist.sdist.run(self)
class TestCommand(test.test):
"""
Ensures that unittest2 is imported if required and replaces the old
unittest module.
"""
def run_tests(self):
try:
import unittest2
sys.modules['unittest'] = unittest2
except ImportError:
pass
return test.test.run_tests(self)
def set_version(version):
global _version
_version = version
def get_version():
v = ''
prev = None
for x in _version:
if prev is not None:
if isinstance(x, int):
v += '.'
prev = x
v += str(x)
return v.strip('.')
def get_extras_require():
return {
'wsgi': ['wsgiref'],
'twisted': ['Twisted>=2.5.0'],
'django': ['Django>=0.96'],
'sqlalchemy': ['SQLAlchemy>=0.4'],
'elixir': ['Elixir>=0.7.1'],
'lxml': ['lxml>=2.2'],
}
def get_package_data():
return {
'cpyamf': ['*.pxd'],
}
def extra_setup_args():
"""
Extra kwargs to supply in the call to C{setup}.
This is used to supply custom commands, not metadata - that should live in
setup.py itself.
"""
return {
'distclass': MyDistribution,
'cmdclass': {
'test': TestCommand,
'build_ext': MyBuildExt,
'sdist': MySDist
},
'package_data': get_package_data(),
}
def get_install_requirements():
"""
Returns a list of dependencies for PyAMF to function correctly on the
target platform.
"""
install_requires = []
if sys.version_info < (2, 5):
install_requires.extend(["elementtree>=1.2.6", "uuid>=1.30"])
if 'dev' in get_version():
install_requires.extend(['Cython>=0.13'])
return install_requires
def get_test_requirements():
"""
Returns a list of required packages to run the test suite.
"""
tests_require = []
if sys.version_info < (2, 7):
tests_require.extend(['unittest2', 'pysqlite'])
return tests_require
def write_version_py(filename='pyamf/_version.py'):
"""
"""
if os.path.exists(filename):
os.remove(filename)
content = """\
# THIS FILE IS GENERATED BY PYAMF SETUP.PY
from pyamf.versions import Version
version = Version(*%(version)r)
"""
a = open(filename, 'wt')
try:
a.write(content % {'version': _version})
finally:
a.close()
def make_extension(mod_name, **extra_options):
"""
Tries is best to return an Extension instance based on the mod_name
"""
base_name = os.path.join(mod_name.replace('.', os.path.sep))
if have_cython:
for ext in ['.pyx', '.py']:
source = base_name + ext
if os.path.exists(source):
return Extension(mod_name, [source], **extra_options)
print('WARNING: Could not find Cython source for %r' % (mod_name,))
else:
source = base_name + '.c'
if os.path.exists(source):
return Extension(mod_name, [source], **extra_options)
print('WARNING: Could not build extension for %r, no source found' % (
mod_name,))
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
def get_extensions():
"""
Return a list of Extension instances that can be compiled.
"""
if sys.platform.startswith('java'):
print(80 * '*')
print('WARNING:')
print('\tAn optional code optimization (C extension) could not be compiled.\n\n')
print('\tOptimizations for this package will not be available!\n\n')
print('Compiling extensions is not supported on Jython')
print(80 * '*')
return []
extensions = []
for p in recursive_glob('.', '*.pyx'):
mod_name = os.path.splitext(p)[0].replace(os.path.sep, '.')
e = make_extension(mod_name)
if e:
extensions.append(e)
return extensions
def get_trove_classifiers():
"""
Return a list of trove classifiers that are setup dependent.
"""
classifiers = []
def dev_status():
version = get_version()
if 'dev' in version:
return 'Development Status :: 2 - Pre-Alpha'
elif 'alpha' in version:
return 'Development Status :: 3 - Alpha'
elif 'beta' in version:
return 'Development Status :: 4 - Beta'
else:
return 'Development Status :: 5 - Production/Stable'
return classifiers + [dev_status()]
def recursive_glob(path, pattern):
matches = []
for root, dirnames, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, pattern):
matches.append(os.path.normpath(os.path.join(root, filename)))
return matches
|