From c5e1f1aa7c98631252327f8617fb91a61ad32617 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 1 Oct 2018 13:52:30 -0500 Subject: [PATCH 1/3] Test --- .../rtd_tests/tests/test_doc_builder.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index 5879be90b05..8d4231df8d3 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -38,6 +38,32 @@ 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_get_config_params(self, checkout_path, docs_dir): + """Test the extra data that is added to the conf.py file.""" + 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, + ) + base_sphinx.config_file = os.path.join( + tmp_dir, 'docs/conf.py' + ) + params = base_sphinx.get_config_params() + self.assertEqual( + params['conf_py_path'], + '/docs/' + ) + @patch( 'readthedocs.doc_builder.backends.sphinx.SPHINX_TEMPLATE_DIR', '/tmp/sphinx-template-dir', From b8a5a1397980efa7e29b0f8bb70d13fab9835d64 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 1 Oct 2018 14:10:21 -0500 Subject: [PATCH 2/3] Use relpath for sphinx --- readthedocs/doc_builder/backends/sphinx.py | 7 ++++++- 1 file changed, 6 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 From e89ae988208f386aa47b13b8d1f8241bdc57ad0d Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 1 Oct 2018 14:22:54 -0500 Subject: [PATCH 3/3] Better tests --- .../rtd_tests/tests/test_doc_builder.py | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py index 8d4231df8d3..4cf0b5dd8dc 100644 --- a/readthedocs/rtd_tests/tests/test_doc_builder.py +++ b/readthedocs/rtd_tests/tests/test_doc_builder.py @@ -41,8 +41,13 @@ def setUp(self): @patch('readthedocs.doc_builder.backends.sphinx.BaseSphinx.docs_dir') @patch('readthedocs.projects.models.Project.checkout_path') @override_settings(DONT_HIT_API=True) - def test_get_config_params(self, checkout_path, docs_dir): - """Test the extra data that is added to the conf.py file.""" + 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 @@ -55,14 +60,16 @@ def test_get_config_params(self, checkout_path, docs_dir): build_env=self.build_env, python_env=python_env, ) - base_sphinx.config_file = os.path.join( - tmp_dir, 'docs/conf.py' - ) - params = base_sphinx.get_config_params() - self.assertEqual( - params['conf_py_path'], - '/docs/' - ) + + 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',