From 709545dbcd0085f306a7de8bec8f4004af6c2881 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 17 Dec 2020 18:25:46 -0500 Subject: [PATCH 1/2] Mkdocs: default to "docs" for docs_dir This value has been the default since the start of the project https://github.com/mkdocs/mkdocs/blob/0.13.0/mkdocs/config/defaults.py#L44 We should respect that default value, (we should actually don't edit it at all https://github.com/readthedocs/readthedocs.org/issues/2483). So, instead of trying to guess the docs dir always, only try to guess it if the user doesn't have mkdocs.yaml file. This should avoid any backwards compatibility and avoid weird bugs to new users. Closes https://github.com/readthedocs/readthedocs.org/issues/7539 --- readthedocs/doc_builder/backends/mkdocs.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/readthedocs/doc_builder/backends/mkdocs.py b/readthedocs/doc_builder/backends/mkdocs.py index 4c400c917ea..62c797ebd1c 100644 --- a/readthedocs/doc_builder/backends/mkdocs.py +++ b/readthedocs/doc_builder/backends/mkdocs.py @@ -115,6 +115,7 @@ def load_yaml_config(self): ) return { 'site_name': self.version.project.name, + 'docs_dir': self.docs_dir(), } except yaml.YAMLError as exc: note = '' @@ -139,14 +140,12 @@ def append_conf(self): user_config = self.load_yaml_config() # Handle custom docs dirs - user_docs_dir = user_config.get('docs_dir') - if not isinstance(user_docs_dir, (type(None), str)): + docs_dir = user_config.get('docs_dir', 'docs') + if not isinstance(docs_dir, (type(None), str)): raise MkDocsYAMLParseError( MkDocsYAMLParseError.INVALID_DOCS_DIR_CONFIG, ) - docs_dir = self.docs_dir(docs_dir=user_docs_dir) - self.create_index(extension='md') user_config['docs_dir'] = docs_dir From 4f0840487e8b0dea9ef8425c9db2f285767029ec Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 17 Dec 2020 19:00:58 -0500 Subject: [PATCH 2/2] Fix test --- readthedocs/rtd_tests/tests/test_doc_builder.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index 106a48fb037..95ffba72c0e 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -350,7 +350,10 @@ def test_get_theme_name_with_feature_flag(self, checkout_path, run): self.assertEqual(builder.get_theme_name({}), 'readthedocs') with patch('readthedocs.doc_builder.backends.mkdocs.yaml') as mock_yaml: with patch('readthedocs.doc_builder.backends.mkdocs.MkdocsHTML.load_yaml_config') as mock_load_yaml_config: - mock_load_yaml_config.return_value = {'site_name': self.project.name} + mock_load_yaml_config.return_value = { + 'site_name': self.project.name, + 'docs_dir': tmpdir, + } builder.append_conf() mock_yaml.safe_dump.assert_called_once_with( @@ -374,6 +377,7 @@ def test_get_theme_name_with_feature_flag(self, checkout_path, run): mock_load_yaml_config.return_value = { 'site_name': self.project.name, 'theme': 'customtheme', + 'docs_dir': tmpdir, } builder.append_conf()