Imported Upstream version 3.8.0
[contrib/python-zope.interface.git] / build_ext_3.py
1 import os
2 import sys
3 from distutils.errors import (CCompilerError, DistutilsExecError, 
4                               DistutilsPlatformError)
5 try:
6     from setuptools.command.build_ext import build_ext
7     from pkg_resources import (normalize_path, working_set, 
8                                add_activation_listener, require)
9 except ImportError:
10     raise RuntimeError("zope.interface requires Distribute under Python 3. "
11                        "See http://packages.python.org/distribute")
12
13 class optional_build_ext(build_ext):
14     """This class subclasses build_ext and allows
15        the building of C extensions to fail.
16     """
17     def run(self):
18         try:
19             build_ext.run(self)
20         
21         except DistutilsPlatformError as e:
22             self._unavailable(e)
23
24     def build_extension(self, ext):
25         try:
26             build_ext.build_extension(self, ext)
27         
28         except (CCompilerError, DistutilsExecError) as e:
29             self._unavailable(e)
30
31     def _unavailable(self, e):
32         print('*' * 80, file=sys.stderr)
33         print("""WARNING:
34
35         An optional code optimization (C extension) could not be compiled.
36
37         Optimizations for this package will not be available!""", file=sys.stderr)
38         print(file=sys.stderr)
39         print(e, file=sys.stderr)
40         print('*' * 80, file=sys.stderr)