summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2015-11-13 12:51:00 -0600
committerMichael Merickel <michael@merickel.org>2015-11-13 12:51:00 -0600
commit93e886be234fd187c4ddc5e376fd6c51060500a7 (patch)
treef0b829bf86c3e6ee40e4374de05e7b31994f3df8
parent565058df3e98ba45945b6254b5c69c3de399bcb7 (diff)
downloadpyramid-93e886be234fd187c4ddc5e376fd6c51060500a7.tar.gz
pyramid-93e886be234fd187c4ddc5e376fd6c51060500a7.tar.bz2
pyramid-93e886be234fd187c4ddc5e376fd6c51060500a7.zip
print out every file that has a syntax error
-rw-r--r--pyramid/scripts/pserve.py23
1 files 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: