From 45e24deffea042b5db7ab84cd1eb63b3ed9bb9da Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 13 Aug 2022 09:24:02 -0700 Subject: [PATCH] Link API docs to GitHub source code, refs #464 --- docs/conf.py | 20 +++++++++++++++++++- setup.py | 8 +++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index d9ebc4b..1339477 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from subprocess import Popen, PIPE +from beanbag_docutils.sphinx.ext.github import github_linkcode_resolve # This file is execfile()d with the current directory set to its # containing dir. @@ -30,7 +31,12 @@ from subprocess import Popen, PIPE # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ["sphinx.ext.extlinks", "sphinx.ext.autodoc", "sphinx_copybutton"] +extensions = [ + "sphinx.ext.extlinks", + "sphinx.ext.autodoc", + "sphinx_copybutton", + "sphinx.ext.linkcode", +] autodoc_member_order = "bysource" autodoc_typehints = "description" @@ -38,6 +44,18 @@ extlinks = { "issue": ("https://github.com/simonw/sqlite-utils/issues/%s", "#"), } + +def linkcode_resolve(domain, info): + return github_linkcode_resolve( + domain=domain, + info=info, + allowed_module_names=["sqlite_utils"], + github_org_id="simonw", + github_repo_id="sqlite-utils", + branch="main", + ) + + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] diff --git a/setup.py b/setup.py index 019d44e..8b8434a 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,13 @@ setup( ], extras_require={ "test": ["pytest", "black", "hypothesis", "cogapp"], - "docs": ["furo", "sphinx-autobuild", "codespell", "sphinx-copybutton"], + "docs": [ + "furo", + "sphinx-autobuild", + "codespell", + "sphinx-copybutton", + "beanbag-docutils @ https://github.com/simonw/beanbag-docutils/archive/refs/heads/bytes-in-url.zip", + ], "mypy": [ "mypy", "types-click",