Skip to content

Pass record to command #5028

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

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 9 additions & 13 deletions readthedocs/doc_builder/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class BuildCommand(BuildCommandResultMixin):

def __init__(self, command, cwd=None, shell=False, environment=None,
combine_output=True, input_data=None, build_env=None,
bin_path=None, description=None, record_as_success=False):
bin_path=None, description=None, record=False,
record_as_success=False):
self.command = command
self.shell = shell
if cwd is None:
Expand All @@ -101,6 +102,7 @@ def __init__(self, command, cwd=None, shell=False, environment=None,
self.description = ''
if description is not None:
self.description = description
self.record = record
self.record_as_success = record_as_success
self.exit_code = None

Expand Down Expand Up @@ -176,6 +178,8 @@ def run(self):
self.exit_code = -1
finally:
self.end_time = datetime.utcnow()
if self.record:
self.save()

def sanitize_output(self, output):
r"""
Expand Down Expand Up @@ -303,6 +307,8 @@ def run(self):
self.output = _('Command exited abnormally')
finally:
self.end_time = datetime.utcnow()
if self.record:
self.save()

def get_wrapped_command(self):
"""
Expand Down Expand Up @@ -341,9 +347,6 @@ def __init__(self, project, environment=None):
self.environment = environment or {}
self.commands = []

def record_command(self, command):
pass

def run(self, *cmd, **kwargs):
"""Shortcut to run command from environment."""
return self.run_command_class(cls=self.command_class, cmd=cmd, **kwargs)
Expand Down Expand Up @@ -381,21 +384,17 @@ def run_command_class(
kwargs['bin_path'] = env_path
assert 'environment' not in kwargs, "environment can't be passed in via commands."
kwargs['environment'] = self.environment
kwargs['record'] = record

# ``build_env`` is passed as ``kwargs`` when it's called from a
# ``*BuildEnvironment``
build_cmd = cls(cmd, **kwargs)
build_cmd.run()

if record:
# TODO: I don't like how it's handled this entry point here since
# this class should know nothing about a BuildCommand (which are the
# only ones that can be saved/recorded)
self.record_command(build_cmd)

# We want append this command to the list of commands only if it has
# to be recorded in the database (to keep consistency) and also, it
# has to be added after ``self.record_command`` since its
# has to be added after ``build_cmd.run()`` since its
# ``exit_code`` can be altered because of ``record_as_success``
self.commands.append(build_cmd)

Expand Down Expand Up @@ -537,9 +536,6 @@ def handle_exception(self, exc_type, exc_value, _):
)
return True

def record_command(self, command):
command.save()

def run(self, *cmd, **kwargs):
kwargs.update({
'build_env': self,
Expand Down