Skip to content

Commit 5ffb6bc

Browse files
authored
Merge pull request #3525 from stsewd/fix-docroot-path-mkdocks
Use relative path for docroot on mkdocs
2 parents 5030ec4 + 78093a0 commit 5ffb6bc

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

readthedocs/doc_builder/backends/mkdocs.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,16 @@ def append_conf(self, **__):
111111
'%scss/readthedocs-doc-embed.css' % static_url,
112112
])
113113

114-
docs_path = os.path.join(self.root_path, docs_dir)
114+
# The docs path is relative to the location
115+
# of the mkdocs configuration file.
116+
docs_path = os.path.join(
117+
os.path.dirname(self.yaml_file),
118+
docs_dir
119+
)
115120

116121
# RTD javascript writing
117122
rtd_data = self.generate_rtd_data(
118-
docs_dir=docs_dir,
123+
docs_dir=os.path.relpath(docs_path, self.root_path),
119124
mkdocs_config=user_config
120125
)
121126
with open(os.path.join(docs_path, 'readthedocs-data.js'), 'w') as f:

readthedocs/rtd_tests/tests/test_doc_builder.py

+33
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,36 @@ def test_dont_override_theme(self, checkout_path, run):
335335
config['theme_dir'],
336336
'not-readthedocs'
337337
)
338+
339+
@patch('readthedocs.doc_builder.backends.mkdocs.BaseMkdocs.generate_rtd_data')
340+
@patch('readthedocs.doc_builder.base.BaseBuilder.run')
341+
@patch('readthedocs.projects.models.Project.checkout_path')
342+
def test_write_js_data_docs_dir(self, checkout_path, run, generate_rtd_data):
343+
tmpdir = tempfile.mkdtemp()
344+
os.mkdir(os.path.join(tmpdir, 'docs'))
345+
yaml_file = os.path.join(tmpdir, 'mkdocs.yml')
346+
yaml.safe_dump(
347+
{
348+
'site_name': 'mkdocs',
349+
'docs_dir': 'docs',
350+
},
351+
open(yaml_file, 'w')
352+
)
353+
checkout_path.return_value = tmpdir
354+
generate_rtd_data.return_value = ''
355+
356+
python_env = Virtualenv(
357+
version=self.version,
358+
build_env=self.build_env,
359+
config=None,
360+
)
361+
self.searchbuilder = MkdocsHTML(
362+
build_env=self.build_env,
363+
python_env=python_env,
364+
)
365+
self.searchbuilder.append_conf()
366+
367+
generate_rtd_data.assert_called_with(
368+
docs_dir='docs',
369+
mkdocs_config=mock.ANY
370+
)

0 commit comments

Comments
 (0)