From d7a8387978a5de5851803ee71f96366623b6af18 Mon Sep 17 00:00:00 2001 From: epage Date: Thu, 26 Mar 2009 02:42:08 +0000 Subject: [PATCH] Making sure we always have the pyc for supposedly faster startup git-svn-id: file:///svnroot/gc-dialer/trunk@253 c39d3808-3fe2-4d86-a59f-b7f623ee9f21 --- Makefile | 20 ++++++++++++-------- support/test_syntax.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) create mode 100755 support/test_syntax.py diff --git a/Makefile b/Makefile index 1edb00e..a79ef30 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ TAG_FILE=~/.ctags/$(PROJECT_NAME).tags DEBUGGER=winpdb UNIT_TEST=nosetests --with-doctest -w . +SYNTAX_TEST=support/test_syntax.py STYLE_TEST=../../Python/tools/pep8.py --ignore=W191 LINT_RC=./support/pylint.rc LINT=pylint --rcfile=$(LINT_RC) @@ -19,22 +20,22 @@ CTAGS=ctags-exuberant .PHONY: all run profile debug test lint tags build clean distclean -all: test package +all: test -run: $(SOURCE) +run: $(OBJ) $(SOURCE_PATH)/dc_glade.py -profile: $(SOURCE) +profile: $(OBJ) $(PROFILE_GEN) $(PROGRAM) $(PROFILE_VIEW) -debug: $(SOURCE) +debug: $(OBJ) $(DEBUGGER) $(PROGRAM) -test: $(SOURCE) +test: $(OBJ) $(UNIT_TEST) -build: +build: $(OBJ) @# @todo Add a PYC generation step rm -Rf $(BUILD_PATH) mkdir $(BUILD_PATH) @@ -48,7 +49,7 @@ build: cp support/icons/hicolor/scalable/hildon/$(PROJECT_NAME).png $(BUILD_PATH)/scale-$(PROJECT_NAME).png cp support/builddeb.py $(BUILD_PATH) -lint: $(SOURCE) +lint: $(OBJ) $(foreach file, $(SOURCE), $(LINT) $(file) ; ) tags: $(TAG_FILE) @@ -66,10 +67,13 @@ distclean: find $(SOURCE_PATH) -name "*.bak" | xargs rm -f find $(SOURCE_PATH) -name ".*.swp" | xargs rm -f -$(TAG_FILE): $(SOURCE) +$(TAG_FILE): $(OBJ) mkdir -p $(dir $(TAG_FILE)) $(CTAGS) -o $(TAG_FILE) $(SOURCE) +%.pyc: %.py + $(SYNTAX_TEST) $< + #Makefile Debugging #Target to print any variable, can be added to the dependencies of any other target #Userfule flags for make, -d, -p, -n diff --git a/support/test_syntax.py b/support/test_syntax.py new file mode 100755 index 0000000..65a373c --- /dev/null +++ b/support/test_syntax.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import commands + + +verbose = False + + +def syntax_test(file): + commandTemplate = """ + python -t -t -W all -c "import py_compile; py_compile.compile ('%(filename)s', doraise=False)" """ + compileCommand = commandTemplate % {"filename": file} + (status, text) = commands.getstatusoutput (compileCommand) + text = text.rstrip() + passed = len(text) == 0 + + if passed: + output = ("Syntax is correct for "+file) if verbose else "" + else: + output = ("Syntax is invalid for %s\n" % file) if verbose else "" + output += text + return (passed, output) + + +if __name__ == "__main__": + import sys + import os + import optparse + + opar = optparse.OptionParser() + opar.add_option("-v", "--verbose", dest="verbose", help="Toggle verbosity", action="store_true", default=False) + options, args = opar.parse_args(sys.argv[1:]) + verbose = options.verbose + + completeOutput = [] + allPassed = True + for filename in args: + passed, output = syntax_test(filename) + if not passed: + allPassed = False + if output.strip(): + completeOutput.append(output) + print "\n".join(completeOutput) + + sys.exit(0 if allPassed else 1); -- 1.7.9.5