未验证 提交 9875055f 编写于 作者: P Paul Moore 提交者: GitHub

Merge pull request #5239 from pradyunsg/fix/5237

Improve Error Messages on EnvironmentErrors when installing
Fix and improve error message when EnvironmentError occurs during installation.
......@@ -358,25 +358,14 @@ class InstallCommand(RequirementCommand):
installed = ' '.join(items)
if installed:
logger.info('Successfully installed %s', installed)
except EnvironmentError as e:
message_parts = []
user_option_part = "Consider using the `--user` option"
permissions_part = "Check the permissions"
if e.errno == errno.EPERM:
if not options.use_user_site:
message_parts.extend([
user_option_part, " or ",
permissions_part.lower(),
])
else:
message_parts.append(permissions_part)
message_parts.append("\n")
except EnvironmentError as error:
show_traceback = (self.verbosity >= 1)
logger.error(
"".join(message_parts), exc_info=(self.verbosity > 1)
message = create_env_error_message(
error, show_traceback, options.use_user_site,
)
logger.error(message, exc_info=show_traceback)
return ERROR
except PreviousBuildDirError:
options.no_clean = True
......@@ -475,3 +464,39 @@ class InstallCommand(RequirementCommand):
def get_lib_location_guesses(*args, **kwargs):
scheme = distutils_scheme('', *args, **kwargs)
return [scheme['purelib'], scheme['platlib']]
def create_env_error_message(error, show_traceback, using_user_site):
"""Format an error message for an EnvironmentError
It may occur anytime during the execution of the install command.
"""
parts = []
# Mention the error if we are not going to show a traceback
parts.append("Could not install packages due to an EnvironmentError")
if not show_traceback:
parts.append(": ")
parts.append(str(error))
else:
parts.append(".")
# Spilt the error indication from a helper message (if any)
parts[-1] += "\n"
# Suggest useful actions to the user:
# (1) using user site-packages or (2) verifying the permissions
if error.errno == errno.EACCES:
user_option_part = "Consider using the `--user` option"
permissions_part = "Check the permissions"
if not using_user_site:
parts.extend([
user_option_part, " or ",
permissions_part.lower(),
])
else:
parts.append(permissions_part)
parts.append(".\n")
return "".join(parts).strip() + "\n"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册