From ddaeb7071c2e3d1d166230309c525ceb3581d061 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Wed, 6 Mar 2019 15:20:45 -0500 Subject: [PATCH 1/2] Clean arttifacts before and after builds --- readthedocs/doc_builder/backends/sphinx.py | 18 +++++++++++------- readthedocs/projects/tasks.py | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py index c5a664835fa..0664404b7b7 100644 --- a/readthedocs/doc_builder/backends/sphinx.py +++ b/readthedocs/doc_builder/backends/sphinx.py @@ -202,7 +202,6 @@ def append_conf(self, **__): ) def build(self): - self.clean() project = self.project build_command = [ 'python', @@ -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): + shutil.rmtree(self.json_path) + log.info('Removing old artifact path: %s', self.json_path) + class HtmlDirBuilder(HtmlBuilder): type = 'sphinx_htmldir' @@ -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. diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index 103dbbf7599..3a20941a1ff 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -845,9 +845,11 @@ def build_docs_html(self): if self.build_force: html_builder.force() html_builder.append_conf() + html_builder.clean() success = html_builder.build() if success: html_builder.move() + html_builder.clean() # Gracefully attempt to move files via task on web workers. try: @@ -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): From 6def40f52a6b7f80f126916ff5bd3cf0fee0df91 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 11 Mar 2019 11:35:18 -0500 Subject: [PATCH 2/2] Log before removing --- readthedocs/doc_builder/backends/sphinx.py | 2 +- readthedocs/doc_builder/base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py index 0664404b7b7..d5a69c3b3af 100644 --- a/readthedocs/doc_builder/backends/sphinx.py +++ b/readthedocs/doc_builder/backends/sphinx.py @@ -262,8 +262,8 @@ def move(self, **__): def clean(self, **__): super().clean() if os.path.exists(self.json_path): - shutil.rmtree(self.json_path) log.info('Removing old artifact path: %s', self.json_path) + shutil.rmtree(self.json_path) class HtmlDirBuilder(HtmlBuilder): diff --git a/readthedocs/doc_builder/base.py b/readthedocs/doc_builder/base.py index 1f5712feb6a..cb7658b5146 100644 --- a/readthedocs/doc_builder/base.py +++ b/readthedocs/doc_builder/base.py @@ -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."""