From 56496896e023773e4d2a464e7a59b4caa053096d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Wed, 5 Apr 2006 03:37:46 +0000 Subject: [PATCH] * setup.py: Incorporate cleanups suggested by Michael Urman. svn path=/trunk/yasm/; revision=1461 --- tools/python-yasm/setup.py | 45 +++++++------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) diff --git a/tools/python-yasm/setup.py b/tools/python-yasm/setup.py index 87f7304c..c6afc0c8 100644 --- a/tools/python-yasm/setup.py +++ b/tools/python-yasm/setup.py @@ -28,54 +28,25 @@ from distutils.core import setup from distutils.extension import Extension from Pyrex.Distutils import build_ext from os.path import basename, join, exists -import re def ReadSetup(filename): """ReadSetup goes through filename and parses out the values stored in the file. Values need to be stored in a \"key=value format\"""" + return dict(line.split('=', 1) for line in open(filename)) - #return val - opts = {} - - fh = open(filename, 'r') - reobj = re.compile(r"([a-z]+)=(.+)") - for line in fh.readlines(): - matchobj = reobj.search(line) - - if matchobj is None: - raise "Error: syntaxt error in setup.txt line: %s"%line - - lab, val = matchobj.groups() - opts[lab] = val - return opts - -def ParseCPPFlags(str): +def ParseCPPFlags(flags): """parse the CPPFlags macro""" - incl_dir = [] - cppflags = [] - - tokens = str.split() - # go through the list of compile flags. treat search path args - # specially; otherwise just add to "extra_compile_args" - for tok in tokens: - if tok.startswith("-I"): - incl_dir.append(tok[2:]) - else: - cppflags.append(tok) - + incl_dir = [x[2:] for x in flags.split() if x.startswith("-I")] + cppflags = [x for x in flags.split() if not x.startswith("-I")] return (incl_dir, cppflags) -def ParseSources(str, srcdir): +def ParseSources(src, srcdir): """parse the Sources macro""" - sources = [] - - tokens = str.split() - # go through the list of source filenames # do the dance of detecting if the source file is in the current # directory, and if it's not, prepend srcdir - for tok in tokens: - fn = None + sources = [] + for tok in src.split(): if tok.endswith(".c"): fn = tok elif tok.endswith(".y"): @@ -112,7 +83,7 @@ if __name__ == "__main__": incldir, cppflags = ParseCPPFlags(opts["includes"]) sources = ParseSources(opts["sources"], opts["srcdir"]) sources.append('yasm_python.c') - if opts["gcc"] == "yes": + if opts["gcc"].strip() == "yes": cppflags.append('-w') RunSetup(incldir, cppflags, sources) -- 2.40.0