Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache avatars #12077

Merged
merged 9 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/_static/js/contrib-avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function putAvatarsInPage() {
}
// finish
outer.append(title, inner);
document.getElementById("institution-logos").after(outer);
document.body.append(outer);
}

putAvatarsInPage();
2 changes: 2 additions & 0 deletions doc/_templates/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@
</div>
{% endfor %}
</div>
<!-- contributors -->
{% include 'avatars.html' %}
</div>
3 changes: 0 additions & 3 deletions doc/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@
{%- block scripts_end %}
{{ super() }}
<script src="https://mne.tools/versionwarning.js"></script>
{% if pagename == 'index' %}
<script src="{{ pathto('_static/js/contrib-avatars.js', 1) }}"></script>
{% endif %}
{%- endblock %}
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"sphinxcontrib.bibtex",
"sphinxcontrib.youtube",
# homegrown
"contrib_avatars",
"gen_commands",
"gen_names",
"gh_substitutions",
Expand Down
7 changes: 7 additions & 0 deletions doc/sphinxext/_avatar_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
<script src="../_static/js/contrib-avatars.js"></script>
</head>
<body>
</body>
</html>
34 changes: 34 additions & 0 deletions doc/sphinxext/contrib_avatars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pathlib import Path

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException


def generate_contrib_avatars(app, config):
"""Render a template webpage with avatars generated by JS and a GitHub API call."""
root = Path(app.srcdir)
infile = root / "sphinxext" / "_avatar_template.html"
outfile = root / "_templates" / "avatars.html"
try:
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
except WebDriverException:
options = webdriver.FirefoxOptions()
options.add_argument("--headless")
drammock marked this conversation as resolved.
Show resolved Hide resolved
driver = webdriver.Firefox(options=options)
driver.get(f"file://{infile}")
wait = WebDriverWait(driver, 20)
wait.until(lambda d: d.find_element(by=By.ID, value="contributor-avatars"))
body = driver.find_element(by=By.TAG_NAME, value="body").get_attribute("innerHTML")
with open(outfile, "w") as fid:
fid.write(body)
driver.quit()


def setup(app):
"""Set up the Sphinx app."""
app.connect("config-inited", generate_contrib_avatars)
return
1 change: 1 addition & 0 deletions requirements_doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pytest
graphviz
pyzmq!=24.0.0
ipython!=8.7.0
selenium
2 changes: 2 additions & 0 deletions tools/circleci_bash_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -o pipefail

./tools/setup_xvfb.sh
sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
python3.10 -m venv ~/python_env
echo "set -e" >> $BASH_ENV
echo "set -o pipefail" >> $BASH_ENV
Expand Down
4 changes: 3 additions & 1 deletion tools/circleci_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -ef

python -m pip install --upgrade "pip!=20.3.0" setuptools wheel
python -m pip install --upgrade --progress-bar off --only-binary "numpy,scipy,matplotlib,pandas,statsmodels" -r requirements.txt -r requirements_testing.txt -r requirements_doc.txt PyQt6 git+https://github.com/mne-tools/mne-qt-browser -e .
python -m pip install --upgrade --progress-bar off --only-binary "numpy,scipy,matplotlib,pandas,statsmodels" -r requirements.txt -r requirements_testing.txt -r requirements_doc.txt webdrivermanager PyQt6 git+https://github.com/mne-tools/mne-qt-browser -e .

webdrivermanager firefox --linkpath AUTO
drammock marked this conversation as resolved.
Show resolved Hide resolved
Loading