Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 17 additions & 9 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,23 @@ jobs: # This workflow contains a single
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v7
- uses: actions/setup-python@v7

- name: Install uv
uses: astral-sh/setup-uv@v10.3.0
with:
python-version: '3.12'
cache: 'pip'
# Install
- name: Install dependencies
enable-cache: true
cache-dependency-glob: |
**/pyproject.toml
docs/requirements.txt

# a virtual environment, on the PATH of the later steps (no R: no page
# or lab runs it)
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y r-base libtirpc-dev
pip install -r docs/requirements.txt
pip install .
uv venv --python 3.12
echo "$PWD/.venv/bin" >> "$GITHUB_PATH"
uv pip install -r docs/requirements.txt
uv pip install .

# Checkout labs
- name: Checkout version of labs
Expand Down Expand Up @@ -60,6 +66,8 @@ jobs: # This workflow contains a single
deploy:
runs-on: ubuntu-latest
needs: build
# (a run on another branch only builds, to try it)
if: github.ref == 'refs/heads/main'

# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
[modelmatrix](https://github.com/intro-stat-learning/modelmatrix), which
ISLP now depends on (`modelmatrix>=0.3`).

### Documentation

- **The docs build with uv, without conda or R**: the docs workflow
installs with uv, and `docs/make_notebooks.py` runs a lab in a uv
virtual environment (Python 3.12 by default) instead of a conda
environment. R and `rpy2` are no longer installed: no page or lab runs R.
A run of the workflow on a branch other than main only builds.

### Breaking changes

- **`ModelSpec`'s `intercept` defaults to `False`**, as 0.6.0 announced. Pass
Expand Down
17 changes: 10 additions & 7 deletions docs/make_notebooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'''
Run notebooks in an isolated environment specified by a requirements.txt file
(a virtual environment made with uv, https://docs.astral.sh/uv/)
'''

from hashlib import md5
import tempfile
import os
import shutil
from argparse import ArgumentParser


Expand All @@ -16,7 +18,7 @@
type=str,
nargs='+')
parser.add_argument('--python',
default='3.10')
default='3.12')
parser.add_argument('--tarball',
default=None,
dest='tarball')
Expand All @@ -36,7 +38,7 @@ def make_notebooks(requirements='requirements.txt',
tarball='',
inplace=False,
tmpdir='',
python='3.10',
python='3.12',
timeout=5000, # should be enough for Ch10
env_tag='',
):
Expand All @@ -48,11 +50,12 @@ def make_notebooks(requirements='requirements.txt',
md5_.update(open(requirements, 'rb').read());
hash_ = md5_.hexdigest()[:8]

env_name = f'isolated_env_{hash_}' + env_tag
env_dir = os.path.join(tempfile.gettempdir(), f'isolated_env_{hash_}' + env_tag)
env_bin = os.path.join(env_dir, 'bin')

setup_cmd = f'''
conda create -n {env_name} python={python} -y;
conda run -n {env_name} pip install -r {requirements} jupyter jupytext;
uv venv --python {python} {env_dir};
uv pip install --python {env_bin}/python -r {requirements} jupyter jupytext;
'''

print(setup_cmd)
Expand All @@ -64,7 +67,7 @@ def make_notebooks(requirements='requirements.txt',
if src_ != dest_:
os.system(f'cp {src_} {dest_}')
name = os.path.split(dest_)[1]
build_cmd = f'''conda run -n {env_name} jupyter nbconvert --inplace --execute --ExecutePreprocessor.timeout={timeout} {dest_} '''
build_cmd = f'''{env_bin}/jupyter nbconvert --inplace --execute --ExecutePreprocessor.timeout={timeout} {dest_} '''
if '02' in name:
build_cmd += ' --allow-errors '

Expand All @@ -82,7 +85,7 @@ def make_notebooks(requirements='requirements.txt',
print(tarball_cmd)
os.system(tarball_cmd)

os.system(f'conda env remove -n {env_name}')
shutil.rmtree(env_dir, ignore_errors=True)

if __name__ == '__main__':

Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ texext
numpydoc
myst_nb
sphinx-book-theme
rpy2
sphinx_rtd_theme
jupytext
polars
Loading