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?") assert os.path.exists(gperf_file) command = "gperf.exe "+ gperf_file+ " --output-file=" + output_file print(command) #subprocess.check_call(command) 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='vicent@github.com', 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'] ) ], )