diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-12-26 22:29:53 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-12-26 22:29:53 (GMT) |
commit | 5874ed6cee569a73cd0e947605210822b251df7f (patch) | |
tree | 804b3a120d312569f8d1d8217ed24dc491391458 /Lib/site.py | |
parent | 8e726b4328cc6db1c9524aa4f4d52c4921d9020a (diff) | |
download | cpython-5874ed6cee569a73cd0e947605210822b251df7f.zip cpython-5874ed6cee569a73cd0e947605210822b251df7f.tar.gz cpython-5874ed6cee569a73cd0e947605210822b251df7f.tar.bz2 |
Merged revisions 87497 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r87497 | r.david.murray | 2010-12-26 14:54:29 -0500 (Sun, 26 Dec 2010) | 7 lines
#5258/#10642: print fn, line, traceback and continue when .pth file is broken
If a .pth file contained an error, it could cause a traceback in site.py,
terminating its processing. In 2.7 and 3.2, the interpreter will then not
start. Previously, a message would print saying to use -v to get the
traceback. In either case, the traceback generated for a failed .pth file did
not include the .pth filename, making it difficult to debug the problem. Now
site.py reports not only the .pth filename but also the line number causing the
error, and just skips the remainder of the file.
........
Diffstat (limited to 'Lib/site.py')
-rw-r--r-- | Lib/site.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/Lib/site.py b/Lib/site.py index f22e1d1..90cf331 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -61,6 +61,7 @@ ImportError exception, it is silently ignored. import sys import os import __builtin__ +import traceback # Prefixes for site-packages; add additional prefixes like /usr/local here PREFIXES = [sys.prefix, sys.exec_prefix] @@ -155,17 +156,26 @@ def addpackage(sitedir, name, known_paths): except IOError: return with f: - for line in f: + for n, line in enumerate(f): if line.startswith("#"): continue - if line.startswith(("import ", "import\t")): - exec line - continue - line = line.rstrip() - dir, dircase = makepath(sitedir, line) - if not dircase in known_paths and os.path.exists(dir): - sys.path.append(dir) - known_paths.add(dircase) + try: + if line.startswith(("import ", "import\t")): + exec line + continue + line = line.rstrip() + dir, dircase = makepath(sitedir, line) + if not dircase in known_paths and os.path.exists(dir): + sys.path.append(dir) + known_paths.add(dircase) + except Exception as err: + print >>sys.stderr, "Error processing line {:d} of {}:\n".format( + n+1, fullname) + for record in traceback.format_exception(*sys.exc_info()): + for line in record.splitlines(): + print >>sys.stderr, ' '+line + print >>sys.stderr, "\nRemainder of file ignored" + break if reset: known_paths = None return known_paths |