diff --git a/readthedocs/doc_builder/backends/mkdocs.py b/readthedocs/doc_builder/backends/mkdocs.py index 36f2e1e5d6f..52bc208c2c5 100644 --- a/readthedocs/doc_builder/backends/mkdocs.py +++ b/readthedocs/doc_builder/backends/mkdocs.py @@ -10,10 +10,8 @@ import yaml from django.conf import settings -from readthedocs.core.utils.filesystem import safe_open from readthedocs.doc_builder.base import BaseBuilder -from readthedocs.projects.constants import MKDOCS -from readthedocs.projects.constants import MKDOCS_HTML +from readthedocs.projects.exceptions import UserFileNotFound log = structlog.get_logger(__name__) @@ -44,46 +42,25 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # This is the *MkDocs* yaml file - self.yaml_file = self.get_yaml_config() - - def get_final_doctype(self): - """ - Select a doctype based on the ``use_directory_urls`` setting. - - https://www.mkdocs.org/user-guide/configuration/#use_directory_urls - """ - - # TODO: we should eventually remove this method completely and stop - # relying on "loading the `mkdocs.yml` file in a safe way just to know - # if it's a MKDOCS or MKDOCS_HTML documentation type". - - # Allow symlinks, but only the ones that resolve inside the base directory. - with safe_open( - self.yaml_file, - "r", - allow_symlinks=True, - base_path=self.project_path, - ) as fh: - config = yaml_load_safely(fh) - use_directory_urls = config.get("use_directory_urls", True) - return MKDOCS if use_directory_urls else MKDOCS_HTML - - def get_yaml_config(self): - """Find the ``mkdocs.yml`` file in the project root.""" - mkdocs_path = self.config.mkdocs.configuration - if not mkdocs_path: - mkdocs_path = "mkdocs.yml" - return os.path.join( + self.config_file = os.path.join( self.project_path, - mkdocs_path, + self.config.mkdocs.configuration, ) def show_conf(self): """Show the current ``mkdocs.yaml`` being used.""" + if not os.path.exists(self.config_file): + raise UserFileNotFound( + message_id=UserFileNotFound.FILE_NOT_FOUND, + format_values={ + "filename": os.path.relpath(self.config_file, self.project_path), + }, + ) + # Write the mkdocs.yml to the build logs self.run( "cat", - os.path.relpath(self.yaml_file, self.project_path), + os.path.relpath(self.config_file, self.project_path), cwd=self.project_path, ) @@ -97,8 +74,9 @@ def build(self): "--site-dir", os.path.join("$READTHEDOCS_OUTPUT", "html"), "--config-file", - os.path.relpath(self.yaml_file, self.project_path), + os.path.relpath(self.config_file, self.project_path), ] + if self.config.mkdocs.fail_on_warning: build_command.append("--strict") cmd_ret = self.run( diff --git a/readthedocs/projects/notifications.py b/readthedocs/projects/notifications.py index 9b9e5d43e7a..2e4fc616ac8 100644 --- a/readthedocs/projects/notifications.py +++ b/readthedocs/projects/notifications.py @@ -101,7 +101,7 @@ ), Message( id=RepositoryError.UNSUPPORTED_VCS, - header=_("Repository type not suported"), + header=_("Repository type not supported"), body=_( textwrap.dedent( """ diff --git a/readthedocs/projects/tests/test_build_tasks.py b/readthedocs/projects/tests/test_build_tasks.py index 51177f88868..89bab7cf4df 100644 --- a/readthedocs/projects/tests/test_build_tasks.py +++ b/readthedocs/projects/tests/test_build_tasks.py @@ -302,6 +302,14 @@ def test_build_updates_documentation_type(self, load_yaml_config): ) ).touch() + # Create "mkdocs.yml" for the "cat" command to find it + pathlib.Path( + os.path.join( + self.project.checkout_path(self.version.slug), + "mkdocs.yml", + ) + ).touch() + self._trigger_update_docs_task() # Update version state @@ -1413,7 +1421,7 @@ def test_build_commands_executed_with_clone_token( os.makedirs(self.project.artifact_path(version=self.version.slug, type_="epub")) os.makedirs(self.project.artifact_path(version=self.version.slug, type_="pdf")) - get_clone_token.return_value = "toke:1234" + get_clone_token.return_value = "token:1234" github_app_installation = get( GitHubAppInstallation, installation_id=1234, @@ -2626,6 +2634,16 @@ def test_mkdocs_fail_on_warning(self, load_yaml_config): validate=True, ) + # Create "mkdocs.yaml" for the "cat" command to find it + os.makedirs(os.path.join(self.project.checkout_path(version=self.version.slug), "docs")) + pathlib.Path( + os.path.join( + self.project.checkout_path(self.version.slug), + "docs", + "mkdocs.yaml", + ) + ).touch() + self._trigger_update_docs_task() self.mocker.mocks["environment.run"].assert_has_calls(