Skip to content

Clean arttifacts before and after builds #5409

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
Closed
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
18 changes: 11 additions & 7 deletions readthedocs/doc_builder/backends/sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def append_conf(self, **__):
)

def build(self):
self.clean()
project = self.project
build_command = [
'python',
Expand Down Expand Up @@ -237,29 +236,35 @@ class HtmlBuilder(BaseSphinx):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.sphinx_builder = 'readthedocs'
self.json_path = os.path.abspath(
os.path.join(self.old_artifact_path, '..', 'json'),
)

def move(self, **__):
super().move()
# Copy JSON artifacts to its own directory
# to keep compatibility with the older builder.
json_path = os.path.abspath(
os.path.join(self.old_artifact_path, '..', 'json'),
)
json_path_target = self.project.artifact_path(
version=self.version.slug,
type_='sphinx_search',
)
if os.path.exists(json_path):
if os.path.exists(self.json_path):
if os.path.exists(json_path_target):
shutil.rmtree(json_path_target)
log.info('Copying json on the local filesystem')
shutil.copytree(
json_path,
self.json_path,
json_path_target,
)
else:
log.warning('Not moving json because the build dir is unknown.',)

def clean(self, **__):
super().clean()
if os.path.exists(self.json_path):
log.info('Removing old artifact path: %s', self.json_path)
shutil.rmtree(self.json_path)


class HtmlDirBuilder(HtmlBuilder):
type = 'sphinx_htmldir'
Expand Down Expand Up @@ -367,7 +372,6 @@ class PdfBuilder(BaseSphinx):
pdf_file_name = None

def build(self):
self.clean()
cwd = os.path.dirname(self.config_file)

# Default to this so we can return it always.
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/doc_builder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def move(self, **__):
def clean(self, **__):
"""Clean the path where documentation will be built."""
if os.path.exists(self.old_artifact_path):
shutil.rmtree(self.old_artifact_path)
log.info('Removing old artifact path: %s', self.old_artifact_path)
shutil.rmtree(self.old_artifact_path)

def docs_dir(self, docs_dir=None, **__):
"""Handle creating a custom docs_dir if it doesn't exist."""
Expand Down
4 changes: 4 additions & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,11 @@ def build_docs_html(self):
if self.build_force:
html_builder.force()
html_builder.append_conf()
html_builder.clean()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should refactor build_docs_html to use build_docs_class, but not so trivial code needs to be moved around, so keeping simple this for now. I'm creating a new issue to refactor this later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

success = html_builder.build()
if success:
html_builder.move()
html_builder.clean()

# Gracefully attempt to move files via task on web workers.
try:
Expand Down Expand Up @@ -912,8 +914,10 @@ def build_docs_class(self, builder_class):
self.build_env,
python_env=self.python_env,
)
builder.clean()
success = builder.build()
builder.move()
builder.clean()
return success

def send_notifications(self):
Expand Down