Skip to content

Commit dd07a3e

Browse files
humitosagjohnson
andauthored
Build: check for _build/html directory and fail if exists (#10126)
* Build: check for `_build/html` directory and fail if exists Continuation of #10038 Closes #10036 * Update exception message Co-authored-by: Anthony <[email protected]> --------- Co-authored-by: Anthony <[email protected]>
1 parent 87b9959 commit dd07a3e

File tree

5 files changed

+37
-27
lines changed

5 files changed

+37
-27
lines changed

readthedocs/doc_builder/director.py

+24
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,30 @@ def run_build_job(self, job):
332332
for command in commands:
333333
environment.run(command, escape_command=False, cwd=cwd)
334334

335+
def check_old_output_directory(self):
336+
"""
337+
Check if there the directory '_build/html' exists and fail the build if so.
338+
339+
Read the Docs used to build artifacts into '_build/html' and there are
340+
some projects with this path hardcoded in their files. Those builds are
341+
having unexpected behavior since we are not using that path anymore.
342+
343+
In case we detect they are keep using that path, we fail the build
344+
explaining this.
345+
"""
346+
command = self.build_environment.run(
347+
"test",
348+
"-x",
349+
"_build/html",
350+
cwd=self.data.project.checkout_path(self.data.version.slug),
351+
record=False,
352+
)
353+
if command.exit_code == 0:
354+
log.warning(
355+
"Directory '_build/html' exists. This may lead to unexpected behavior."
356+
)
357+
raise BuildUserError(BuildUserError.BUILD_OUTPUT_OLD_DIRECTORY_USED)
358+
335359
def run_build_commands(self):
336360
reshim_commands = (
337361
{"pip", "install"},

readthedocs/doc_builder/exceptions.py

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class BuildUserError(BuildBaseException):
5252
"and it is not currently supported. "
5353
'Please, remove all the files but the "{artifact_type}" your want to upload.'
5454
)
55+
BUILD_OUTPUT_OLD_DIRECTORY_USED = gettext_noop(
56+
"Some files were detected in an unsupported output path, '_build/html'. "
57+
"Ensure your project is configured to use the output path "
58+
"'$READTHEDOCS_OUTPUT/html' instead."
59+
)
5560
PDF_COMMAND_FAILED = gettext_noop(
5661
"PDF generation failed. "
5762
"The build log below contains information on what errors caused the failure."

readthedocs/projects/tasks/builds.py

+1
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ def execute(self):
754754
self.update_build(state=BUILD_STATE_BUILDING)
755755
self.data.build_director.build()
756756
finally:
757+
self.data.build_director.check_old_output_directory()
757758
self.data.build_data = self.collect_build_data()
758759

759760
# At this point, the user's build already succeeded.

readthedocs/projects/tests/test_build_tasks.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,13 @@ def test_build_commands_executed(
782782
cwd=mock.ANY,
783783
record=False,
784784
),
785+
mock.call(
786+
"test",
787+
"-x",
788+
"_build/html",
789+
record=False,
790+
cwd=mock.ANY,
791+
),
785792
# FIXME: I think we are hitting this issue here:
786793
# https://github.com/pytest-dev/pytest-mock/issues/234
787794
mock.call("lsb_release", "--description", record=False, demux=True),
@@ -806,14 +813,6 @@ def test_build_commands_executed(
806813
record=False,
807814
demux=True,
808815
),
809-
mock.call(
810-
"test",
811-
"-x",
812-
"_build/html",
813-
record=False,
814-
demux=True,
815-
cwd=mock.ANY,
816-
),
817816
]
818817
)
819818

readthedocs/telemetry/collectors.py

-19
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,8 @@ def collect(self):
9393
}
9494
data["doctool"] = self._get_doctool()
9595

96-
# NOTE: Check if there are files at `_build/html` (the old output directory)
97-
# and log these projects so we can communicate with their maintainers
98-
#
99-
# This temporal and should be removed in the future once we have
100-
# decided what to do with this collected data.
101-
self._check_using_old_output_directory()
102-
10396
return data
10497

105-
def _check_using_old_output_directory(self):
106-
code, _, _ = self.run(
107-
"test",
108-
"-x",
109-
"_build/html",
110-
cwd=self.project.checkout_path(self.version.slug),
111-
)
112-
if code == 0:
113-
log.warning(
114-
"Directory '_build/html' exists. This may lead to unexpected behavior."
115-
)
116-
11798
def _get_doctool_name(self):
11899
if self.version.is_sphinx_type:
119100
return "sphinx"

0 commit comments

Comments
 (0)