Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
10 changes: 9 additions & 1 deletion readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"""

import os

import structlog
import yaml
from django.conf import settings

from readthedocs.core.utils.filesystem import safe_open
from readthedocs.doc_builder.base import BaseBuilder
from readthedocs.doc_builder.exceptions import BuildUserError
from readthedocs.projects.constants import MKDOCS
from readthedocs.projects.constants import MKDOCS_HTML
from readthedocs.projects.exceptions import ProjectConfigurationError



log = structlog.get_logger(__name__)
Expand Down Expand Up @@ -45,6 +47,8 @@ def __init__(self, *args, **kwargs):

# This is the *MkDocs* yaml file
self.yaml_file = self.get_yaml_config()
if not os.path.exists(self.yaml_file):
raise ProjectConfigurationError(ProjectConfigurationError.MKDOCS_NOT_FOUND)
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this here.


def get_final_doctype(self):
"""
Expand Down Expand Up @@ -99,6 +103,10 @@ def build(self):
"--config-file",
os.path.relpath(self.yaml_file, self.project_path),
]

if not os.path.exists(self.yaml_file):
raise ProjectConfigurationError(ProjectConfigurationError.NOT_FOUND)

Copy link
Member

Choose a reason for hiding this comment

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

Please, move this code to show_config following the same pattern we are using for Sphinx. Take a look at its code at https://github.com/readthedocs/readthedocs.org/blob/main/readthedocs/doc_builder/backends/sphinx.py#L110-L124

if self.config.mkdocs.fail_on_warning:
build_command.append("--strict")
cmd_ret = self.run(
Expand Down
2 changes: 2 additions & 0 deletions readthedocs/projects/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ProjectConfigurationError(BuildUserError):

NOT_FOUND = "project:sphinx:conf-py-not-found"
MULTIPLE_CONF_FILES = "project:sphinx:multiple-conf-py-files-found"
MKDOCS_NOT_FOUND = "project:configuration:mkdocs-not-found"



class UserFileNotFound(BuildUserError):
Expand Down
14 changes: 14 additions & 0 deletions readthedocs/projects/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@
),
type=ERROR,
),
Message(
id=ProjectConfigurationError.MKDOCS_NOT_FOUND,
header=_("MkDocs configuration file is missing"),
body=_(
textwrap.dedent(
"""
A configuration file was not found.
Make sure you have a <code>mkdocs.yml</code> file in your repository.
"""
).strip(),
),
type=ERROR,
),

Message(
id=ProjectConfigurationError.MULTIPLE_CONF_FILES,
header=_("Multiple Sphinx configuration files found"),
Expand Down