diff --git a/.github/workflows/build_docs.yml b/.github/workflows/build_docs.yml index 7328c69..1802a4a 100644 --- a/.github/workflows/build_docs.yml +++ b/.github/workflows/build_docs.yml @@ -5,12 +5,6 @@ name: Build docs # Controls when the workflow will run on: workflow_dispatch: - inputs: - LABS: - description: 'Labs version' - required: true - default: 'v2' - type: string # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -39,12 +33,10 @@ jobs: # Checkout labs - name: Checkout version of labs - env: - LABS: ${{ inputs.LABS }} run: | git submodule update --init --force docs/ISLP_labs cd docs - python fix_and_clear_notebooks.py --version $LABS + python source/fix_and_clear_notebooks.py --noclear rm source/labs/Ch*md - name: Make docs diff --git a/ISLP/__init__.py b/ISLP/__init__.py index 0cd8d3e..4e7e3f4 100644 --- a/ISLP/__init__.py +++ b/ISLP/__init__.py @@ -119,3 +119,4 @@ def confusion_table(predicted_labels, from . import _version __version__ = _version.get_versions()['version'] + diff --git a/docs/source/conf.py b/docs/source/conf.py index dac1a2d..c1e337c 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -2,12 +2,31 @@ # -- Project information +import json +import os + project = 'ISLP' copyright = '2023, ISLP authors' author = 'Jonathan Taylor' -release = '0.1' -version = '0.1.0' +import ISLP +version = ISLP.__version__ + + +# this should agree with +docs_version = {"labs": "v2.2", + "library": "v0.4"} + +lab_version = docs_version['labs'] + +myst_enable_extensions = ['substitution'] + +myst_substitutions = { + "ISLP_lab_link": f"[ISLP_labs/{lab_version}](https://github.com/intro-stat-learning/ISLP_labs/tree/{lab_version})", + "ISLP_binder_code": f"[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/intro-stat-learning/ISLP_labs/{lab_version})", + "ISLP_lab_version": "[ISLP/{0}](https://github.com/intro-stat-learning/ISLP/tree/{0})".format(docs_version['library']) + } +myst_number_code_blocks = ['python', 'ipython3'] # -- General configuration diff --git a/docs/source/docs_version.json b/docs/source/docs_version.json new file mode 100644 index 0000000..d5c8575 --- /dev/null +++ b/docs/source/docs_version.json @@ -0,0 +1,4 @@ +{"labs": "v2.2", + "library": "v0.4", + "comment":"library should be version of ISLP pointed to in ISLP/labs" +} diff --git a/docs/fix_and_clear_notebooks.py b/docs/source/fix_and_clear_notebooks.py similarity index 80% rename from docs/fix_and_clear_notebooks.py rename to docs/source/fix_and_clear_notebooks.py index aac28ee..87e1254 100644 --- a/docs/fix_and_clear_notebooks.py +++ b/docs/source/fix_and_clear_notebooks.py @@ -1,17 +1,21 @@ import os +import sys +import json import nbformat from argparse import ArgumentParser from glob import glob +import __main__ +dirname = os.path.abspath(os.path.join(os.path.split(__main__.__file__)[0], '..')) +from conf import docs_version + parser = ArgumentParser() -parser.add_argument('--version', default='v2') +parser.add_argument('--version', default=docs_version['labs']) +parser.add_argument('--clear', dest='clear', action='store_true', default=False) +parser.add_argument('--noclear', dest='clear', action='store_false') args = parser.parse_args() version = args.version -import __main__ -dirname = os.path.split(__main__.__file__)[0] -print(dirname) - for f in glob(os.path.join(dirname, 'source', 'labs', 'Ch14*')): os.remove(f) print(f) @@ -63,9 +67,10 @@ if labname[:4] not in ['Ch10', 'Ch13']: # clear outputs for all but Ch10,Ch13 - cmd = f'jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace {nbfile}' - print(f'Running: {cmd}') - os.system(cmd) + if args.clear: + cmd = f'jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace {nbfile}' + print(f'Running the clearing command: {cmd}') + os.system(cmd) cmd = f'jupytext --set-formats ipynb,md:myst {nbfile}; jupytext --sync {nbfile}' print(f'Running: {cmd}') @@ -84,7 +89,6 @@ open(f'{base}.md', 'w').write(myst) -# cmd = f'jupytext --sync {base}.ipynb; rm {base}.md' cmd = f'jupytext --sync {base}.ipynb; ' print(f'Running: {cmd}') os.system(cmd) diff --git a/docs/source/installation.myst b/docs/source/installation.myst index 542644e..cb42d7f 100644 --- a/docs/source/installation.myst +++ b/docs/source/installation.myst @@ -52,20 +52,10 @@ pip install ISLP ```{attention} Python packages change frequently. The labs here are built -with specific versions of the various packages. +with {{ ISLP_lab_link }}. Visit the lab git repo for specific instructions +to install the frozen environment. ``` -To ensure you have the same package versions as those built here, run: - -```{code-cell} ipython3 ---- -tags: [skip-execution] ---- -pip install -r https://raw.githubusercontent.com/intro-stat-learning/ISLP_labs/v2/requirements.txt -``` - -For more specific install instructions go to [ISLP_labs](https://github.com/intro-stat-learning/ISLP_labs/tree/v2). - ## Torch requirements The `ISLP` labs use `torch` and various related packages for the lab diff --git a/docs/source/labs.myst b/docs/source/labs.myst new file mode 100644 index 0000000..373c500 --- /dev/null +++ b/docs/source/labs.myst @@ -0,0 +1,54 @@ +--- +file_format: mystnb +kernelspec: + name: python3 + display_name: python3 +myst_number_code_blocks: python +--- + +# Labs + +{{ ISLP_binder_code }} + +The current version of the labs for `ISLP` are included here. + +## Package versions + + +```{attention} + +Python packages change frequently. The labs here are built +with {{ ISLP_lab_link }}. Visit the lab git repo for specific instructions +to install the frozen environment. + + +``` + +```{warning} +The version of the `ISLP` library used to build these labs +may differ slightly from the one documented here. +The labs are built with {{ ISLP_lab_version }}. + +The [Binder](http://mybinder.org) link above will run {{ ISLP_lab_link }} with +library version {{ ISLP_lab_version }}. + +``` + + +```{toctree} +maxdepth: 1 + +labs/Ch02-statlearn-lab +labs/Ch03-linreg-lab +labs/Ch04-classification-lab +labs/Ch05-resample-lab +labs/Ch06-varselect-lab +labs/Ch07-nonlin-lab +labs/Ch08-baggboost-lab +labs/Ch09-svm-lab +labs/Ch10-deeplearning-lab +labs/Ch11-surv-lab +labs/Ch12-unsup-lab +labs/Ch13-multiple-lab +``` + diff --git a/docs/source/labs.rst b/docs/source/labs.rst deleted file mode 100644 index 653020d..0000000 --- a/docs/source/labs.rst +++ /dev/null @@ -1,36 +0,0 @@ -Labs -==== - -The current version of the labs for `ISLP` are included here. - - -Package versions ----------------- - -.. attention:: - - Python packages change frequently. The labs here are built - with specific versions of the various packages. - - -To ensure you have the same package versions as those built here, run: - - pip install -r https://raw.githubusercontent.com/intro-stat-learning/ISLP_labs/v2/requirements.txt; - -.. toctree:: - :maxdepth: 1 - - labs/Ch02-statlearn-lab - labs/Ch03-linreg-lab - labs/Ch04-classification-lab - labs/Ch05-resample-lab - labs/Ch06-varselect-lab - labs/Ch07-nonlin-lab - labs/Ch08-baggboost-lab - labs/Ch09-svm-lab - labs/Ch10-deeplearning-lab - labs/Ch11-surv-lab - labs/Ch12-unsup-lab - labs/Ch13-multiple-lab - -