From 8bcad531fe58af57b0560787c5566415a20a776a Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Thu, 19 Nov 2026 10:24:05 +1100 Subject: [PATCH 1/2] Build matplotlib's font cache before the build On a freshly launched runner the first matplotlib import scans the system fonts from a cold disk, which took 10 to 13 s in an instrumented pair of builds on this machine image (1.9 s warm). Past 5 s matplotlib prints "Matplotlib is building the font cache; this may take a moment." into the output of the first notebook that imports it, so whether that line reaches a page depends on the instance. One step after the environment is complete, in cache.yml, ci.yml and publish.yml, builds the cache first. The same change as QuantEcon/lecture-python-programming#664. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL --- .github/workflows/cache.yml | 9 +++++++++ .github/workflows/ci.yml | 9 +++++++++ .github/workflows/publish.yml | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml index ecf5b666a..6a8871e41 100644 --- a/.github/workflows/cache.yml +++ b/.github/workflows/cache.yml @@ -26,6 +26,15 @@ jobs: pip install -U "jax[cuda13]" pip install numpyro python scripts/test-jax-install.py + - name: Build matplotlib's font cache + shell: bash -l {0} + run: | + # On a freshly launched runner the first matplotlib import scans the + # system fonts from a cold disk, which can take over 5 s, and + # matplotlib then prints "Matplotlib is building the font cache; this + # may take a moment." into the output of the first notebook that + # imports it. Build the cache here, so no page depends on that timing. + python -c "import matplotlib.pyplot" - name: Check nvidia drivers shell: bash -l {0} run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d3e5abb8..07a448de0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,15 @@ jobs: pip install -U "jax[cuda13]" pip install numpyro python scripts/test-jax-install.py + - name: Build matplotlib's font cache + shell: bash -l {0} + run: | + # On a freshly launched runner the first matplotlib import scans the + # system fonts from a cold disk, which can take over 5 s, and + # matplotlib then prints "Matplotlib is building the font cache; this + # may take a moment." into the output of the first notebook that + # imports it. Build the cache here, so no page depends on that timing. + python -c "import matplotlib.pyplot" - name: Display Conda Environment Versions shell: bash -l {0} run: conda list diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 236c4b532..9e94b7e93 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,6 +43,15 @@ jobs: pip install -U "jax[cuda13]" pip install numpyro python scripts/test-jax-install.py + - name: Build matplotlib's font cache + shell: bash -l {0} + run: | + # On a freshly launched runner the first matplotlib import scans the + # system fonts from a cold disk, which can take over 5 s, and + # matplotlib then prints "Matplotlib is building the font cache; this + # may take a moment." into the output of the first notebook that + # imports it. Build the cache here, so no page depends on that timing. + python -c "import matplotlib.pyplot" - name: Check nvidia drivers shell: bash -l {0} run: | From a1b09de1af6f8ecba9ccf51749123a0334c65c28 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Thu, 19 Nov 2026 10:46:04 +1100 Subject: [PATCH 2/2] Build the font cache by importing the font manager alone matplotlib.font_manager builds the cache on import with no backend involved, so the step cannot depend on which backend the runner would choose (Copilot's review on QuantEcon/lecture-python.myst#1134). pyplot would not have failed there: on a Linux runner without a display matplotlib's automatic choice is Agg. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WT8bMacV9Lmy1VLUc6XJoL --- .github/workflows/cache.yml | 5 +++-- .github/workflows/ci.yml | 5 +++-- .github/workflows/publish.yml | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cache.yml b/.github/workflows/cache.yml index 6a8871e41..8eb18905b 100644 --- a/.github/workflows/cache.yml +++ b/.github/workflows/cache.yml @@ -33,8 +33,9 @@ jobs: # system fonts from a cold disk, which can take over 5 s, and # matplotlib then prints "Matplotlib is building the font cache; this # may take a moment." into the output of the first notebook that - # imports it. Build the cache here, so no page depends on that timing. - python -c "import matplotlib.pyplot" + # imports it. Build the cache here, so no page depends on that timing: + # the font manager builds it on import, with no backend involved. + python -c "import matplotlib.font_manager" - name: Check nvidia drivers shell: bash -l {0} run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07a448de0..88f64be48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,8 +44,9 @@ jobs: # system fonts from a cold disk, which can take over 5 s, and # matplotlib then prints "Matplotlib is building the font cache; this # may take a moment." into the output of the first notebook that - # imports it. Build the cache here, so no page depends on that timing. - python -c "import matplotlib.pyplot" + # imports it. Build the cache here, so no page depends on that timing: + # the font manager builds it on import, with no backend involved. + python -c "import matplotlib.font_manager" - name: Display Conda Environment Versions shell: bash -l {0} run: conda list diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9e94b7e93..5efe21030 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -50,8 +50,9 @@ jobs: # system fonts from a cold disk, which can take over 5 s, and # matplotlib then prints "Matplotlib is building the font cache; this # may take a moment." into the output of the first notebook that - # imports it. Build the cache here, so no page depends on that timing. - python -c "import matplotlib.pyplot" + # imports it. Build the cache here, so no page depends on that timing: + # the font manager builds it on import, with no backend involved. + python -c "import matplotlib.font_manager" - name: Check nvidia drivers shell: bash -l {0} run: |