Repository: readthedocs/readthedocs.org

Issue:
"Edit on GitHub" url broken for sphinx projects
## Details

* Read the Docs project URL: https://jsxc.readthedocs.io
* Build URL (if applicable): https://github.com/jsxc/documentation

## Expected Result
"Edit on GitHub", "View on GitHub" and so on should link to https://github.com/jsxc/documentation.

## Actual Result
Those links points to https://github.com/jsxc/documentation/blob/master/home/docs/checkouts/readthedocs.org/user_builds/jsxc/checkouts/latest/conf.py/index.rst

As you can see the string `/home/docs/checkouts/readthedocs.org/user_builds/jsxc/checkouts/latest/conf.py` is added to the url. The only thing that I can think of, is that I have currently no tags in my repo. Maybe this is the reason, I don't know.


Discussion:
Thanks for the report, this is a duplicate of #1917

I have a PR that fixes this in #3525
@stsewd I don't think this is a duplicate issue as this bug is appearing in sphinx based projects too.
In the #4482 the value for `conf_py_path` is changed from a relative to an absolute path. This is passed to the sphinx build context and then used in the readthedocs default theme to [generate the "Edit on [VCS]" link](https://github.com/rtfd/sphinx_rtd_theme/blob/310043695f75cac495f8bde089a301e53f46d6db/sphinx_rtd_theme/breadcrumbs.html#L45).
This is also documented in: https://docs.readthedocs.io/en/latest/vcs.html?highlight=conf_py_path
Maybe you need an absolute path here, but we also need to provide a relative path in the checkout to the docs root in order to generate a correct "Edit on [VCS]" link.
oops, didn't see that your project is sphinx type. Yeah, that's a bug
@stsewd that's not my project, I just noticed the same bug in a sphinx based project and commented this same issue instead of opening a new one.
Thanks for your commitment.

Resolving patch:
diff --git a/readthedocs/doc_builder/backends/sphinx.py b/readthedocs/doc_builder/backends/sphinx.py
--- 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


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_doc_builder.py b/readthedocs/rtd_tests/tests/test_doc_builder.py
--- 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',