From 4c2fe1ed771a8ed428234760496fd720d31caa0e Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 2 Oct 2018 11:12:50 -0500 Subject: [PATCH] Fix broken url on sphinx projects (#4696) * Test * Use relpath for sphinx * Better tests --- readthedocs/doc_builder/backends/sphinx.py | 7 +++- .../rtd_tests/tests/test_doc_builder.py | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py index 58c36db2d00..4dc29714218 100644 --- a/readthedocs/doc_builder/backends/sphinx.py +++ b/readthedocs/doc_builder/backends/sphinx.py @@ -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 diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index 160726fde40..6a453c4837e 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -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',