File: setup.py

package info (click to toggle)
mod-wsgi 4.6.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,784 kB
  • sloc: ansic: 14,843; python: 3,628; makefile: 224; sh: 174
file content (593 lines) | stat: -rw-r--r-- 21,985 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
from __future__ import print_function

import os
import sys
import fnmatch
import subprocess
import tarfile
import shutil
import stat
import re

try:
    from urllib.request import urlretrieve
except ImportError:
    from urllib import urlretrieve

from setuptools import setup
from distutils.core import Extension
from distutils.sysconfig import get_config_var as get_python_config
from distutils.sysconfig import get_python_lib

# Before anything else, this setup.py uses some tricks to potentially
# install Apache. This can be from a local tarball, or from precompiled
# Apache binaries for Heroku and OpenShift environments downloaded from
# Amazon S3. Once they are installed, then the installation of the
# mod_wsgi package itself will be triggered, ensuring that it can be
# built against the precompiled Apache binaries which were installed.
#
# First work out whether we are actually running on either Heroku or
# OpenShift. If we are, then we identify the set of precompiled binaries
# we are to use and copy it into the Python installation.

PREFIX = 'https://s3.amazonaws.com'
BUCKET = os.environ.get('MOD_WSGI_REMOTE_S3_BUCKET_NAME', 'modwsgi.org')

REMOTE_TARBALL_NAME = os.environ.get('MOD_WSGI_REMOTE_PACKAGES_NAME')
LOCAL_TARBALL_FILE = os.environ.get('MOD_WSGI_LOCAL_PACKAGES_FILE')

TGZ_OPENSHIFT='mod_wsgi-packages-openshift-centos6-apache-2.4.12-1.tar.gz'
TGZ_HEROKU='mod_wsgi-packages-heroku-cedar14-apache-2.4.12-1.tar.gz'

if not REMOTE_TARBALL_NAME and not LOCAL_TARBALL_FILE:
    if os.environ.get('OPENSHIFT_HOMEDIR'):
        REMOTE_TARBALL_NAME = TGZ_OPENSHIFT
    elif os.path.isdir('/app/.heroku'):
        REMOTE_TARBALL_NAME = TGZ_HEROKU

REMOTE_TARBALL_URL = None

if LOCAL_TARBALL_FILE is None and REMOTE_TARBALL_NAME:
    REMOTE_TARBALL_URL = '%s/%s/%s' % (PREFIX, BUCKET, REMOTE_TARBALL_NAME)

WITH_TARBALL_PACKAGE = False

if REMOTE_TARBALL_URL or LOCAL_TARBALL_FILE:
    WITH_TARBALL_PACKAGE = True

# If we are doing an install, download the tarball and unpack it into
# the 'packages' subdirectory. We will then add everything in that
# directory as package data so that it will be installed into the Python
# installation.

if WITH_TARBALL_PACKAGE:
    if REMOTE_TARBALL_URL:
        if not os.path.isfile(REMOTE_TARBALL_NAME):
            print('Downloading', REMOTE_TARBALL_URL)
            urlretrieve(REMOTE_TARBALL_URL, REMOTE_TARBALL_NAME+'.download')
            os.rename(REMOTE_TARBALL_NAME+'.download', REMOTE_TARBALL_NAME)
        LOCAL_TARBALL_FILE = REMOTE_TARBALL_NAME

    if LOCAL_TARBALL_FILE:
        shutil.rmtree('src/packages', ignore_errors=True)

        tar = tarfile.open(LOCAL_TARBALL_FILE)
        tar.extractall('src/packages')
        tar.close()

    open('src/packages/__init__.py', 'a').close()

    package_files = []

    for root, dirs, files in os.walk('src/packages', topdown=False):
        for name in files:
            path = os.path.join(root, name).split('/', 1)[1]
            package_files.append(path)
            print('adding ', path)

    print('Running setup for Apache')

    setup(name = 'mod_wsgi-packages',
        version = '1.0.0',
        packages = ['mod_wsgi', 'mod_wsgi.packages'],
        package_dir = {'mod_wsgi': 'src'},
        package_data = {'mod_wsgi': package_files},
    )

# From this point on we will now actually install mod_wsgi. First we need
# to work out what all the available source code files are that should be
# compiled.

source_files = [os.path.join('src/server', name) for name in 
        os.listdir(os.path.join(os.path.dirname(os.path.abspath(__file__)),
        'src/server')) if fnmatch.fnmatch(name, '*.c')]

# Work out all the Apache specific compilation flags. This is done using
# the standard Apache apxs command unless we are installing our own build
# of Apache. In that case we use Python code to do the equivalent of apxs
# as apxs will not work due to paths not matching where it was installed.

def find_program(names, default=None, paths=[]):
    for name in names:
        for path in os.environ['PATH'].split(':') + paths:
            program = os.path.join(path, name)
            if os.path.exists(program):
                return program
    return default

APXS = os.environ.get('APXS')

WITH_HTTPD_PACKAGE = False

if APXS is None:
    APXS = find_program(['mod_wsgi-apxs'],
            paths=[os.path.dirname(sys.executable)])
    if APXS is not None:
        WITH_HTTPD_PACKAGE = True

if APXS is None:
    APXS = find_program(['mod_wsgi-apxs', 'apxs2', 'apxs'],
            'apxs', ['/usr/sbin', os.getcwd()])
elif not os.path.isabs(APXS):
    APXS = find_program([APXS], APXS, ['/usr/sbin', os.getcwd()])

WITHOUT_APXS = False
WITH_WINDOWS_APACHE = None
WITH_MACOSX_APACHE = None

if not WITH_TARBALL_PACKAGE:
    if not os.path.isabs(APXS) or not os.access(APXS, os.X_OK):
        WITHOUT_APXS = True

if WITHOUT_APXS and os.name == 'nt':
    APACHE_ROOTDIR = os.environ.get('MOD_WSGI_APACHE_ROOTDIR')
    if APACHE_ROOTDIR:
        if os.path.exists(APACHE_ROOTDIR):
            WITH_WINDOWS_APACHE = APACHE_ROOTDIR
        else:
            raise RuntimeError('The Apache directory %r does not exist.' %
                    APACHE_ROOTDIR)
    else:
        if os.path.exists('c:\\Apache24'):
            WITH_WINDOWS_APACHE = 'c:\\Apache24'
        elif os.path.exists('c:\\Apache22'):
            WITH_WINDOWS_APACHE = 'c:\\Apache22'
        elif os.path.exists('c:\\Apache2'):
            WITH_WINDOWS_APACHE = 'c:\\Apache2'
        else:
            raise RuntimeError('No Apache installation can be found. Set the '
                    'MOD_WSGI_APACHE_ROOTDIR environment to its location.')

elif WITHOUT_APXS and sys.platform == 'darwin':
    WITH_MACOSX_APACHE = '/Applications/Xcode.app'

if WITHOUT_APXS and not WITH_WINDOWS_APACHE and not WITH_MACOSX_APACHE:
    raise RuntimeError('The %r command appears not to be installed or '
            'is not executable. Please check the list of prerequisites '
            'in the documentation for this package and install any '
            'missing Apache httpd server packages.' % APXS)

if WITH_WINDOWS_APACHE:
    def get_apxs_config(name):
        if name == 'INCLUDEDIR':
            return WITH_WINDOWS_APACHE + '/include'
        elif name == 'LIBEXECDIR':
            return WITH_WINDOWS_APACHE + '/lib'
        else:
            return ''

    def get_apr_includes():
        return ''

    def get_apu_includes():
        return ''

elif WITH_MACOSX_APACHE:
    def get_apxs_config(name):
        if name == 'BINDIR':
            return '/usr/bin'
        elif name == 'SBINDIR':
            return '/usr/sbin'
        elif name == 'LIBEXECDIR':
            return '/usr/libexec/apache2'
        elif name == 'PROGNAME':
            return 'httpd'
        elif name == 'SHLIBPATH_VAR':
            return 'DYLD_LIBRARY_PATH'
        else:
            return ''

    def get_apr_includes():
        return ''

    def get_apu_includes():
        return ''

elif WITH_TARBALL_PACKAGE:
    SCRIPT_DIR = os.path.join(os.path.dirname(__file__), 'src', 'packages')

    CONFIG_FILE = os.path.join(SCRIPT_DIR, 'apache/build/config_vars.mk')

    CONFIG = {}

    with open(CONFIG_FILE) as fp:
        for line in fp.readlines():
            name, value = line.split('=', 1)
            name = name.strip()
            value = value.strip()
            CONFIG[name] = value

    _varprog = re.compile(r'\$(\w+|(?:\{[^}]*\}|\([^)]*\)))')

    def expand_vars(value):
        if '$' not in value:
            return value

        i = 0
        while True:
            m = _varprog.search(value, i)
            if not m:
                break
            i, j = m.span(0)
            name = m.group(1)
            if name.startswith('{') and name.endswith('}'):
                name = name[1:-1]
            elif name.startswith('(') and name.endswith(')'):
                name = name[1:-1]
            if name in CONFIG:
                tail = value[j:]
                value = value[:i] + CONFIG.get(name, '')
                i = len(value)
                value += tail
            else:
                i = j

        return value

    def get_apxs_config(name):
        value = CONFIG.get(name, '')
        sub_value = expand_vars(value)
        while value != sub_value:
            value = sub_value
            sub_value = expand_vars(value)
        return sub_value.replace('/mod_wsgi-packages/', SCRIPT_DIR+'/')

    def get_apr_includes():
        return ''

    def get_apu_includes():
        return ''

    CONFIG['PREFIX'] = get_apxs_config('prefix')
    CONFIG['TARGET'] = get_apxs_config('target')
    CONFIG['SYSCONFDIR'] = get_apxs_config('sysconfdir')
    CONFIG['INCLUDEDIR'] = get_apxs_config('includedir')
    CONFIG['LIBEXECDIR'] = get_apxs_config('libexecdir')
    CONFIG['BINDIR'] = get_apxs_config('bindir')
    CONFIG['SBINDIR'] = get_apxs_config('sbindir')
    CONFIG['PROGNAME'] = get_apxs_config('progname')

else:
    def get_apxs_config(query):
        p = subprocess.Popen([APXS, '-q', query],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        if isinstance(out, bytes):
            out = out.decode('UTF-8')
        return out.strip()

    def get_apr_includes():
        if not APR_CONFIG:
            return ''

        p = subprocess.Popen([APR_CONFIG, '--includes'],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        if isinstance(out, bytes):
            out = out.decode('UTF-8')
        return out.strip()

    def get_apu_includes():
        if not APU_CONFIG:
            return ''

        p = subprocess.Popen([APU_CONFIG, '--includes'],
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, err = p.communicate()
        if isinstance(out, bytes):
            out = out.decode('UTF-8')
        return out.strip()

INCLUDEDIR = get_apxs_config('INCLUDEDIR')
CPPFLAGS = get_apxs_config('CPPFLAGS').split()
CFLAGS = get_apxs_config('CFLAGS').split()

EXTRA_INCLUDES = get_apxs_config('EXTRA_INCLUDES').split()
EXTRA_CPPFLAGS = get_apxs_config('EXTRA_CPPFLAGS').split()
EXTRA_CFLAGS = get_apxs_config('EXTRA_CFLAGS').split()

APR_CONFIG = get_apxs_config('APR_CONFIG')
APU_CONFIG = get_apxs_config('APU_CONFIG')

# Make sure that 'apr-1-config' exists. If it doesn't we may be running
# on MacOS X Sierra, which has decided to not provide either it or the
# 'apu-1-config' script and otherwise completely broken 'apxs'. In that
# case we manually set the locations of the Apache and APR header files.

if (not os.path.exists(APR_CONFIG) and
        os.path.exists('/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk')):
    INCLUDEDIR = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/apache2'
    APR_INCLUDES = ['-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/apr-1']
    APU_INCLUDES = []

elif (not os.path.exists(APR_CONFIG) and
        os.path.exists('/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/MacOSX.sdk')):
    INCLUDEDIR = '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/MacOSX.sdk/usr/include/apache2'
    APR_INCLUDES = ['-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdks/MacOSX.sdk/usr/include/apr-1']
    APU_INCLUDES = []

else:
    APR_INCLUDES = get_apr_includes().split()
    APU_INCLUDES = get_apu_includes().split()

if not os.path.exists(APR_CONFIG) and not INCLUDEDIR:
    if sys.platform == 'darwin':
        # Likely no Xcode application installed or location of SDK in
        # Xcode has changed with a new release of Xcode application.

        raise RuntimeError('No Apache installation can be found, do you '
                'have the full Apple Xcode installed. It is not enough to '
                'have just the xcode command line tools installed.')
    else:
        # Set INCLUDEDIR just to avoid having an empty path. Probably
        # should raise an exception here.

        INCLUDEDIR = '/usr/include'

# Write out apxs_config.py which caches various configuration related to
# Apache. For the case of using our own Apache build, this needs to
# calculate values dynamically based on where binaries were installed.
# This is necessary as on OpenShift the virtual environment gets copied
# for each gear to a different path. We can't therefore rely on a hard
# coded path.

BINDIR = get_apxs_config('BINDIR')
SBINDIR = get_apxs_config('SBINDIR')

PROGNAME = get_apxs_config('PROGNAME')

MPM_NAME = get_apxs_config('MPM_NAME')
LIBEXECDIR = get_apxs_config('LIBEXECDIR')
SHLIBPATH_VAR = get_apxs_config('SHLIBPATH_VAR')

APXS_CONFIG_TEMPLATE = """
import os

WITH_TARBALL_PACKAGE = %(WITH_TARBALL_PACKAGE)r
WITH_HTTPD_PACKAGE = %(WITH_HTTPD_PACKAGE)r

if WITH_HTTPD_PACKAGE:
    from mod_wsgi_packages.httpd import __file__ as PACKAGES_ROOTDIR
    PACKAGES_ROOTDIR = os.path.dirname(PACKAGES_ROOTDIR)
    BINDIR = os.path.join(PACKAGES_ROOTDIR, 'bin')
    SBINDIR = BINDIR
    LIBEXECDIR = os.path.join(PACKAGES_ROOTDIR, 'modules')
    SHLIBPATH = os.path.join(PACKAGES_ROOTDIR, 'lib')
elif WITH_TARBALL_PACKAGE:
    from mod_wsgi.packages import __file__ as PACKAGES_ROOTDIR
    PACKAGES_ROOTDIR = os.path.dirname(PACKAGES_ROOTDIR)
    BINDIR = os.path.join(PACKAGES_ROOTDIR, 'apache', 'bin')
    SBINDIR = BINDIR
    LIBEXECDIR = os.path.join(PACKAGES_ROOTDIR, 'apache', 'modules')
    SHLIBPATH = []
    SHLIBPATH.append(os.path.join(PACKAGES_ROOTDIR, 'apr-util', 'lib'))
    SHLIBPATH.append(os.path.join(PACKAGES_ROOTDIR, 'apr', 'lib'))
    SHLIBPATH = ':'.join(SHLIBPATH)
else:
    BINDIR = '%(BINDIR)s'
    SBINDIR = '%(SBINDIR)s'
    LIBEXECDIR = '%(LIBEXECDIR)s'
    SHLIBPATH = ''

MPM_NAME = '%(MPM_NAME)s'
PROGNAME = '%(PROGNAME)s'
SHLIBPATH_VAR = '%(SHLIBPATH_VAR)s'

if os.path.exists(os.path.join(SBINDIR, PROGNAME)):
    HTTPD = os.path.join(SBINDIR, PROGNAME)
elif os.path.exists(os.path.join(BINDIR, PROGNAME)):
    HTTPD = os.path.join(BINDIR, PROGNAME)
else:
    HTTPD = PROGNAME

if os.path.exists(os.path.join(SBINDIR, 'rotatelogs')):
    ROTATELOGS = os.path.join(SBINDIR, 'rotatelogs')
elif os.path.exists(os.path.join(BINDIR, 'rotatelogs')):
    ROTATELOGS = os.path.join(BINDIR, 'rotatelogs')
else:
    ROTATELOGS = 'rotatelogs'
"""

with open(os.path.join(os.path.dirname(__file__),
        'src/server/apxs_config.py'), 'w') as fp:
    print(APXS_CONFIG_TEMPLATE % dict(
            WITH_TARBALL_PACKAGE=WITH_TARBALL_PACKAGE,
            WITH_HTTPD_PACKAGE=WITH_HTTPD_PACKAGE,
            BINDIR=BINDIR, SBINDIR=SBINDIR, LIBEXECDIR=LIBEXECDIR,
            MPM_NAME=MPM_NAME, PROGNAME=PROGNAME,
            SHLIBPATH_VAR=SHLIBPATH_VAR), file=fp)

# Work out location of Python library and how to link it.

PYTHON_VERSION = get_python_config('VERSION')

if os.name == 'nt':
    if hasattr(sys, 'real_prefix'):
        PYTHON_LIBDIR = sys.real_prefix
    else:
        PYTHON_LIBDIR = get_python_config('BINDIR')

    PYTHON_LDFLAGS = []
    PYTHON_LDLIBS = ['%s/libs/python%s.lib' % (PYTHON_LIBDIR, PYTHON_VERSION),
            '%s/lib/libhttpd.lib' % WITH_WINDOWS_APACHE,
            '%s/lib/libapr-1.lib' % WITH_WINDOWS_APACHE,
            '%s/lib/libaprutil-1.lib' % WITH_WINDOWS_APACHE,
            '%s/lib/libapriconv-1.lib' % WITH_WINDOWS_APACHE]

else:
    PYTHON_LDVERSION = get_python_config('LDVERSION') or PYTHON_VERSION

    PYTHON_LIBDIR = get_python_config('LIBDIR')
    PYTHON_CFGDIR =  get_python_lib(plat_specific=1, standard_lib=1) + '/config'

    if PYTHON_LDVERSION and PYTHON_LDVERSION != PYTHON_VERSION:
        PYTHON_CFGDIR = '%s-%s' % (PYTHON_CFGDIR, PYTHON_LDVERSION)
        if not os.path.exists(PYTHON_CFGDIR):
            PYTHON_CFGDIR = '%s-%s' % (PYTHON_CFGDIR, sys.platform)

    PYTHON_LDFLAGS = ['-L%s' % PYTHON_LIBDIR, '-L%s' % PYTHON_CFGDIR]
    PYTHON_LDLIBS = ['-lpython%s' % PYTHON_LDVERSION]

    if os.path.exists(os.path.join(PYTHON_LIBDIR,
            'libpython%s.a' % PYTHON_VERSION)):
        PYTHON_LDLIBS = ['-lpython%s' % PYTHON_VERSION]

    if os.path.exists(os.path.join(PYTHON_CFGDIR,
            'libpython%s.a' % PYTHON_VERSION)):
        PYTHON_LDLIBS = ['-lpython%s' % PYTHON_VERSION]

# Create the final set of compilation flags to be used.

INCLUDE_DIRS = [INCLUDEDIR]
EXTRA_COMPILE_FLAGS = (EXTRA_INCLUDES + CPPFLAGS + EXTRA_CPPFLAGS +
        CFLAGS + EXTRA_CFLAGS + APR_INCLUDES + APU_INCLUDES)
EXTRA_LINK_ARGS = PYTHON_LDFLAGS + PYTHON_LDLIBS

# Force adding of LD_RUN_PATH for platforms that may need it.

if os.name != 'nt':
    LD_RUN_PATH = os.environ.get('LD_RUN_PATH', '')
    LD_RUN_PATH += ':%s:%s' % (PYTHON_LIBDIR, PYTHON_CFGDIR)
    LD_RUN_PATH = LD_RUN_PATH.lstrip(':')

    os.environ['LD_RUN_PATH'] = LD_RUN_PATH

# On MacOS X, recent versions of Apple's Apache do not support compiling
# Apache modules with a target older than 10.8. This is because it
# screws up Apache APR % formats for apr_time_t, which breaks daemon
# mode queue time. For the target to be 10.8 or newer for now if Python
# installation supports older versions. This means that things will not
# build for older MacOS X versions. Deal with these when they occur.

if sys.platform == 'darwin':
    target = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
    if target is None:
        target = get_python_config('MACOSX_DEPLOYMENT_TARGET')

    if target:
        target_version = tuple(map(int, target.split('.')))
        #assert target_version >= (10, 8), \
        #        'Minimum of 10.8 for MACOSX_DEPLOYMENT_TARGET'
        if target_version < (10, 8):
            os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.8'

# Now add the definitions to build everything.

if os.name == 'nt':
    extension_name = 'mod_wsgi.server.mod_wsgi'
else:
    extension_name = 'mod_wsgi.server.mod_wsgi-py%s%s' % sys.version_info[:2]

extension = Extension(extension_name, source_files,
        include_dirs=INCLUDE_DIRS, extra_compile_args=EXTRA_COMPILE_FLAGS,
        extra_link_args=EXTRA_LINK_ARGS)

def _documentation():
    result = []
    prefix = 'docs/_build/html'
    for root, dirs, files in os.walk(prefix, topdown=False):
        for name in files:
            if root == prefix:
                result.append(os.path.join(root[len(prefix):], name))
            else:
                result.append(os.path.join(root[len(prefix)+1:], name))
    return result

def _version():
    path = 'src/server/wsgi_version.h'
    pattern = r'#define MOD_WSGI_VERSION_STRING "(?P<version>[^"]*)"'
    with open(path, 'r') as fp:
        match = re.search(pattern, fp.read(), flags=re.MULTILINE)
    return match.group('version')

# Final check to make sure a shared library for Python does actually
# exist. Warn if one doesn't as we really want a shared library.

SHARED_LIBRARY_WARNING = """
WARNING: The Python installation you are using does not appear to have
been installed with a shared library, or in the case of MacOS X, as a
framework. Where these are not present, the compilation of mod_wsgi may
fail, or if it does succeed, will result in extra memory being used by
all processes at run time as a result of the static library needing to
be loaded in its entirety to every process. It is highly recommended
that you reinstall the Python installation being used from source code,
supplying the '--enable-shared' option to the 'configure' script when
configuring the source code prior to building and installing it.
"""

if os.name != 'nt':
    if (not get_python_config('Py_ENABLE_SHARED') and
            not get_python_config('PYTHONFRAMEWORK')):
        print(SHARED_LIBRARY_WARNING)

# Now finally run distutils.

long_description = open('README.rst').read()

setup(name = 'mod_wsgi',
    version = _version(),
    description = 'Installer for Apache/mod_wsgi.',
    long_description = long_description,
    author = 'Graham Dumpleton',
    author_email = 'Graham.Dumpleton@gmail.com',
    maintainer = 'Graham Dumpleton',
    maintainer_email = 'Graham.Dumpleton@gmail.com',
    url = 'http://www.modwsgi.org/',
    bugtrack_url = 'https://github.com/GrahamDumpleton/mod_wsgi/issues',
    license = 'Apache License, Version 2.0',
    platforms = [],
    download_url = None,
    classifiers = [
        'Development Status :: 6 - Mature',
        'License :: OSI Approved :: Apache Software License',
        'Operating System :: MacOS :: MacOS X',
        'Operating System :: POSIX',
        'Operating System :: POSIX :: BSD',
        'Operating System :: POSIX :: Linux',
        'Operating System :: POSIX :: SunOS/Solaris',
        'Programming Language :: Python',
        'Programming Language :: Python :: Implementation :: CPython',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Topic :: Internet :: WWW/HTTP :: WSGI',
        'Topic :: Internet :: WWW/HTTP :: WSGI :: Server'
    ],
    keywords = 'mod_wsgi wsgi apache',
    packages = ['mod_wsgi', 'mod_wsgi.server', 'mod_wsgi.server.management',
        'mod_wsgi.server.management.commands', 'mod_wsgi.docs',
        'mod_wsgi.images'],
    package_dir = {'mod_wsgi': 'src', 'mod_wsgi.docs': 'docs/_build/html',
        'mod_wsgi.images': 'images'},
    package_data = {'mod_wsgi.docs': _documentation(),
        'mod_wsgi.images': ['snake-whiskey.jpg']},
    ext_modules = [extension],
    entry_points = { 'console_scripts':
        ['mod_wsgi-express = mod_wsgi.server:main'],},
    zip_safe = False,
)