Skip to content

pylint fix for readthedocs.doc_builder #5660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,12 @@ def run_command_class(

if warn_only:
log.warning(
LOG_TEMPLATE.format(
project=self.project.slug,
version='latest',
msg=msg,
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': 'latest',
'msg': msg,
}
)
else:
raise BuildEnvironmentWarning(msg)
Expand Down Expand Up @@ -551,11 +552,12 @@ def __exit__(self, exc_type, exc_value, tb):
ret = self.handle_exception(exc_type, exc_value, tb)
self.update_build(BUILD_STATE_FINISHED)
log.info(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Build finished',
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': 'Build finished',
}
)
return ret

Expand Down Expand Up @@ -586,11 +588,12 @@ def handle_exception(self, exc_type, exc_value, _):
self.failure = exc_value

log_level_function(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=exc_value,
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': exc_value,
},
exc_info=True,
extra={
'stack': True,
Expand Down Expand Up @@ -820,15 +823,16 @@ def __enter__(self):
raise exc
else:
log.warning(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=(
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': (
'Removing stale container {}'.format(
self.container_id,
)
),
),
}
)
client = self.get_client()
client.remove_container(self.container_id)
Expand Down Expand Up @@ -874,11 +878,12 @@ def __exit__(self, exc_type, exc_value, tb):
# request. These errors should not surface to the user.
except (DockerAPIError, ConnectionError):
log.exception(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg="Couldn't remove container",
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': "Couldn't remove container",
}
)
self.container = None
except BuildEnvironmentError:
Expand All @@ -902,11 +907,12 @@ def get_client(self):
return self.client
except DockerException:
log.exception(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Could not connect to Docker API',
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': "Could not connect to Docker API",
}
)
# We don't raise an error here mentioning Docker, that is a
# technical detail that the user can't resolve on their own.
Expand Down Expand Up @@ -1024,14 +1030,15 @@ def create_container(self):
client.start(container=self.container_id)
except ConnectionError:
log.exception(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=(
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': (
'Could not connect to the Docker API, '
'make sure Docker is running'
),
),
}
)
# We don't raise an error here mentioning Docker, that is a
# technical detail that the user can't resolve on their own.
Expand All @@ -1043,10 +1050,11 @@ def create_container(self):
)
except DockerAPIError as e:
log.exception(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg=e.explanation,
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': e.explanation,
}
)
raise BuildEnvironmentCreationFailed
33 changes: 18 additions & 15 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def delete_existing_build_dir(self):
)
if os.path.exists(build_dir):
log.info(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Removing existing build directory',
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': 'Removing existing build directory',
}
)
shutil.rmtree(build_dir)

Expand All @@ -57,11 +58,12 @@ def delete_existing_venv_dir(self):
# Handle deleting old venv dir
if os.path.exists(venv_dir):
log.info(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Removing existing venv directory',
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': 'Removing existing venv directory',
}
)
shutil.rmtree(venv_dir)

Expand Down Expand Up @@ -413,11 +415,12 @@ def setup_base(self):
if os.path.exists(version_path):
# Re-create conda directory each time to keep fresh state
log.info(
LOG_TEMPLATE.format(
project=self.project.slug,
version=self.version.slug,
msg='Removing existing conda directory',
),
LOG_TEMPLATE,
{
'project': self.project.slug,
'version': self.version.slug,
'msg': 'Removing existing conda directory',
}
)
shutil.rmtree(version_path)
self.build_env.run(
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
('other', 'Other'),
)

LOG_TEMPLATE = '(Build) [{project}:{version}] {msg}'
LOG_TEMPLATE = '(Build) [%(project)s:%(version)s] %(msg)s'

PROJECT_PK_REGEX = r'(?:[-\w]+)'
PROJECT_SLUG_REGEX = r'(?:[-\w]+)'
Expand Down