Ticket #5158: 5158.diff

File 5158.diff, 2.6 KB (added by lvh, 5 years ago)
  • twisted/topfiles/setup.py

    === modified file 'twisted/topfiles/setup.py'
     
    1919from twisted.python.dist import getPackages, getDataFiles, getScripts
    2020from twisted.python.dist import twisted_subprojects
    2121
     22import platform
     23
     24
     25def _isCPython():
     26    try:
     27        return platform.python_implementation() == "CPython"
     28    except AttributeError:
     29        # For 2.5:
     30        try:
     31            implementation, _, _ = sys.subversion
     32            return implementation == "CPython"
     33        except AttributeError:
     34            pass
     35
     36        # Pythons older than 2.5 require us to try and guess by
     37        # elimination. If you're on such an old, obscure version of
     38        # Python, I can't help you.
     39       
     40        # Are we on Pypy?
     41        if "__pypy__" in sys.modules:
     42            return False
     43
     44        # Guess not. Are we on Jython?
     45        try:
     46            platform.java_ver
     47            return False
     48        except AttributeError:
     49            pass
     50
     51        # Guess not. Are we on IronPython?
     52        try:
     53            import clr
     54            return False
     55        except ImportError:
     56            pass
     57       
     58        # Well, then we're *probably* on CPython.
     59        return True
     60
     61
     62isCPython = _isCPython()
     63
     64
     65def hasEpoll(builder):
     66    builder._check_header("sys/epoll.h")
    2267
    2368
    2469extensions = [
    2570    Extension("twisted.test.raiser",
    26               ["twisted/test/raiser.c"]),
     71              ["twisted/test/raiser.c"],
     72              condition=lambda _: isCPython),
    2773
    2874    Extension("twisted.python._epoll",
    2975              ["twisted/python/_epoll.c"],
    30               condition=lambda builder: builder._check_header("sys/epoll.h")),
     76              condition=lambda builder: isCPython and hasEpoll(builder)),
    3177
    3278    Extension("twisted.internet.iocpreactor.iocpsupport",
    3379              ["twisted/internet/iocpreactor/iocpsupport/iocpsupport.c",
    3480               "twisted/internet/iocpreactor/iocpsupport/winsock_pointers.c"],
    3581              libraries=["ws2_32"],
    36               condition=lambda builder: sys.platform == "win32"),
     82              condition=lambda _: isCPython and sys.platform == "win32"),
    3783
    3884    Extension("twisted.python._initgroups",
    3985              ["twisted/python/_initgroups.c"]),
    4086    Extension("twisted.internet._sigchld",
    4187              ["twisted/internet/_sigchld.c"],
    42               condition=lambda builder: sys.platform != "win32"),
     88              condition=lambda _: sys.platform != "win32"),
    4389]
    4490
    4591# Figure out which plugins to include: all plugins except subproject ones