-
Notifications
You must be signed in to change notification settings - Fork 80
/
setup.py
53 lines (45 loc) · 1.4 KB
/
setup.py
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
from distutils.spawn import find_executable
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import re
import os
import subprocess
import fnmatch
def c_files_in(directory):
paths = []
names = os.listdir(directory)
for f in fnmatch.filter(names, '*.c'):
paths.append(os.path.join(directory, f))
return paths
def process_gperf_file(gperf_file, output_file):
if not find_executable("gperf"):
raise Exception("Couldn't find `gperf`, is it installed?")
subprocess.check_call(["gperf", gperf_file, "--output-file=%s" % output_file])
version = None
version_re = re.compile(r'^#define\s+SNUDOWN_VERSION\s+"([^"]+)"$')
with open('snudown.c', 'r') as f:
for line in f:
m = version_re.match(line)
if m:
version = m.group(1)
assert version
class GPerfingBuildExt(build_ext):
def run(self):
process_gperf_file("src/html_entities.gperf", "src/html_entities.h")
build_ext.run(self)
setup(
name='snudown',
version=version,
author='Vicent Marti',
author_email='[email protected]',
license='MIT',
test_suite="test_snudown.test_snudown",
cmdclass={'build_ext': GPerfingBuildExt,},
ext_modules=[
Extension(
name='snudown',
sources=['snudown.c'] + c_files_in('src/') + c_files_in('html/'),
include_dirs=['src', 'html']
)
],
)