From 93e886be234fd187c4ddc5e376fd6c51060500a7 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Fri, 13 Nov 2015 12:51:00 -0600 Subject: print out every file that has a syntax error --- pyramid/scripts/pserve.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 4a6e917a7..1e580d897 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -18,6 +18,7 @@ import py_compile import re import subprocess import sys +import tempfile import textwrap import threading import time @@ -847,8 +848,16 @@ class Monitor(object): # pragma: no cover self.syntax_error_files = set() self.pending_reload = False self.file_callbacks = list(self.global_file_callbacks) + temp_pyc_fp = tempfile.NamedTemporaryFile(delete=False) + self.temp_pyc = temp_pyc_fp.name + temp_pyc_fp.close() def _exit(self): + try: + os.unlink(self.temp_pyc) + except IOError: + # not worried if the tempfile can't be removed + pass # use os._exit() here and not sys.exit() since within a # thread sys.exit() just closes the given thread and # won't kill the process; note os._exit does not call @@ -879,6 +888,7 @@ class Monitor(object): # pragma: no cover continue if filename is not None: filenames.append(filename) + new_changes = False for filename in filenames: try: stat = os.stat(filename) @@ -896,7 +906,7 @@ class Monitor(object): # pragma: no cover old_mtime = self.module_mtimes.get(filename) self.module_mtimes[filename] = mtime if old_mtime is not None and old_mtime < mtime: - self.pending_reload = True + new_changes = True if pyc: filename = filename[:-1] is_valid = True @@ -904,6 +914,11 @@ class Monitor(object): # pragma: no cover is_valid = self.check_syntax(filename) if is_valid: print("%s changed ..." % filename) + if new_changes: + self.pending_reload = True + if self.syntax_error_files: + for filename in sorted(self.syntax_error_files): + print("%s has a SyntaxError; NOT reloading." % filename) if self.pending_reload and not self.syntax_error_files: self.pending_reload = False return False @@ -913,9 +928,9 @@ class Monitor(object): # pragma: no cover # check if a file has syntax errors. # If so, track it until it's fixed. try: - py_compile.compile(filename, doraise=True) - except py_compile.PyCompileError: - print("%s has a SyntaxError; NOT reloading." % filename) + py_compile.compile(filename, cfile=self.temp_pyc, doraise=True) + except py_compile.PyCompileError as ex: + print(ex.msg) self.syntax_error_files.add(filename) return False else: -- cgit v1.2.3