From 402c26405cf8ce378750583855053f6a03d42648 Mon Sep 17 00:00:00 2001 From: Jordan Milne Date: Tue, 24 Feb 2015 17:06:07 -0800 Subject: [PATCH] Properly handle errors calling gperf --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 693a584..a780cb0 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,10 @@ +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): @@ -13,6 +15,11 @@ def c_files_in(directory): 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: @@ -22,9 +29,10 @@ def c_files_in(directory): version = m.group(1) assert version + class GPerfingBuildExt(build_ext): def run(self): - os.system("gperf src/html_entities.gperf > src/html_entities.h") + process_gperf_file("src/html_entities.gperf", "src/html_entities.h") build_ext.run(self) setup(