Skip to content

Commit

Permalink
Fix broken url on sphinx projects (#4696)
Browse files Browse the repository at this point in the history
* Test

* Use relpath for sphinx

* Better tests
  • Loading branch information
stsewd authored and agjohnson committed Oct 2, 2018
1 parent bfa6bdb commit 4c2fe1e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion readthedocs/doc_builder/backends/sphinx.py
Expand Up @@ -74,7 +74,12 @@ def get_config_params(self):
# TODO this should be handled better in the theme
conf_py_path = os.path.join(
os.path.sep,
self.config_file,
os.path.dirname(
os.path.relpath(
self.config_file,
self.project.checkout_path(self.version.slug)
)
),
'',
)
remote_version = self.version.commit_name
Expand Down
33 changes: 33 additions & 0 deletions readthedocs/rtd_tests/tests/test_doc_builder.py
Expand Up @@ -38,6 +38,39 @@ def setUp(self):
BaseSphinx.type = 'base'
BaseSphinx.sphinx_build_dir = tempfile.mkdtemp()

@patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir')
@patch('readthedocs.projects.models.Project.checkout_path')
@override_settings(DONT_HIT_API=True)
def test_conf_py_path(self, checkout_path, docs_dir):
"""
Test the conf_py_path that is added to the conf.py file.
This value is used from the theme and footer
to build the ``View`` and ``Edit`` on link.
"""
tmp_dir = tempfile.mkdtemp()
checkout_path.return_value = tmp_dir
docs_dir.return_value = tmp_dir
python_env = Virtualenv(
version=self.version,
build_env=self.build_env,
config=None,
)
base_sphinx = BaseSphinx(
build_env=self.build_env,
python_env=python_env,
)

for value, expected in (('conf.py', '/'), ('docs/conf.py', '/docs/')):
base_sphinx.config_file = os.path.join(
tmp_dir, value
)
params = base_sphinx.get_config_params()
self.assertEqual(
params['conf_py_path'],
expected
)

@patch(
'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR',
'/tmp/sphinx-template-dir',
Expand Down

0 comments on commit 4c2fe1e

Please sign in to comment.