Commit 8d06c3c3 authored by Jim Fulton's avatar Jim Fulton

- Tracebacks are now printed for internal errors (as opposed to user

  errors) even without the -D option.

- pyc and pyo files are regenerated for installed eggs so that the
  stored path in code objects matches the the install location.
parent 69086ce2
...@@ -4,12 +4,18 @@ Status ...@@ -4,12 +4,18 @@ Status
Change History Change History
************** **************
1.1 (unreleased) 1.1 (2008-07-19)
================== ================
- Added a buildout-level unzip option tp change the default policy for - Added a buildout-level unzip option tp change the default policy for
unzipping zip-safe eggs. unzipping zip-safe eggs.
- Tracebacks are now printed for internal errors (as opposed to user
errors) even without the -D option.
- pyc and pyo files are regenerated for installed eggs so that the
stored path in code objects matches the the install location.
1.0.6 (2008-06-13) 1.0.6 (2008-06-13)
================== ==================
......
...@@ -1256,9 +1256,6 @@ def _error(*message): ...@@ -1256,9 +1256,6 @@ def _error(*message):
_internal_error_template = """ _internal_error_template = """
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
%s:
%s
""" """
def _check_for_unused_options_in_section(buildout, section): def _check_for_unused_options_in_section(buildout, section):
...@@ -1269,11 +1266,6 @@ def _check_for_unused_options_in_section(buildout, section): ...@@ -1269,11 +1266,6 @@ def _check_for_unused_options_in_section(buildout, section):
% (section, ' '.join(map(repr, unused))) % (section, ' '.join(map(repr, unused)))
) )
def _internal_error(v):
sys.stderr.write(_internal_error_template % (v.__class__.__name__, v))
sys.exit(1)
_usage = """\ _usage = """\
Usage: buildout [options] [assignments] [command [command arguments]] Usage: buildout [options] [assignments] [command [command arguments]]
...@@ -1482,9 +1474,9 @@ def main(args=None): ...@@ -1482,9 +1474,9 @@ def main(args=None):
pass pass
except Exception, v: except Exception, v:
_doing() _doing()
if debug:
exc_info = sys.exc_info() exc_info = sys.exc_info()
import pdb, traceback import pdb, traceback
if debug:
traceback.print_exception(*exc_info) traceback.print_exception(*exc_info)
sys.stderr.write('\nStarting pdb:\n') sys.stderr.write('\nStarting pdb:\n')
pdb.post_mortem(exc_info[2]) pdb.post_mortem(exc_info[2])
...@@ -1495,7 +1487,10 @@ def main(args=None): ...@@ -1495,7 +1487,10 @@ def main(args=None):
): ):
_error(str(v)) _error(str(v))
else: else:
_internal_error(v) sys.stderr.write(_internal_error_template)
traceback.print_exception(*exc_info)
sys.exit(1)
finally: finally:
logging.shutdown() logging.shutdown()
......
...@@ -449,7 +449,7 @@ leave previously created paths in place: ...@@ -449,7 +449,7 @@ leave previously created paths in place:
... path = foo bin ... path = foo bin
... """) ... """)
>>> print system(buildout), >>> print system(buildout), # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Uninstalling data-dir. Uninstalling data-dir.
Installing data-dir. Installing data-dir.
...@@ -460,9 +460,9 @@ leave previously created paths in place: ...@@ -460,9 +460,9 @@ leave previously created paths in place:
<BLANKLINE> <BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
<BLANKLINE> Traceback (most recent call last):
OSError: ...
[Errno 17] File exists: '/sample-buildout/bin' OSError: [Errno 17] File exists: '/sample-buildout/bin'
We meant to create a directory bins, but typed bin. Now foo was We meant to create a directory bins, but typed bin. Now foo was
left behind. left behind.
...@@ -483,7 +483,7 @@ If we fix the typo: ...@@ -483,7 +483,7 @@ If we fix the typo:
... path = foo bins ... path = foo bins
... """) ... """)
>>> print system(buildout), >>> print system(buildout), # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -492,9 +492,9 @@ If we fix the typo: ...@@ -492,9 +492,9 @@ If we fix the typo:
<BLANKLINE> <BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
<BLANKLINE> Traceback (most recent call last):
OSError: ...
[Errno 17] File exists: '/sample-buildout/foo' OSError: [Errno 17] File exists: '/sample-buildout/foo'
Now they fail because foo exists, because it was left behind. Now they fail because foo exists, because it was left behind.
...@@ -559,7 +559,7 @@ And put back the typo: ...@@ -559,7 +559,7 @@ And put back the typo:
When we rerun the buildout: When we rerun the buildout:
>>> print system(buildout), >>> print system(buildout), # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -569,9 +569,9 @@ When we rerun the buildout: ...@@ -569,9 +569,9 @@ When we rerun the buildout:
<BLANKLINE> <BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
<BLANKLINE> Traceback (most recent call last):
OSError: ...
[Errno 17] File exists: '/sample-buildout/bin' OSError: [Errno 17] File exists: '/sample-buildout/bin'
we get the same error, but we don't get the directory left behind: we get the same error, but we don't get the directory left behind:
...@@ -635,7 +635,7 @@ It would be simpler just to return the paths as before. ...@@ -635,7 +635,7 @@ It would be simpler just to return the paths as before.
If we rerun the buildout, again, we'll get the error and no If we rerun the buildout, again, we'll get the error and no
directories will be created: directories will be created:
>>> print system(buildout), >>> print system(buildout), # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
Installing data-dir. Installing data-dir.
data-dir: Creating directory foo data-dir: Creating directory foo
...@@ -645,9 +645,9 @@ directories will be created: ...@@ -645,9 +645,9 @@ directories will be created:
<BLANKLINE> <BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
<BLANKLINE> Traceback (most recent call last):
OSError: ...
[Errno 17] File exists: '/sample-buildout/bin' OSError: [Errno 17] File exists: '/sample-buildout/bin'
>>> os.path.exists('foo') >>> os.path.exists('foo')
False False
......
...@@ -20,13 +20,22 @@ installed. ...@@ -20,13 +20,22 @@ installed.
$Id$ $Id$
""" """
import glob, logging, os, re, shutil, sys, tempfile, urlparse, zipimport
import distutils.errors import distutils.errors
import glob
import logging
import os
import pkg_resources import pkg_resources
import py_compile
import re
import setuptools.archive_util
import setuptools.command.setopt import setuptools.command.setopt
import setuptools.package_index import setuptools.package_index
import setuptools.archive_util import shutil
import sys
import tempfile
import urlparse
import zc.buildout import zc.buildout
import zipimport
_oprp = getattr(os.path, 'realpath', lambda path: path) _oprp = getattr(os.path, 'realpath', lambda path: path)
def realpath(path): def realpath(path):
...@@ -570,6 +579,7 @@ class Installer: ...@@ -570,6 +579,7 @@ class Installer:
if ws.find(requirement) is None: if ws.find(requirement) is None:
for dist in self._get_dist(requirement, ws, False): for dist in self._get_dist(requirement, ws, False):
ws.add(dist) ws.add(dist)
redo_pyc(dist.location)
def _constrain(self, requirement): def _constrain(self, requirement):
...@@ -607,6 +617,7 @@ class Installer: ...@@ -607,6 +617,7 @@ class Installer:
for requirement in requirements: for requirement in requirements:
for dist in self._get_dist(requirement, ws, self._always_unzip): for dist in self._get_dist(requirement, ws, self._always_unzip):
ws.add(dist) ws.add(dist)
redo_pyc(dist.location)
self._maybe_add_setuptools(ws, dist) self._maybe_add_setuptools(ws, dist)
# OK, we have the requested distributions and they're in the working # OK, we have the requested distributions and they're in the working
...@@ -633,6 +644,7 @@ class Installer: ...@@ -633,6 +644,7 @@ class Installer:
): ):
ws.add(dist) ws.add(dist)
redo_pyc(dist.location)
self._maybe_add_setuptools(ws, dist) self._maybe_add_setuptools(ws, dist)
except pkg_resources.VersionConflict, err: except pkg_resources.VersionConflict, err:
raise VersionConflict(err, ws) raise VersionConflict(err, ws)
...@@ -696,6 +708,9 @@ class Installer: ...@@ -696,6 +708,9 @@ class Installer:
base, pkg_resources.WorkingSet(), base, pkg_resources.WorkingSet(),
self._dest, dist) self._dest, dist)
for dist in dists:
redo_pyc(dist.location)
return [dist.location for dist in dists] return [dist.location for dist in dists]
finally: finally:
shutil.rmtree(build_tmp) shutil.rmtree(build_tmp)
...@@ -1087,3 +1102,37 @@ def _final_version(parsed_version): ...@@ -1087,3 +1102,37 @@ def _final_version(parsed_version):
if (part[:1] == '*') and (part not in _final_parts): if (part[:1] == '*') and (part not in _final_parts):
return False return False
return True return True
def redo_pyc(egg):
if not os.path.isdir(egg):
return
for dirpath, dirnames, filenames in os.walk(egg):
for filename in filenames:
if not filename.endswith('.py'):
continue
filepath = os.path.join(dirpath, filename)
if not (os.path.exists(filepath+'c')
or os.path.exists(filepath+'o')):
# If it wasn't compiled, it may not be compilable
continue
# OK, it looks like we should try to compile.
# Remove old files.
for suffix in 'co':
if os.path.exists(filepath+suffix):
os.remove(filepath+suffix)
# Compile under current optimization
try:
py_compile.compile(filepath)
except py_compile.PyCompileError:
logger.warning("Couldn't compile %s", filepath)
else:
# Recompile under other optimization. :)
args = [sys.executable]
if __debug__:
args.append('-O')
args.extend(['-m', 'py_compile', filepath])
os.spawnv(os.P_WAIT, sys.executable, args)
...@@ -1359,7 +1359,7 @@ def internal_errors(): ...@@ -1359,7 +1359,7 @@ def internal_errors():
... recipe = recipes:mkdir ... recipe = recipes:mkdir
... ''') ... ''')
>>> print system(buildout), >>> print system(buildout), # doctest: +ELLIPSIS
Develop: '/sample-buildout/recipes' Develop: '/sample-buildout/recipes'
While: While:
Installing. Installing.
...@@ -1368,9 +1368,9 @@ def internal_errors(): ...@@ -1368,9 +1368,9 @@ def internal_errors():
<BLANKLINE> <BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
<BLANKLINE> Traceback (most recent call last):
NameError: ...
global name 'os' is not defined NameError: global name 'os' is not defined
""" """
def whine_about_unused_options(): def whine_about_unused_options():
...@@ -1812,7 +1812,7 @@ if sys.version_info > (2, 4): ...@@ -1812,7 +1812,7 @@ if sys.version_info > (2, 4):
... recipe = zc.buildout.testexit ... recipe = zc.buildout.testexit
... ''') ... ''')
>>> call(buildout) # doctest: +NORMALIZE_WHITESPACE >>> call(buildout) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
Develop: '/sample-buildout/.' Develop: '/sample-buildout/.'
While: While:
Installing. Installing.
...@@ -1822,12 +1822,13 @@ if sys.version_info > (2, 4): ...@@ -1822,12 +1822,13 @@ if sys.version_info > (2, 4):
<BLANKLINE> <BLANKLINE>
An internal error occured due to a bug in either zc.buildout or in a An internal error occured due to a bug in either zc.buildout or in a
recipe being used: recipe being used:
<BLANKLINE> Traceback (most recent call last):
SyntaxError: ...
invalid syntax (testexitrecipe.py, line 2) x y
^
SyntaxError: invalid syntax
<BLANKLINE> <BLANKLINE>
Exit: True Exit: True
""" """
def bug_59270_recipes_always_start_in_buildout_dir(): def bug_59270_recipes_always_start_in_buildout_dir():
...@@ -2403,6 +2404,43 @@ honoring our version specification. ...@@ -2403,6 +2404,43 @@ honoring our version specification.
""" """
def pyc_and_pyo_files_have_correct_paths():
r"""
>>> write('buildout.cfg',
... '''
... [buildout]
... parts = eggs
... find-links = %(link_server)s
... unzip = true
...
... [eggs]
... recipe = zc.recipe.egg
... eggs = demo
... interpreter = py
... ''' % globals())
>>> _ = system(buildout)
>>> write('t.py',
... '''
... import eggrecipedemo, eggrecipedemoneeded
... print eggrecipedemo.main.func_code.co_filename
... print eggrecipedemoneeded.f.func_code.co_filename
... ''')
>>> print system(join('bin', 'py')+ ' t.py'),
/sample-buildout/eggs/demo-0.4c1-py2.4.egg/eggrecipedemo.py
/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg/eggrecipedemoneeded.py
>>> ls('eggs', 'demoneeded-1.2c1-py2.4.egg')
d EGG-INFO
- eggrecipedemoneeded.py
- eggrecipedemoneeded.pyc
- eggrecipedemoneeded.pyo
"""
###################################################################### ######################################################################
def create_sample_eggs(test, executable=sys.executable): def create_sample_eggs(test, executable=sys.executable):
...@@ -2413,7 +2451,7 @@ def create_sample_eggs(test, executable=sys.executable): ...@@ -2413,7 +2451,7 @@ def create_sample_eggs(test, executable=sys.executable):
write(tmp, 'README.txt', '') write(tmp, 'README.txt', '')
for i in (0, 1, 2): for i in (0, 1, 2):
write(tmp, 'eggrecipedemoneeded.py', 'y=%s\n' % i) write(tmp, 'eggrecipedemoneeded.py', 'y=%s\ndef f():\n pass' % i)
c1 = i==2 and 'c1' or '' c1 = i==2 and 'c1' or ''
write( write(
tmp, 'setup.py', tmp, 'setup.py',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment