Skip to content

Commit

Permalink
Properly handle errors calling gperf
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMilne committed Feb 25, 2015
1 parent 98a8498 commit 402c264
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion 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):
Expand All @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit 402c264

Please sign in to comment.