Skip to content

Commit 5cbd078

Browse files
committed
Refactor to mixin
1 parent 23290a8 commit 5cbd078

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

readthedocs/doc_builder/environments.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,7 @@ def run_command_class(self, cls, cmd, warn_only=False, **kwargs):
347347
return build_cmd
348348

349349

350-
class LocalEnvironment(BaseEnvironment):
351-
352-
# TODO: BuildCommand name doesn't make sense here, should be just Command
353-
command_class = BuildCommand
350+
class PostCommandRecordMixin(object):
354351

355352
def post_run_command(self):
356353
command = self.commands[-1]
@@ -359,6 +356,12 @@ def post_run_command(self):
359356
if self.record:
360357
command.save()
361358

359+
360+
class LocalEnvironment(BaseEnvironment, PostCommandRecordMixin):
361+
362+
# TODO: BuildCommand name doesn't make sense here, should be just Command
363+
command_class = BuildCommand
364+
362365
def run(self, *cmd, **kwargs):
363366
self.record = kwargs.pop('record', False)
364367
self.record_as_success = kwargs.pop('record_as_success', False)
@@ -381,7 +384,7 @@ def run_command_class(self, *cmd, **kwargs): # noqa
381384
return super(LocalEnvironment, self).run_command_class(*cmd, **kwargs)
382385

383386

384-
class BuildEnvironment(BaseEnvironment):
387+
class BuildEnvironment(BaseEnvironment, PostCommandRecordMixin):
385388

386389
"""
387390
Base build environment.
@@ -459,13 +462,6 @@ def handle_exception(self, exc_type, exc_value, _):
459462
self.failure = exc_value
460463
return True
461464

462-
def post_run_command(self):
463-
command = self.commands[-1]
464-
if self.record_as_success:
465-
command.exit_code = 0
466-
if self.record:
467-
command.save()
468-
469465
def run(self, *cmd, **kwargs):
470466
kwargs.update({
471467
'build_env': self,

0 commit comments

Comments
 (0)