-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Can we turn Elegant Scipy into a Jupyter-book? | ||
|
||
## Create an environment with latest Jupyter Book and Jupytext | ||
|
||
```bash | ||
conda create -n jupytextbook | ||
conda activate jupytextbook | ||
conda install jupyter numpy matplotlib tqdm pytest -y | ||
|
||
git clone https://github.com/jupyter/jupyter-book.git | ||
pip install jupyter-book | ||
git clone https://github.com/mwouts/jupytext.git | ||
pip install jupytext | ||
``` | ||
|
||
## Download Elegant-Scipy | ||
|
||
```bash | ||
git clone https://github.com/elegant-scipy/elegant-scipy.git | ||
``` | ||
|
||
# Install the book requirements | ||
|
||
We could create a separate env for that, but for simplicity we use the same environment as above | ||
|
||
```bash | ||
pip install -r elegant-scipy/requirements.txt | ||
python -m ipykernel install --name elegant-scipy-kernel --user | ||
``` | ||
|
||
We also inject the current kernel into the Markdown file (later on, if possible, I'd prefer to pass the desired kernel as an option to Jupyter book) | ||
|
||
```bash | ||
# Not working https://github.com/mwouts/jupytext/issues/325 | ||
# jupytext --set-kernel elegant-scipy-kernel elegant-scipy/markdown/* | ||
``` | ||
|
||
Anyway the above does not work yet, so I'll do it manually: | ||
|
||
```bash | ||
for MDFILE in elegant-scipy/markdown/*.markdown; do | ||
echo '--- | ||
jupyter: | ||
jupytext: | ||
text_representation: | ||
extension: .markdown | ||
format_name: markdown | ||
format_version: '1.1' | ||
jupytext_version: 1.2.3 | ||
kernelspec: | ||
display_name: elegant-scipy-kernel | ||
language: python | ||
name: elegant-scipy-kernel | ||
--- | ||
' | cat - $MDFILE > /tmp/concat | ||
mv /tmp/concat $MDFILE | ||
# rename .markdown to .md extension? | ||
# mv /tmp/concat "${MDFILE%.markdown}.md" | ||
done | ||
``` | ||
|
||
## Create our Jupyter Book | ||
|
||
We first create then book | ||
|
||
```bash | ||
jupyter-book create elegant-scipy-book --content-folder elegant-scipy/markdown --license elegant-scipy/LICENSE.md | ||
``` | ||
|
||
Then we update the table of contents (with only two chapters for now) | ||
|
||
```bash | ||
echo '- title: Elegant Scipy | ||
url: /elegant-scipy/acknowledgements | ||
not_numbered: true | ||
expand_sections: true | ||
sections: | ||
- title: Preface | ||
url: /elegant-scipy/preface | ||
not_numbered: true | ||
- title: "Elegant NumPy: The Foundation of Scientific Python" | ||
url: /elegant-scipy/ch1 | ||
- title: Quantile Normalization with NumPy and SciPy | ||
url: /elegant-scipy/ch2 | ||
- title: Epilogue | ||
url: /elegant-scipy/epilogue | ||
not_numbered: true | ||
' > ./elegant-scipy-book/_data/toc.yml | ||
``` | ||
|
||
and finally, we build the book | ||
|
||
```bash | ||
jupyter-book build elegant-scipy-book | ||
``` |