summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2017-11-08 08:01:54 -0600
committerJason Madden <jamadden@gmail.com>2017-11-08 08:01:54 -0600
commitbbb6c7de6cad1eb26768f87a2d87883eebb98437 (patch)
treed89e787c3419e9cc314d2dabf5788cad64e525de
parent2602ed62388af8a1ed59e67cdcdd84d35fa9d72a (diff)
downloadzope-proxy-issue26.tar.gz
Make the C extension optional; test PURE_PYTHON and PyPy3 on Travis. Fixes #26issue26
-rw-r--r--.travis.yml17
-rw-r--r--CHANGES.rst6
-rw-r--r--setup.py61
-rw-r--r--tox.ini2
4 files changed, 64 insertions, 22 deletions
diff --git a/.travis.yml b/.travis.yml
index 8d12ab1..d0ab77c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,16 @@
language: python
sudo: false
-python:
- - 2.7
- - 3.4
- - 3.5
- - 3.6
- - pypy-5.6.0
+matrix:
+ include:
+ - python: 2.7
+ - python: 3.4
+ - python: 3.5
+ - python: 3.6
+ - python: pypy
+ - python: pypy3
+ - python: 2.7
+ env:
+ - PURE_PYTHON=1
install:
- pip install -U pip
- pip install -U setuptools
diff --git a/CHANGES.rst b/CHANGES.rst
index c475402..e0ef7d3 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,7 +6,11 @@ Changes
- Simplify the internal C handling of attribute names in
``__getattribute__`` and ``__setattr__``.
-
+- Make building the C extension optional. We still attempt to build it
+ on supported platforms, but we allow it to fail in case of a missing
+ compiler or headers. See `issue 26
+ <https://github.com/zopefoundation/zope.proxy/issues/26>`_.
+- Test the PURE_PYTHON environment and PyPy3 on Travis CI.
4.3.0 (2017-09-13)
------------------
diff --git a/setup.py b/setup.py
index 980b2ca..37934dd 100644
--- a/setup.py
+++ b/setup.py
@@ -21,7 +21,41 @@
import os
import platform
-from setuptools import setup, Extension, Feature
+
+from distutils.errors import CCompilerError
+from distutils.errors import DistutilsExecError
+from distutils.errors import DistutilsPlatformError
+
+from setuptools import Extension
+from setuptools.command.build_ext import build_ext
+from setuptools import setup
+from setuptools import Feature
+
+class optional_build_ext(build_ext):
+ """This class subclasses build_ext and allows
+ the building of C extensions to fail.
+ """
+ def run(self):
+ try:
+ build_ext.run(self)
+ except DistutilsPlatformError as e:
+ self._unavailable(e)
+
+ def build_extension(self, ext):
+ try:
+ build_ext.build_extension(self, ext)
+ except (CCompilerError, DistutilsExecError, OSError) as e:
+ self._unavailable(e)
+
+ def _unavailable(self, e):
+ print('*' * 80)
+ print("""WARNING:
+ An optional code optimization (C extension) could not be compiled.
+ Optimizations for this package will not be available!""")
+ print()
+ print(e)
+ print('*' * 80)
+
def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
@@ -29,21 +63,19 @@ def read(*rnames):
Cwrapper = Feature(
"C wrapper",
- standard = True,
+ standard=True,
headers=[os.path.join('src', 'zope', 'proxy', 'proxy.h')],
- ext_modules=[Extension("zope.proxy._zope_proxy_proxy",
- [os.path.join('src', 'zope', 'proxy',
- "_zope_proxy_proxy.c")
- ],
- extra_compile_args=['-g']),
- ],
+ ext_modules=[
+ Extension(
+ "zope.proxy._zope_proxy_proxy",
+ [os.path.join('src', 'zope', 'proxy', "_zope_proxy_proxy.c")],
+ ),
+ ],
)
# PyPy won't build the extension.
-py_impl = getattr(platform, 'python_implementation', lambda: None)
-is_pypy = py_impl() == 'PyPy'
-is_pure = os.environ.get('PURE_PYTHON')
-if is_pypy or is_pure:
+is_pypy = platform.python_implementation() == 'PyPy'
+if is_pypy:
features = {}
else:
features = {'Cwrapper': Cwrapper}
@@ -60,7 +92,7 @@ setup(name='zope.proxy',
),
url='http://github.com/zopefoundation/zope.proxy',
license='ZPL 2.1',
- classifiers = [
+ classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
@@ -81,6 +113,9 @@ setup(name='zope.proxy',
packages=['zope', 'zope.proxy'],
package_dir={'': 'src'},
namespace_packages=['zope',],
+ cmdclass={
+ 'build_ext': optional_build_ext,
+ },
features=features,
install_requires=[
'zope.interface',
diff --git a/tox.ini b/tox.ini
index c4f3928..3dfea08 100644
--- a/tox.ini
+++ b/tox.ini
@@ -35,11 +35,9 @@ basepython =
python2.7
setenv =
PURE_PYTHON = 1
- PIP_CACHE_DIR = {envdir}/.cache
[testenv:py36-pure]
basepython =
python3.6
setenv =
PURE_PYTHON = 1
- PIP_CACHE_DIR = {envdir}/.cache