[Checkins] SVN: zope.optionalextension/ Distutils command for optional C extensions.
Tres Seaver
tseaver at palladion.com
Sat Jul 3 14:05:38 EDT 2010
Log message for revision 114142:
Distutils command for optional C extensions.
Changed:
A zope.optionalextension/
A zope.optionalextension/branches/
A zope.optionalextension/tags/
A zope.optionalextension/trunk/
A zope.optionalextension/trunk/CHANGES.txt
A zope.optionalextension/trunk/COPYRIGHT.txt
A zope.optionalextension/trunk/LICENSE.txt
A zope.optionalextension/trunk/README.txt
A zope.optionalextension/trunk/bootstrap.py
A zope.optionalextension/trunk/buildout.cfg
A zope.optionalextension/trunk/setup.py
A zope.optionalextension/trunk/src/
A zope.optionalextension/trunk/src/zope/
A zope.optionalextension/trunk/src/zope/__init__.py
A zope.optionalextension/trunk/src/zope/optionalextension/
A zope.optionalextension/trunk/src/zope/optionalextension/__init__.py
A zope.optionalextension/trunk/src/zope/optionalextension/tests/
A zope.optionalextension/trunk/src/zope/optionalextension/tests/__init__.py
A zope.optionalextension/trunk/src/zope/optionalextension/tests/test_command.py
-=-
Added: zope.optionalextension/trunk/CHANGES.txt
===================================================================
--- zope.optionalextension/trunk/CHANGES.txt (rev 0)
+++ zope.optionalextension/trunk/CHANGES.txt 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,7 @@
+``zope.optionalextension`` Changelog
+=====================================
+
+1.0 (unreleased)
+----------------
+
+- Extracted from ``zope.i18nmessageid`` 3.5.0.
Added: zope.optionalextension/trunk/COPYRIGHT.txt
===================================================================
--- zope.optionalextension/trunk/COPYRIGHT.txt (rev 0)
+++ zope.optionalextension/trunk/COPYRIGHT.txt 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1 @@
+Zope Foundation and Contributors
\ No newline at end of file
Added: zope.optionalextension/trunk/LICENSE.txt
===================================================================
--- zope.optionalextension/trunk/LICENSE.txt (rev 0)
+++ zope.optionalextension/trunk/LICENSE.txt 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,44 @@
+Zope Public License (ZPL) Version 2.1
+
+A copyright notice accompanies this license document that identifies the
+copyright holders.
+
+This license has been certified as open source. It has also been designated as
+GPL compatible by the Free Software Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions in source code must retain the accompanying copyright
+notice, this list of conditions, and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying copyright
+notice, this list of conditions, and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to endorse or promote
+products derived from this software without prior written permission from the
+copyright holders.
+
+4. The right to distribute this software or to use it for any purpose does not
+give you the right to use Servicemarks (sm) or Trademarks (tm) of the
+copyright
+holders. Use of them is covered by separate agreement with the copyright
+holders.
+
+5. If any files are modified, you must cause the modified files to carry
+prominent notices stating that you changed the files and the date of any
+change.
+
+Disclaimer
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
+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 HOLDERS 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.
Added: zope.optionalextension/trunk/README.txt
===================================================================
--- zope.optionalextension/trunk/README.txt (rev 0)
+++ zope.optionalextension/trunk/README.txt 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,22 @@
+``zope.optionalextension`` README
+=================================
+
+This package provides a distutils extension for building optional C
+extensions. It is intended for use in projects which have a Python reference
+implementation of one or more features, and which can function without
+needing any C extensions to be successfully compiled.
+
+Using the Command
+-----------------
+
+In the ``setup.py`` for your package::
+
+ from distutils import setup # or setuptools
+ from zope.optionalextension import optional_build_ext
+
+ setup(name='your.package',
+ ...
+ cmdclass = {'build_ext': optional_build_ext,
+ },
+ ...
+ )
Added: zope.optionalextension/trunk/bootstrap.py
===================================================================
--- zope.optionalextension/trunk/bootstrap.py (rev 0)
+++ zope.optionalextension/trunk/bootstrap.py 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 72703 2007-02-20 11:49:26Z jim $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+is_jython = sys.platform.startswith('java')
+
+if is_jython:
+ import subprocess
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+ cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+
+if is_jython:
+ assert subprocess.Popen([sys.executable] + ['-c', cmd, '-mqNxd', tmpeggs,
+ 'zc.buildout'],
+ env = dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ).wait() == 0
+
+else:
+ assert os.spawnle(
+ os.P_WAIT, sys.executable, sys.executable,
+ '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)
Added: zope.optionalextension/trunk/buildout.cfg
===================================================================
--- zope.optionalextension/trunk/buildout.cfg (rev 0)
+++ zope.optionalextension/trunk/buildout.cfg 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,8 @@
+[buildout]
+develop = .
+parts =
+ test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zope.optionalextension
Added: zope.optionalextension/trunk/setup.py
===================================================================
--- zope.optionalextension/trunk/setup.py (rev 0)
+++ zope.optionalextension/trunk/setup.py 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+# This package is developed by the Zope Toolkit project, documented here:
+# http://docs.zope.org/zopetoolkit
+# When developing and releasing this package, please follow the documented
+# Zope Toolkit policies as described by this documentation.
+##############################################################################
+""" Setup for zope.optionalextension package
+"""
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
+ extras = {}
+else:
+ extras = {'test_suite': 'zope.optionalextension.tests',
+ }
+
+README = open('README.txt').read()
+CHANGES = open('CHANGES.txt').read()
+
+setup(name='zope.optionalextension',
+ version = '1.0dev',
+ url='http://pypi.python.org/pypi/zope.optionalextension',
+ license='ZPL 2.1',
+ description='Optional compilation of C extensions',
+ author='Zope Foundation and Contributors',
+ author_email='zope-dev at zope.org',
+ long_description='\n\n'.join([README, CHANGES]),
+ classifiers=[
+ "Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: Zope Public License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python :: 2.4",
+ "Programming Language :: Python :: 2.5",
+ "Programming Language :: Python :: 2.6",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
+ packages = ['zope', 'zope.optionalextension'],
+ package_dir = {'': 'src'},
+ **extras
+)
Added: zope.optionalextension/trunk/src/zope/__init__.py
===================================================================
--- zope.optionalextension/trunk/src/zope/__init__.py (rev 0)
+++ zope.optionalextension/trunk/src/zope/__init__.py 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+ import pkg_resources
+ pkg_resources.declare_namespace(__name__)
+except ImportError:
+ import pkgutil
+ __path__ = pkgutil.extend_path(__path__, __name__)
Added: zope.optionalextension/trunk/src/zope/optionalextension/__init__.py
===================================================================
--- zope.optionalextension/trunk/src/zope/optionalextension/__init__.py (rev 0)
+++ zope.optionalextension/trunk/src/zope/optionalextension/__init__.py 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+from distutils.command.build_ext import build_ext
+from distutils.errors import CCompilerError
+from distutils.errors import DistutilsExecError
+from distutils.errors import DistutilsPlatformError
+import sys
+from traceback import format_exc
+
+
+class optional_build_ext(build_ext):
+ """ Allow building of C extensions to fail without blocking installation.
+ """
+ description = __doc__
+
+ def __init__ (self, dist, stream=None):
+ build_ext.__init__(self, dist)
+ if stream is None:
+ stream = sys.stderr
+ self._stream = stream
+
+ def run(self):
+ try:
+ build_ext.run(self)
+ except DistutilsPlatformError, e:
+ self._unavailable(e)
+
+ def build_extension(self, ext):
+ try:
+ build_ext.build_extension(self, ext)
+ except (CCompilerError, DistutilsExecError), e:
+ self._unavailable(e)
+
+ def _unavailable(self, e):
+ self._stream.write('%s\n' % ('*' * 80))
+ self._stream.write("""WARNING:
+
+ An optional code optimization (C extension) could not be compiled.
+ """)
+ self._stream.write('\n')
+ self._stream.write('%s\n' % format_exc(e))
+ self._stream.write('%s\n' % ('*' * 80))
Added: zope.optionalextension/trunk/src/zope/optionalextension/tests/__init__.py
===================================================================
--- zope.optionalextension/trunk/src/zope/optionalextension/tests/__init__.py (rev 0)
+++ zope.optionalextension/trunk/src/zope/optionalextension/tests/__init__.py 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1 @@
+# package
Added: zope.optionalextension/trunk/src/zope/optionalextension/tests/test_command.py
===================================================================
--- zope.optionalextension/trunk/src/zope/optionalextension/tests/test_command.py (rev 0)
+++ zope.optionalextension/trunk/src/zope/optionalextension/tests/test_command.py 2010-07-03 18:05:37 UTC (rev 114142)
@@ -0,0 +1,58 @@
+import unittest
+
+class Test_optional_build_ext(unittest.TestCase):
+
+ def _getTargetClass(self):
+ from zope.optionalextension import optional_build_ext
+ return optional_build_ext
+
+ def _makeOne(self, dist=None, stream=None):
+ if dist is None:
+ dist = self._makeDistribution()
+ if stream is None:
+ stream = self._makeStream()
+ command = self._getTargetClass()(dist, stream)
+ command.initialize_options()
+ command.finalize_options()
+ return command
+
+ def _makeDistribution(self):
+ from distutils.core import Distribution
+
+ class DummyDistribution(Distribution):
+
+ def has_c_libraries(self):
+ return True
+
+ return DummyDistribution()
+
+ def _makeExtension(self, name, sources):
+ from distutils.core import Extension
+
+ class DummyExtension(Extension):
+ pass
+
+ return DummyExtension(name, sources)
+
+ def _makeStream(self):
+ from StringIO import StringIO
+ return StringIO()
+
+ def test_run(self):
+ command = self._makeOne()
+ command.extensions = [self._makeExtension('aaa', ['foo.c'])]
+ command.run() # doesn't raise
+ self.failUnless('CompileError' in command._stream.getvalue())
+
+ def test_build_extension(self):
+ command = self._makeOne()
+ command.compiler = DummyCompiler()
+ ext = self._makeExtension('aaa', ['foo.c'])
+ command.build_extension(ext) # doesn't raise
+ self.failUnless('TESTING' in command._stream.getvalue())
+
+
+class DummyCompiler:
+ def compile(self, *args, **kw):
+ from distutils.errors import CCompilerError
+ raise CCompilerError('TESTING')
More information about the checkins
mailing list