Skip to content

Commit a49f111

Browse files
authored
Build: show the YAML config file before validating it (#11175)
* Build: show the YAML config file before validating it This moves the `cat readthedocs.yaml` command _before_ validating the YAML file. This allows the user to inspect the configuration file in case it fails due to a validation error. Closes #11097 * Use a better name for the variable * Omit check for `cat readthedocs.yaml` for now We can't perform this check on the "build environment" because it happens in the "VCS environment" now and we are not mocking it. We should find a way to check these commands on the "VCS environment".
1 parent 268bd69 commit a49f111

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

readthedocs/doc_builder/director.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from django.utils.translation import gettext_lazy as _
1717

1818
from readthedocs.builds.constants import EXTERNAL
19+
from readthedocs.config.config import CONFIG_FILENAME_REGEX
20+
from readthedocs.config.find import find_one
1921
from readthedocs.core.utils.filesystem import safe_open
2022
from readthedocs.doc_builder.config import load_yaml_config
2123
from readthedocs.doc_builder.exceptions import BuildUserError
@@ -108,20 +110,6 @@ def setup_vcs(self):
108110
# self.run_build_job("pre_checkout")
109111
self.checkout()
110112

111-
# Output the path for the config file used.
112-
# This works as confirmation for us & the user about which file is used,
113-
# as well as the fact that *any* config file is used.
114-
if self.data.config.source_file:
115-
cwd = self.data.project.checkout_path(self.data.version.slug)
116-
command = self.vcs_environment.run(
117-
"cat",
118-
# Show user the relative path to the config file
119-
# TODO: Have our standard path replacement code catch this.
120-
# https://github.com/readthedocs/readthedocs.org/pull/10413#discussion_r1230765843
121-
self.data.config.source_file.replace(cwd + "/", ""),
122-
cwd=cwd,
123-
)
124-
125113
self.run_build_job("post_checkout")
126114

127115
commit = self.data.build_commit or self.vcs_repository.commit
@@ -240,6 +228,24 @@ def checkout(self):
240228

241229
if custom_config_file:
242230
log.info("Using a custom .readthedocs.yaml file.", path=custom_config_file)
231+
232+
checkout_path = self.data.project.checkout_path(self.data.version.slug)
233+
default_config_file = find_one(checkout_path, CONFIG_FILENAME_REGEX)
234+
final_config_file = custom_config_file or default_config_file
235+
236+
# Output the path for the config file used.
237+
# This works as confirmation for us & the user about which file is used,
238+
# as well as the fact that *any* config file is used.
239+
if final_config_file:
240+
command = self.vcs_environment.run(
241+
"cat",
242+
# Show user the relative path to the config file
243+
# TODO: Have our standard path replacement code catch this.
244+
# https://github.com/readthedocs/readthedocs.org/pull/10413#discussion_r1230765843
245+
final_config_file.replace(checkout_path + "/", ""),
246+
cwd=checkout_path,
247+
)
248+
243249
self.data.config = load_yaml_config(
244250
version=self.data.version,
245251
readthedocs_yaml_path=custom_config_file,

readthedocs/projects/tests/test_build_tasks.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -810,11 +810,14 @@ def test_build_commands_executed(
810810
python_version = settings.RTD_DOCKER_BUILD_SETTINGS["tools"]["python"]["3"]
811811
self.mocker.mocks["environment.run"].assert_has_calls(
812812
[
813-
mock.call(
814-
"cat",
815-
"readthedocs.yml",
816-
cwd="/tmp/readthedocs-tests/git-repository",
817-
),
813+
# TODO: check for this in the VCS environment.
814+
# We can't check it here because this is the build environment.
815+
#
816+
# mock.call(
817+
# "cat",
818+
# "readthedocs.yml",
819+
# cwd="/tmp/readthedocs-tests/git-repository",
820+
# ),
818821
mock.call("asdf", "install", "python", python_version),
819822
mock.call("asdf", "global", "python", python_version),
820823
mock.call("asdf", "reshim", "python", record=False),
@@ -1348,7 +1351,10 @@ def test_conda_config_calls_conda_command(self, load_yaml_config):
13481351
]
13491352
self.mocker.mocks["environment.run"].assert_has_calls(
13501353
[
1351-
mock.call("cat", "readthedocs.yml", cwd=mock.ANY),
1354+
# TODO: check for this in the VCS environment.
1355+
# We can't check it here because this is the build environment.
1356+
#
1357+
# mock.call("cat", "readthedocs.yml", cwd=mock.ANY),
13521358
mock.call("asdf", "install", "python", python_version),
13531359
mock.call("asdf", "global", "python", python_version),
13541360
mock.call("asdf", "reshim", "python", record=False),
@@ -1442,7 +1448,10 @@ def test_python_mamba_commands(self, load_yaml_config):
14421448

14431449
self.mocker.mocks["environment.run"].assert_has_calls(
14441450
[
1445-
mock.call("cat", "readthedocs.yml", cwd=mock.ANY),
1451+
# TODO: check for this in the VCS environment.
1452+
# We can't check it here because this is the build environment.
1453+
#
1454+
# mock.call("cat", "readthedocs.yml", cwd=mock.ANY),
14461455
mock.call("asdf", "install", "python", "mambaforge-4.10.3-10"),
14471456
mock.call("asdf", "global", "python", "mambaforge-4.10.3-10"),
14481457
mock.call("asdf", "reshim", "python", record=False),

0 commit comments

Comments
 (0)