From f00d052503d1de0bba6f5ffb859a022b672c8f71 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 5 Oct 2023 17:25:40 +0300 Subject: [PATCH 1/9] WIP --- doc/_static/js/contrib-avatars.js | 2 +- doc/_templates/homepage.html | 2 ++ doc/_templates/layout.html | 3 --- doc/conf.py | 1 + doc/sphinxext/contrib_avatars.py | 36 +++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 doc/sphinxext/contrib_avatars.py diff --git a/doc/_static/js/contrib-avatars.js b/doc/_static/js/contrib-avatars.js index bc8257530e3..dde2e8d29f7 100644 --- a/doc/_static/js/contrib-avatars.js +++ b/doc/_static/js/contrib-avatars.js @@ -47,7 +47,7 @@ async function putAvatarsInPage() { } // finish outer.append(title, inner); - document.getElementById("institution-logos").after(outer); + document.body.append(outer); } putAvatarsInPage(); diff --git a/doc/_templates/homepage.html b/doc/_templates/homepage.html index 3b65c11e59c..023e92e4dbc 100644 --- a/doc/_templates/homepage.html +++ b/doc/_templates/homepage.html @@ -41,4 +41,6 @@ {% endfor %} + +{% include 'avatars.html' %} diff --git a/doc/_templates/layout.html b/doc/_templates/layout.html index a016af6141f..6bb88d43ed1 100644 --- a/doc/_templates/layout.html +++ b/doc/_templates/layout.html @@ -17,7 +17,4 @@ {%- block scripts_end %} {{ super() }} - {% if pagename == 'index' %} - - {% endif %} {%- endblock %} diff --git a/doc/conf.py b/doc/conf.py index 02d61c1210b..3e905d6a955 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -103,6 +103,7 @@ "sphinxcontrib.bibtex", "sphinxcontrib.youtube", # homegrown + "contrib_avatars", "gen_commands", "gen_names", "gh_substitutions", diff --git a/doc/sphinxext/contrib_avatars.py b/doc/sphinxext/contrib_avatars.py new file mode 100644 index 00000000000..e3affa15634 --- /dev/null +++ b/doc/sphinxext/contrib_avatars.py @@ -0,0 +1,36 @@ +from io import StringIO + +from selenium import webdriver +from selenium.webdriver.common.by import By + +TEMPLATE = """ + + + + + + + +""" + + +def generate_contrib_avatars(app): + """Render a template webpage with avatars generated by JS and a GitHub API call.""" + options = webdriver.ChromeOptions() + options.add_argument("--headless=new") + driver = webdriver.Chrome(options=options) + with StringIO(TEMPLATE) as f: + driver.get(f) + driver.implicitly_wait(5) + body = driver.find_element(by=By.TAG_NAME, value="body").get_attribute( + "innerHTML" + ) + with open("../_templates/avatars.html", "w") as fid: + fid.write(body) + driver.quit() + + +def setup(app): + """Set up the Sphinx app.""" + app.connect("config-inited", generate_contrib_avatars) + return From 0e84cc5114e0405117d7ea389fbd4a5931dde043 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 5 Oct 2023 21:04:23 +0300 Subject: [PATCH 2/9] query GH API on build (not page load) --- doc/sphinxext/_avatar_template.html | 7 ++++++ doc/sphinxext/contrib_avatars.py | 34 +++++++++++------------------ 2 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 doc/sphinxext/_avatar_template.html diff --git a/doc/sphinxext/_avatar_template.html b/doc/sphinxext/_avatar_template.html new file mode 100644 index 00000000000..a0e086ee85e --- /dev/null +++ b/doc/sphinxext/_avatar_template.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/doc/sphinxext/contrib_avatars.py b/doc/sphinxext/contrib_avatars.py index e3affa15634..a2ed2770ad0 100644 --- a/doc/sphinxext/contrib_avatars.py +++ b/doc/sphinxext/contrib_avatars.py @@ -1,33 +1,25 @@ -from io import StringIO +from pathlib import Path from selenium import webdriver from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait -TEMPLATE = """ - - - - - - - -""" - -def generate_contrib_avatars(app): +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" options = webdriver.ChromeOptions() options.add_argument("--headless=new") driver = webdriver.Chrome(options=options) - with StringIO(TEMPLATE) as f: - driver.get(f) - driver.implicitly_wait(5) - body = driver.find_element(by=By.TAG_NAME, value="body").get_attribute( - "innerHTML" - ) - with open("../_templates/avatars.html", "w") as fid: - fid.write(body) - driver.quit() + 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): From 47b37bc13a5538c044758445c95c0a4d18fc6529 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 5 Oct 2023 21:24:06 +0300 Subject: [PATCH 3/9] install selenium in CircleCI --- requirements_doc.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements_doc.txt b/requirements_doc.txt index a3cc904f979..c0b2bdce0a6 100644 --- a/requirements_doc.txt +++ b/requirements_doc.txt @@ -19,3 +19,4 @@ pytest graphviz pyzmq!=24.0.0 ipython!=8.7.0 +selenium From 853a9f6149a22fad8a4732dec95f35dbfec6b249 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 5 Oct 2023 23:47:10 +0300 Subject: [PATCH 4/9] install browser into CI --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6f11c346045..552c04078da 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -159,6 +159,10 @@ jobs: echo "Source Sans Pro" curl https://codeload.github.com/adobe-fonts/source-sans/tar.gz/3.028R | tar xz -C $HOME/.fonts fc-cache -f + - run: + name: Install chromium for selenium + command: | + sudo apt install -y chromium-driver chromium # Load pip cache - restore_cache: From 321140ec0efeed4c6594b0d8414f317f835c8c28 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 5 Oct 2023 23:49:51 +0300 Subject: [PATCH 5/9] try another way --- .circleci/config.yml | 4 ---- tools/circleci_bash_env.sh | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 552c04078da..6f11c346045 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -159,10 +159,6 @@ jobs: echo "Source Sans Pro" curl https://codeload.github.com/adobe-fonts/source-sans/tar.gz/3.028R | tar xz -C $HOME/.fonts fc-cache -f - - run: - name: Install chromium for selenium - command: | - sudo apt install -y chromium-driver chromium # Load pip cache - restore_cache: diff --git a/tools/circleci_bash_env.sh b/tools/circleci_bash_env.sh index c63a6f0da1a..f8b70be587a 100755 --- a/tools/circleci_bash_env.sh +++ b/tools/circleci_bash_env.sh @@ -4,7 +4,7 @@ set -e set -o pipefail ./tools/setup_xvfb.sh -sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg +sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg chromium chromium-driver python3.10 -m venv ~/python_env echo "set -e" >> $BASH_ENV echo "set -o pipefail" >> $BASH_ENV From eea4b7a68256f491cc4e5bf61766294320b94b62 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 6 Oct 2023 09:36:45 +0300 Subject: [PATCH 6/9] try firefox --- doc/sphinxext/contrib_avatars.py | 12 +++++++++--- tools/circleci_bash_env.sh | 2 +- tools/circleci_dependencies.sh | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/sphinxext/contrib_avatars.py b/doc/sphinxext/contrib_avatars.py index a2ed2770ad0..f4e1b29faf3 100644 --- a/doc/sphinxext/contrib_avatars.py +++ b/doc/sphinxext/contrib_avatars.py @@ -3,6 +3,7 @@ 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): @@ -10,9 +11,14 @@ def generate_contrib_avatars(app, config): root = Path(app.srcdir) infile = root / "sphinxext" / "_avatar_template.html" outfile = root / "_templates" / "avatars.html" - options = webdriver.ChromeOptions() - options.add_argument("--headless=new") - driver = webdriver.Chrome(options=options) + try: + options = webdriver.FirefoxOptions() + options.add_argument("--headless") + driver = webdriver.Firefox(options=options) + except WebDriverException: + options = webdriver.ChromeOptions() + options.add_argument("--headless=new") + driver = webdriver.Chrome(options=options) driver.get(f"file://{infile}") wait = WebDriverWait(driver, 20) wait.until(lambda d: d.find_element(by=By.ID, value="contributor-avatars")) diff --git a/tools/circleci_bash_env.sh b/tools/circleci_bash_env.sh index f8b70be587a..b46aae619a6 100755 --- a/tools/circleci_bash_env.sh +++ b/tools/circleci_bash_env.sh @@ -4,7 +4,7 @@ set -e set -o pipefail ./tools/setup_xvfb.sh -sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg chromium chromium-driver +sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg snap firefox python3.10 -m venv ~/python_env echo "set -e" >> $BASH_ENV echo "set -o pipefail" >> $BASH_ENV diff --git a/tools/circleci_dependencies.sh b/tools/circleci_dependencies.sh index 677bd5ced22..cfaddd88c56 100755 --- a/tools/circleci_dependencies.sh +++ b/tools/circleci_dependencies.sh @@ -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 From 0af1623449192f4dc99eda84877730c17b2ed7ef Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 6 Oct 2023 11:00:03 +0300 Subject: [PATCH 7/9] switch back to chrome --- doc/sphinxext/contrib_avatars.py | 8 ++++---- tools/circleci_bash_env.sh | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/doc/sphinxext/contrib_avatars.py b/doc/sphinxext/contrib_avatars.py index f4e1b29faf3..332adc594fe 100644 --- a/doc/sphinxext/contrib_avatars.py +++ b/doc/sphinxext/contrib_avatars.py @@ -12,13 +12,13 @@ def generate_contrib_avatars(app, config): infile = root / "sphinxext" / "_avatar_template.html" outfile = root / "_templates" / "avatars.html" try: - options = webdriver.FirefoxOptions() - options.add_argument("--headless") - driver = webdriver.Firefox(options=options) - except WebDriverException: options = webdriver.ChromeOptions() options.add_argument("--headless=new") driver = webdriver.Chrome(options=options) + except WebDriverException: + options = webdriver.FirefoxOptions() + options.add_argument("--headless") + 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")) diff --git a/tools/circleci_bash_env.sh b/tools/circleci_bash_env.sh index b46aae619a6..fb5e471c9fd 100755 --- a/tools/circleci_bash_env.sh +++ b/tools/circleci_bash_env.sh @@ -4,7 +4,9 @@ set -e set -o pipefail ./tools/setup_xvfb.sh -sudo apt install -qq graphviz optipng python3.10-venv python3-venv libxft2 ffmpeg snap firefox +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 From 4e558195778278bdc53e06347b76f0b263e065a2 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 6 Oct 2023 03:26:13 -0500 Subject: [PATCH 8/9] Update tools/circleci_dependencies.sh --- tools/circleci_dependencies.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/circleci_dependencies.sh b/tools/circleci_dependencies.sh index cfaddd88c56..677bd5ced22 100755 --- a/tools/circleci_dependencies.sh +++ b/tools/circleci_dependencies.sh @@ -1,6 +1,4 @@ #!/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 webdrivermanager PyQt6 git+https://github.com/mne-tools/mne-qt-browser -e . - -webdrivermanager firefox --linkpath AUTO +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 . From 385dd9221ee7aedd97275d1e39a3e39caeb6b482 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Fri, 6 Oct 2023 03:26:42 -0500 Subject: [PATCH 9/9] Update doc/sphinxext/contrib_avatars.py --- doc/sphinxext/contrib_avatars.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sphinxext/contrib_avatars.py b/doc/sphinxext/contrib_avatars.py index 332adc594fe..e3bedc5e649 100644 --- a/doc/sphinxext/contrib_avatars.py +++ b/doc/sphinxext/contrib_avatars.py @@ -17,7 +17,7 @@ def generate_contrib_avatars(app, config): driver = webdriver.Chrome(options=options) except WebDriverException: options = webdriver.FirefoxOptions() - options.add_argument("--headless") + options.add_argument("--headless=new") driver = webdriver.Firefox(options=options) driver.get(f"file://{infile}") wait = WebDriverWait(driver, 20)