Skip to content

Commit e7ce7d7

Browse files
committed
Use record_as_success instead of force_success
We need the real exit_code for some command since there are decisions based on that code, but we want to record it as success. So, the fake exit_code is saved in the database but the real exit_code is used in the whole flow of the building process.
1 parent d833b2d commit e7ce7d7

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BuildCommand(BuildCommandResultMixin):
7373

7474
def __init__(self, command, cwd=None, shell=False, environment=None,
7575
combine_output=True, input_data=None, build_env=None,
76-
bin_path=None, description=None):
76+
bin_path=None, description=None, record_as_success=False):
7777
self.command = command
7878
self.shell = shell
7979
if cwd is None:
@@ -96,6 +96,7 @@ def __init__(self, command, cwd=None, shell=False, environment=None,
9696
self.description = ''
9797
if description is not None:
9898
self.description = description
99+
self.record_as_success = record_as_success
99100
self.exit_code = None
100101

101102
def __str__(self):
@@ -183,12 +184,21 @@ def get_command(self):
183184

184185
def save(self):
185186
"""Save this command and result via the API."""
187+
exit_code = self.exit_code
188+
189+
# Force record this command as success to avoid Build reporting errors
190+
# on commands that are just for checking purposes and do not interferes
191+
# in the Build
192+
if self.record_as_success:
193+
log.warning('Recording command exit_code as success')
194+
exit_code = 0
195+
186196
data = {
187197
'build': self.build_env.build.get('id'),
188198
'command': self.get_command(),
189199
'description': self.description,
190200
'output': self.output,
191-
'exit_code': self.exit_code,
201+
'exit_code': exit_code,
192202
'start_time': self.start_time,
193203
'end_time': self.end_time,
194204
}
@@ -300,8 +310,8 @@ def run(self, *cmd, **kwargs):
300310
return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
301311

302312
def run_command_class(
303-
self, cls, cmd, record=None, warn_only=False, force_success=False,
304-
**kwargs):
313+
self, cls, cmd, record=None, warn_only=False,
314+
record_as_success=False, **kwargs):
305315
"""
306316
Run command from this environment.
307317
@@ -310,16 +320,22 @@ def run_command_class(
310320
:param record: whether or not to record this particular command
311321
(``False`` implies ``warn_only=True``)
312322
:param warn_only: don't raise an exception on command failure
313-
:param force_success: force command ``exit_code`` to be saved as ``0``
314-
(``True`` implies ``warn_only=True``)
323+
:param record_as_success: force command ``exit_code`` to be saved as
324+
``0`` (``True`` implies ``warn_only=True`` and ``record=True``)
315325
"""
316326
if record is None:
317327
# ``self.record`` only exists when called from ``*BuildEnvironment``
318328
record = getattr(self, 'record', False)
319329

320-
if not record or force_success:
330+
if not record:
321331
warn_only = True
322332

333+
if record_as_success:
334+
record = True
335+
warn_only = True
336+
# ``record_as_success`` is needed to instantiate the BuildCommand
337+
kwargs.update({'record_as_success': record_as_success})
338+
323339
# Remove PATH from env, and set it to bin_path if it isn't passed in
324340
env_path = self.environment.pop('BIN_PATH', None)
325341
if 'bin_path' not in kwargs and env_path:
@@ -340,10 +356,6 @@ def run_command_class(
340356
self.record_command(build_cmd)
341357

342358
if build_cmd.failed:
343-
if force_success:
344-
self._log_warning('Forcing command to exit gracefully (exit_code = 0)')
345-
build_cmd.exit_code = 0
346-
347359
msg = u'Command {cmd} failed'.format(cmd=build_cmd.get_command())
348360

349361
if build_cmd.output:
@@ -445,8 +457,7 @@ def handle_exception(self, exc_type, exc_value, _):
445457
return True
446458

447459
def record_command(self, command):
448-
if self.record:
449-
command.save()
460+
command.save()
450461

451462
def _log_warning(self, msg):
452463
# :'(

0 commit comments

Comments
 (0)