mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Better ignore syntaxerror stack traces in wheels
This already got stripped just fine for non-wheel installs, but for wheels, it only stripped the lined where `SyntaxError` was present leaving the rest of the stacktrace.
This commit is contained in:
parent
4411d86f04
commit
334af19e7c
|
@ -662,14 +662,14 @@ def unpack_file(filename, location, content_type, link):
|
|||
|
||||
|
||||
def remove_tracebacks(output):
|
||||
pattern = (r'\W+File "(.*)", line (.*)\W+(.*)\W+\^\W+'
|
||||
r'Syntax(Error|Warning): (.*)')
|
||||
pattern = (r'(?:\W+File "(?:.*)", line (?:.*)\W+(?:.*)\W+\^\W+)?'
|
||||
r'Syntax(?:Error|Warning): (?:.*)')
|
||||
output = re.sub(pattern, '', output)
|
||||
if PY2:
|
||||
return output
|
||||
# compileall.compile_dir() prints different messages to stdout
|
||||
# in Python 3
|
||||
return re.sub(r"\*\*\* Error compiling (.*)", '', output)
|
||||
return re.sub(r"\*\*\* Error compiling (?:.*)", '', output)
|
||||
|
||||
|
||||
def call_subprocess(cmd, show_stdout=True,
|
||||
|
|
12
pip/wheel.py
12
pip/wheel.py
|
@ -27,7 +27,6 @@ from pip.utils.logging import indent_log
|
|||
from pip._vendor.distlib.scripts import ScriptMaker
|
||||
from pip._vendor import pkg_resources
|
||||
from pip._vendor.six.moves import configparser
|
||||
from pip._vendor.six import PY2
|
||||
|
||||
|
||||
wheel_ext = '.whl'
|
||||
|
@ -162,16 +161,7 @@ def move_wheel_files(name, req, wheeldir, user=False, home=None, root=None,
|
|||
if pycompile:
|
||||
with captured_stdout() as stdout:
|
||||
compileall.compile_dir(source, force=True, quiet=True)
|
||||
# compileall.compile_dir() prints different exception to stdout
|
||||
# in Python 2, so we need a new helper to remove tracebacks
|
||||
# for Python 3
|
||||
if PY2:
|
||||
lines = [line for line in stdout.getvalue().splitlines()
|
||||
if not line.startswith(('SyntaxError:',
|
||||
'SyntaxWarning:'))]
|
||||
print('\n'.join(lines))
|
||||
else:
|
||||
print(remove_tracebacks(stdout.getvalue()))
|
||||
logger.info(remove_tracebacks(stdout.getvalue()))
|
||||
|
||||
def normpath(src, p):
|
||||
return make_path_relative(src, p).replace(os.path.sep, '/')
|
||||
|
|
|
@ -319,4 +319,5 @@ def test_install_from_wheel_uninstalls_old_version(script, data):
|
|||
def test_wheel_compile_syntax_error(script, data):
|
||||
package = data.packages.join("compilewheel-1.0-py2.py3-none-any.whl")
|
||||
result = script.pip('install', '--compile', package, '--no-index')
|
||||
assert 'yield from' not in result.stdout
|
||||
assert 'SyntaxError: ' not in result.stdout
|
||||
|
|
Loading…
Reference in a new issue