File: _setuplibev.py

package info (click to toggle)
python-gevent 25.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,036 kB
  • sloc: python: 170,894; ansic: 82,360; sh: 6,265; makefile: 1,550; javascript: 108
file content (126 lines) | stat: -rw-r--r-- 5,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# -*- coding: utf-8 -*-
"""
setup helpers for libev.

Importing this module should have no side-effects; in particular,
it shouldn't attempt to cythonize anything.
"""

from __future__ import print_function, absolute_import, division

import os.path

from _setuputils import Extension

from _setuputils import system
from _setuputils import dep_abspath
from _setuputils import quoted_dep_abspath
from _setuputils import WIN
from _setuputils import LIBRARIES
from _setuputils import DEFINE_MACROS
from _setuputils import glob_many
from _setuputils import should_embed
from _setuputils import get_include_dirs


LIBEV_EMBED = should_embed('libev')

# Configure libev in place
libev_configure_command = ' '.join([
    "(cd ", quoted_dep_abspath('libev'),
    " && sh ./configure -C > configure-output.txt",
    ")",
])


def configure_libev(build_command=None, extension=None): # pylint:disable=unused-argument
    # build_command is an instance of ConfiguringBuildExt.
    # extension is an instance of the setuptools Extension object.
    #
    # This is invoked while `build_command` is in the middle of its `run()`
    # method.

    # Both of these arguments are unused here so that we can use this function
    # both from a build command and from libev/_corecffi_build.py

    if WIN:
        return

    libev_path = dep_abspath('libev')
    config_path = os.path.join(libev_path, 'config.h')
    if os.path.exists(config_path):
        print("Not configuring libev, 'config.h' already exists")
        return

    system(libev_configure_command)


def build_extension():
    # Return the un-cythonized extension.
    # This can be used to access things like `libraries` and `include_dirs`
    # and `define_macros` so we DRY.
    include_dirs = get_include_dirs()
    include_dirs.append(os.path.abspath(os.path.join('src', 'gevent', 'libev')))
    if LIBEV_EMBED:
        include_dirs.append(dep_abspath('libev'))
    CORE = Extension(name='gevent.libev.corecext',
                     sources=[
                         'src/gevent/libev/corecext.pyx',
                         'src/gevent/libev/callbacks.c',
                     ],
                     include_dirs=include_dirs,
                     libraries=list(LIBRARIES),
                     define_macros=list(DEFINE_MACROS),
                     depends=glob_many('src/gevent/libev/callbacks.*',
                                       'src/gevent/libev/stathelper.c',
                                       'src/gevent/libev/libev*.h',
                                       'deps/libev/*.[ch]'))
    # While we don't actually use periodic watchers,
    # on Windows we need to enable them to work around an issue
    # in libev 4.33 where ``have_monotonic`` is not defined.
    EV_PERIODIC_ENABLE = "0"
    if WIN:
        CORE.define_macros.append(('EV_STANDALONE', '1'))
        EV_PERIODIC_ENABLE = "1"
    # QQQ libev can also use -lm, however it seems to be added implicitly

    if LIBEV_EMBED:
        CORE.define_macros += [
            ('LIBEV_EMBED', '1'),
            # we don't use void* data in the cython implementation;
            # the CFFI implementation does and removes this line.
            ('EV_COMMON', ''),
            # libev watchers that we don't use currently:
            ('EV_CLEANUP_ENABLE', '0'),
            ('EV_EMBED_ENABLE', '0'),
            ("EV_PERIODIC_ENABLE", EV_PERIODIC_ENABLE),
            # Time keeping. If possible, use the realtime and/or monotonic
            # clocks. On Linux, this can reduce the number of observable syscalls.
            # On older linux, such as the version in manylinux2010, this requires
            # linking to lib rt. We handle this in make-manylinux. Newer versions
            # generally don't need that.
            ("EV_USE_REALTIME", "1"),
            ("EV_USE_MONOTONIC", "1"),
            # use the builtin floor() function. Every modern platform should
            # have this, right?
            ("EV_USE_FLOOR", "1"),
        ]
        CORE.configure = configure_libev
        if os.environ.get('GEVENTSETUP_EV_VERIFY') is not None:
            # Numeric values from 0 to 3. 2 and above enable some pedantic
            # checks that can very easily cause undesired failures;
            # for example, it will abort the process if you try to close a
            # watcher whose FD is now invalid.
            CORE.define_macros.append(
                ('EV_VERIFY', os.environ['GEVENTSETUP_EV_VERIFY']))
            # EV_VERIFY is implemented using assert(), which only works if
            # NDEBUG is *not* defined. distutils likes to define NDEBUG by default,
            # meaning that we get no verification in embedded mode. Since that's the
            # most common testing configuration, that's not good.
            CORE.undef_macros.append('NDEBUG')
    else:
        CORE.define_macros += [('LIBEV_EMBED', '0')]
        CORE.libraries.append('ev')
        CORE.configure = lambda *args: print("libev not embedded, not configuring")

    return CORE