From 383201850fd77ab1726f40c7f7797e0d4ccdc466 Mon Sep 17 00:00:00 2001 From: Gabriel Matos Date: Fri, 10 Nov 2023 14:04:10 +0000 Subject: [PATCH] Make logo adapt to dark mode; add source code links to documentation (#113) * Automatic logo adaptation to GitHub dark mode * Add source code links to documentation * Adjust page width CSS --- README.md | 7 ++++- docs/_static/css/custom.css | 10 +++++-- docs/conf.py | 36 ++++++++++++++++++++++++ docs/logo_dark_mode.svg | 55 +++++++++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 docs/logo_dark_mode.svg diff --git a/README.md b/README.md index 799dcf3..78665e6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ # qujax
-logo + + + + + +
[![PyPI - Version](https://img.shields.io/pypi/v/qujax)](https://pypi.org/project/qujax/) diff --git a/docs/_static/css/custom.css b/docs/_static/css/custom.css index 77681d9..25d71d8 100644 --- a/docs/_static/css/custom.css +++ b/docs/_static/css/custom.css @@ -27,8 +27,10 @@ background: #85cfcb; } -.wy-nav-content { - max-width: 1000px; +@media screen and (min-width: 1000px) { + .wy-nav-content { + max-width: 1000px; + } } html.writer-html4 .rst-content dl:not(.docutils) > dt, html.writer-html5 .rst-content dl[class]:not(.option-list):not(.field-list):not(.footnote):not(.citation):not(.glossary):not(.simple) > dt { @@ -50,4 +52,8 @@ h1, h2, h3, h4, h5, h6 { div.toctree-wrapper .caption-text{ color: #203847; +} + +.rst-content .viewcode-back, .rst-content .viewcode-link { + padding-left: 6px; } \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 0efc68d..9dd0111 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,8 @@ import os import sys +import importlib +import inspect +import pathlib sys.path.insert(0, os.path.abspath("..")) # pylint: disable=wrong-import-position @@ -22,6 +25,7 @@ "sphinx_rtd_theme", "sphinx.ext.napoleon", "sphinx.ext.mathjax", + "sphinx.ext.linkcode", "myst_parser", ] @@ -62,3 +66,35 @@ "collapse_navigation": False, "prev_next_buttons_location": "None", } + + +def linkcode_resolve(domain, info): + """ + Called by sphinx's linkcode extension, which adds links directing the user to the + source code of the API objects being documented. The `domain` argument specifies which + programming language the object belongs to. The `info` argument is a dictionary with + information specific to the programming language of the object. + + For Python objects, this dictionary contains a `module` key with the module the object is in + and a `fullname` key with the name of the object. This function uses this information to find + the source file and range of lines the object is defined in and to generate a link pointing to + those lines on GitHub. + """ + github_url = f"https://github.com/CQCL/qujax/tree/develop/qujax" + + if domain != "py": + return + + module = importlib.import_module(info["module"]) + obj = getattr(module, info["fullname"]) + + try: + path = pathlib.Path(inspect.getsourcefile(obj)) + file_name = path.name + lines = inspect.getsourcelines(obj) + except TypeError: + return + + start_line, end_line = lines[1], lines[1] + len(lines[0]) - 1 + + return f"{github_url}/{file_name}#L{start_line}-L{end_line}" diff --git a/docs/logo_dark_mode.svg b/docs/logo_dark_mode.svg new file mode 100644 index 0000000..751c538 --- /dev/null +++ b/docs/logo_dark_mode.svg @@ -0,0 +1,55 @@ + + + +