Skip to content

Commit

Permalink
Raise an ImportError if setup.py is imported
Browse files Browse the repository at this point in the history
Move extension build checking to its rightful place of get_extensions
Look for cpyamf/*.pyx globs rather than specifying specific files.
Provide a new get_test_requirements which will check for the unittest2 requirement.

git-svn-id: https://svn.pyamf.org/branches/test-discovery-780@3361 2dde4cc4-cf3c-0410-b1a3-a9b8ff274da5
  • Loading branch information
njoyce committed Jun 5, 2010
1 parent 8614a04 commit b89201b
Showing 1 changed file with 55 additions and 63 deletions.
118 changes: 55 additions & 63 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,35 @@

from ez_setup import use_setuptools

use_setuptools()
use_setuptools(download_delay=3)

import sys, os.path

from setuptools import setup, find_packages, Extension
from setuptools.command import test

try:
from Cython.Distutils import build_ext
except ImportError:
from setuptools.command.build_ext import build_ext


if __name__ == '__main__':
# add the path of the folder this file lives in
base_path = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))

# since the basedir is set as the first option in sys.path, this works
sys.path.insert(0, base_path)

from pyamf import version

readme = os.path.join(base_path, 'README.txt')


class TestCommand(test.test):
def run_twisted(self):
from twisted.trial import runner
from twisted.trial import reporter
# add the path of the folder this file lives in
base_path = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))

from pyamf.tests import suite
# since the basedir is set as the first option in sys.path, this works
sys.path.insert(0, base_path)

r = runner.TrialRunner(reporter.VerboseTextReporter)
return r.run(suite())
from pyamf import version

def run_tests(self):
import logging
logging.basicConfig()
logging.getLogger().setLevel(logging.CRITICAL)
readme = os.path.join(base_path, 'README.txt')

try:
import twisted

return self.run_twisted()
except ImportError:
return test.test.run_tests(self)
# need to remove all references to imported pyamf modules, as building
# the c extensions change pyamf.util.BufferedByteStream, which blow up
# the tests (at least the first time its built which in case of the
# buildbots is always true)
for k, v in sys.modules.copy().iteritems():
if k and k.startswith('pyamf'):
del sys.modules[k]


def get_cpyamf_extensions():
Expand All @@ -57,39 +41,21 @@ def get_cpyamf_extensions():
:since: 0.4
"""
disable_ext = '--disable-ext'

if disable_ext in sys.argv:
sys.argv.remove(disable_ext)

return []
try:
import Cython

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 * '*')
extension = '.pyx'
except ImportError:
extension = '.c'

return []
import glob

ext_modules = []

try:
import Cython
for file in glob.glob(os.path.join('cpyamf', '*' + extension)):
mod = file.replace(os.path.sep, '.')[:-len(extension)]

ext_modules.extend([
Extension('cpyamf.util', ['cpyamf/util.pyx']),
Extension('cpyamf.amf3', ['cpyamf/amf3.pyx']),
Extension('cpyamf.context', ['cpyamf/context.pyx'])
])
except ImportError:
ext_modules.extend([
Extension('cpyamf.util', ['cpyamf/util.c']),
Extension('cpyamf.amf3', ['cpyamf/amf3.c']),
Extension('cpyamf.context', ['cpyamf/context.c'])
])
ext_modules.append(Extension(mod, [file]))

return ext_modules

Expand All @@ -100,6 +66,21 @@ def get_extensions():
:since: 0.4
"""
if '--disable-ext' in sys.argv:
sys.argv.remove('--disable-ext')

return []

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 []

ext_modules = []

ext_modules.extend(get_cpyamf_extensions())
Expand All @@ -120,12 +101,26 @@ def get_install_requirements():
return install_requires


def get_test_requirements():
tests_require = ['pysqlite']

if sys.version_info < (2, 7):
tests_require.append('unittest2')

return tests_require


keyw = """\
amf amf0 amf3 flex flash remoting rpc http flashplayer air bytearray
objectproxy arraycollection recordset actionscript decoder encoder
gateway remoteobject twisted pylons django sharedobject lso sol"""


if __name__ != '__main__':
raise ImportError('This setup.py file should not be imported. '
'See README.txt for more info.')


setup(name = "PyAMF",
version = str(version),
description = "AMF support for Python",
Expand All @@ -137,22 +132,19 @@ def get_install_requirements():
packages = find_packages(exclude=["*.tests"]),
ext_modules = get_extensions(),
install_requires = get_install_requirements(),
test_suite = "pyamf.tests.suite",
tests_require=['pysqlite'],
tests_require = get_test_requirements(),
zip_safe = True,
license = "MIT License",
platforms = ["any"],
cmdclass = {
'test': TestCommand,
'build_ext': build_ext,
},
extras_require = {
'wsgi': ['wsgiref'],
'twisted': ['Twisted>=2.5.0'],
'django': ['Django>=0.96'],
'sqlalchemy': ['SQLAlchemy>=0.4'],
'cython': ['Cython>=0.10'],
'test': ['pysqlite'],
'cython': ['Cython>=0.12.1'],
},
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down

0 comments on commit b89201b

Please sign in to comment.