File: setup.py

package info (click to toggle)
html5-parser 0.4.12%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,748 kB
  • sloc: ansic: 32,397; python: 1,732; makefile: 6
file content (74 lines) | stat: -rwxr-xr-x 2,090 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
#!/usr/bin/env python
# vim:fileencoding=utf-8
# License: Apache 2.0 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>

import os
import sys
from itertools import chain

from setuptools import Extension, setup, Command

self_path = os.path.abspath(__file__)
base = os.path.dirname(self_path)
sys.path.insert(0, base)
if True:
    from unix_build import (
        SRC_DIRS, TEST_COMMAND, add_python_path, find_c_files, include_dirs, iswindows, libraries,
        library_dirs, version
    )
del sys.path[0]

src_files = tuple(chain(*map(lambda x: find_c_files(x)[0], SRC_DIRS)))
cargs = ('/O2' if iswindows else '-O3').split()
if not iswindows:
    cargs.extend('-std=c99 -fvisibility=hidden'.split())


class Test(Command):

    description = "run unit tests after in-place build"
    user_options = []
    user_options = [
        ('test-name=', None, 'Specify the test to run.'),
    ]
    sub_commands = [
        ('build', None),
    ]

    def initialize_options(self):
        self.test_name = ''

    def finalize_options(self):
        pass

    def run(self):
        for cmd_name in self.get_sub_commands():
            self.run_command(cmd_name)
        import subprocess
        build = self.get_finalized_command('build')
        env = add_python_path(os.environ.copy(), build.build_lib)
        print('\nrunning tests...')
        sys.stdout.flush()
        cmd = [sys.executable] + TEST_COMMAND
        if self.test_name:
            cmd.append(self.test_name)
        ret = subprocess.Popen(cmd, env=env).wait()
        if ret != 0:
            raise SystemExit(ret)


setup(
    cmdclass={'test': Test},
    ext_modules=[
        Extension(
            'html5_parser.html_parser',
            include_dirs=include_dirs(),
            libraries=libraries(),
            library_dirs=library_dirs(),
            extra_compile_args=cargs,
            define_macros=[
                ('MAJOR', str(version.major)),
                ('MINOR', str(version.minor)),
                ('PATCH', str(version.patch))
            ],
            sources=list(map(str, src_files)))])