Skip to content

Commit

Permalink
Merge pull request #543 from analogdevicesinc/tfcollins/doctools
Browse files Browse the repository at this point in the history
Tfcollins/doctools
  • Loading branch information
tfcollins authored Mar 27, 2024
2 parents 2900d32 + 6854c72 commit 4d30e01
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 183 deletions.
111 changes: 4 additions & 107 deletions doc/source/_static/css/style.css
Original file line number Diff line number Diff line change
@@ -1,110 +1,7 @@
:root {
/* Defaults */
--display-dark-stuff: none;
--display-light-stuff: block;
--sidebar-highligh-color-hover: black;
--sidebar-highligh-color: white;
--display-dark-stuff: none;
--display-light-stuff: block;
#indexlogo img, #badges img {
background: none;
}

@media (prefers-color-scheme: dark) {
:root {
/* Change to dark if user prefers dark */
--display-dark-stuff: block;
--display-light-stuff: none;
--sidebar-highligh-color-hover: white;
--sidebar-highligh-color: black;
--display-dark-stuff: block;
--display-light-stuff: none;
}
}


[data-theme=light] {
--sidebar-highligh-color-hover: black;
--sidebar-highligh-color: white;
--display-dark-stuff: none;
--display-light-stuff: block;
}

[data-theme=dark] {
--sidebar-highligh-color-hover: white;
--sidebar-highligh-color: black;
--display-dark-stuff: block;
--display-light-stuff: none;
}

/* Pad sidebar entries so radius does not touch content or browser*/
body>div>aside>div>div>div.sidebar-scroll>div>ul {
padding-right: 10px;
padding-left: 10px;
}

/* Disable sidebar title */
.sidebar-brand-text {
display: none;
}

/* Add better highlighting on selected sidebar entry */
.sidebar-tree .current>.reference {
border-radius: 25px;
color: var(--sidebar-highligh-color);
padding-bottom: 1px;
padding-top: 5px;
}

/* Add better highlighting on selected second level sidebar entry */
.toctree-l2 .current.reference.internal {
border-radius: 25px;
color: var(--sidebar-highligh-color);
padding-bottom: 1px;
padding-top: 1px;
margin: 2px;
}

/* Add better highlighting on selected hovered sidebar entry */
.sidebar-tree .current>.reference:hover {
color: var(--sidebar-highligh-color-hover);
border: 1px solid var(--sidebar-highligh-color-hover);
padding-bottom: 1px;
padding-top: 4px;
}

/* Add better highlighting on selected second level hovered sidebar entry */
.toctree-l2 .current.reference.internal:hover {
color: var(--sidebar-highligh-color-hover);
border: 1px solid var(--sidebar-highligh-color-hover);
padding-bottom: 1px;
padding-top: 1px;
margin: 2px;
}


/* Hide/display logo on index page based on theme */
#indexlogo_light {
display: var(--display-dark-stuff);
}

#indexlogo_dark {
display: var(--display-light-stuff);
}

element.style {
display: none;
}

/* Animate page entries */
.article-container > article:nth-child(3) {
animation-duration: 0.2s;
animation-delay: 0s;
animation-name: fadeInBottom;
}

@keyframes fadeInBottom {
from {
opacity: 0;
transform: translateY(1%);
}
to { opacity: 1 }
#badges img {
display: inline-block;
}
74 changes: 6 additions & 68 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,18 @@
import contextlib
import datetime
import os
import shutil
import sys
from typing import List

sys.path.insert(0, os.path.abspath("../.."))
sys.path.append(os.path.abspath("./ext"))
sys.setrecursionlimit(1500)

# Move logos over to doc directory
p = os.path.join("_static", "logos")
if not os.path.exists(p):
os.mkdir("_static/logos")

for filename in os.listdir(os.path.join("..", "..", "images")):
if filename.endswith(".png"):
shutil.copy(
os.path.join("..", "..", "images", filename),
os.path.join("_static", "logos", filename),
)
fn = os.path.join("_static", "logos", filename)
from PIL import Image

im = Image.open(fn)
# Remove left 30% of image
im = im.crop((int(im.size[0] * 0.45), 0, int(im.size[0] * 1), im.size[1]))
im.save(fn.replace(".png", "_cropped.png"))


import adi # isort:skip

# -- Project information -----------------------------------------------------

repository = "pyadi-iio"
project = "Analog Devices Hardware Python Interfaces"
year_now = datetime.datetime.now().year
copyright = f"2019-{year_now}, Analog Devices, Inc"
Expand All @@ -56,9 +37,6 @@

# -- General configuration ---------------------------------------------------

# The master toctree document.
master_doc = "index"

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Expand All @@ -67,8 +45,9 @@
"sphinx.ext.coverage",
"sphinx.ext.githubpages",
"myst_parser",
"sphinx_favicon",
"sphinxcontrib.mermaid",
"adi_doctools",
"ext_pyadi_iio",
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -92,13 +71,8 @@

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "furo"

html_title = f"{project} {release}"
favicons = ["favicon.png"]
html_theme = "cosmic"
html_favicon = os.path.join("_static", "favicon.png")

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand All @@ -112,40 +86,4 @@
html_theme_options = {
"light_logo": os.path.join("logos", "PyADI-IIO_Logo_300_cropped.png"),
"dark_logo": os.path.join("logos", "PyADI-IIO_Logo_w_300_cropped.png"),
"dark_css_variables": {
"color-sidebar-item-background--current": "white",
"color-sidebar-link-text": "white",
"color-sidebar-link-text--top-level": "white",
},
"light_css_variables": {
"color-sidebar-item-background--current": "black",
"color-sidebar-link-text": "black",
"color-sidebar-link-text--top-level": "black",
},
}

if os.getenv("DEV_BUILD"):
branch = os.getenv("GIT_BRANCH")
if branch is None:
with contextlib.suppress(Exception):
# Try to get branch from git
import subprocess

branch = (
subprocess.run(
args=["git", "rev-parse", "--abbrev-ref", "HEAD"],
capture_output=True,
)
.stdout.decode("utf-8")
.strip()
)
if branch is None:
branch = "_UNKNOWN_" # type: ignore
html_theme_options["announcement"] = (
"<em>WARNING: This is a development \
build of branch: <b>"
+ branch
+ "</b>. Please use the latest stable release.</em>"
)
html_theme_options["dark_css_variables"]["color-announcement-text"] = "red"
html_theme_options["light_css_variables"]["color-announcement-text"] = "red"
40 changes: 40 additions & 0 deletions doc/source/ext/ext_pyadi_iio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from os import chdir, listdir, mkdir, path

from PIL import Image
from sphinx.util.fileutil import copy_asset_file


def builder_inited(app):
chdir(app.builder.srcdir)

outdir = app.builder.outdir
for p in ["_static", "logos"]:
outdir = path.join(outdir, p)
if not path.exists(outdir):
mkdir(outdir)

def copy_asset(app, src, fname):
src_uri = path.abspath(path.join(src, fname))
build_uri = path.join(outdir, fname)
copy_asset_file(src_uri, build_uri)
return build_uri

# Move logos over to doc build directory
for filename in listdir(path.join("..", "..", "images")):
if filename.endswith(".png"):
fn = copy_asset(app, path.join("..", "..", "images"), filename)

im = Image.open(fn)
# Remove left 30% of image
im = im.crop((int(im.size[0] * 0.45), 0, int(im.size[0] * 1), im.size[1]))
im.save(fn.replace(".png", "_cropped.png"))


def setup(app):
app.connect("builder-inited", builder_inited)

return {
"parallel_read_safe": True,
"parallel_write_safe": True,
"version": "0.1",
}
12 changes: 6 additions & 6 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ Analog Devices Hardware Python Interfaces

<center>
<div style="width:70%;">
<div id="indexlogo_dark">
<div id="indexlogo" class="only-light">
<img src="_static/logos/PyADI-IIO_Logo_600.png" alt="PyADI-IIO Logo" />
</div>
<div id="indexlogo_light">
<div id="indexlogo" class="only-dark">
<img src="_static/logos/PyADI-IIO_Logo_w_600.png" alt="PyADI-IIO Logo" />
</div>
</div>
</center>

.. raw:: html

<p align="center">
<div align="center" id="badges">
<a href="https://github.com/analogdevicesinc/pyadi-iio/actions">
<img src="https://github.com/analogdevicesinc/pyadi-iio/actions/workflows/test.yml/badge.svg" alt="Build Status">
</a>
Expand All @@ -48,9 +48,9 @@ Analog Devices Hardware Python Interfaces
<a href="https://www.python.org/download/releases/3.6.0/">
<img src="https://img.shields.io/badge/python-3.6+-blue.svg" alt="Python Version">
</a>
</p>
</div>

<p align="center">
<div align="center" id="badges">
<a href="http://analogdevicesinc.github.io/pyadi-iio/">
<img alt="GitHub Pages" src="https://img.shields.io/badge/docs-GitHub%20Pages-blue.svg">
</a>
Expand All @@ -62,7 +62,7 @@ Analog Devices Hardware Python Interfaces
<a href="https://wiki.analog.com/resources/tools-software/linux-software/pyadi-iio">
<img alt="Analog Wiki" src="https://img.shields.io/badge/Wiki-on%20wiki.analog.com-blue.svg">
</a>
</p>
</div>


Requirements
Expand Down
3 changes: 1 addition & 2 deletions requirements_doc.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
sphinx>=2.0
myst-parser
furo
sphinx-favicon
https://github.com/analogdevicesinc/doctools/releases/download/latest/adi-doctools.tar.gz
sphinxcontrib-mermaid
sphinx-simplepdf
pillow

0 comments on commit 4d30e01

Please sign in to comment.