Skip to content

Commit 33a628b

Browse files
Merge pull request #340 from UBC-DSCI/main
1st edition production
2 parents 0402682 + ae56d01 commit 33a628b

File tree

166 files changed

+73268
-3398
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+73268
-3398
lines changed

.github/workflows/build_book.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ on:
44
branches:
55
- production
66
paths:
7-
- source/**
7+
- 'source/**'
8+
- 'build_html.sh'
89

910
jobs:
1011
deploy-book:
@@ -29,7 +30,7 @@ jobs:
2930
with:
3031
github_token: ${{ secrets.GITHUB_TOKEN }}
3132
publish_dir: source/_build/html
32-
force_orphan: true
3333
cname: python.datasciencebook.ca
34+
force_orphan: true # this will clean up all previous PR previews / main branch preview
3435

3536

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Rebuild and deploy dev version of book to gh-pages branch in dev/ folder
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'source/**'
8+
- 'build_html.sh'
9+
10+
jobs:
11+
deploy-main-preview:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
packages: write
16+
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v2
20+
with:
21+
ref: 'main'
22+
23+
- name: Build the book
24+
run: |
25+
./build_html.sh
26+
27+
# Push the book's HTML to github-pages
28+
- name: GitHub Pages action
29+
uses: peaceiris/[email protected]
30+
with:
31+
github_token: ${{ secrets.GITHUB_TOKEN }}
32+
publish_dir: source/_build/html
33+
keep_files: true
34+
destination_dir: dev
35+
# force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews
36+
37+
38+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "Rebuild and deploy PR version of book to gh-pages branch in pull###/ folder"
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
paths:
6+
- 'source/**'
7+
- 'Dockerfile'
8+
branches:
9+
- 'main'
10+
jobs:
11+
deploy-pr-preview:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
packages: write
16+
pull-requests: write
17+
18+
steps:
19+
- name: Wait for potential build environment update
20+
uses: fountainhead/[email protected]
21+
with:
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
checkName: "Rebuild docker image"
24+
ref: ${{ github.event.pull_request.head.sha }}
25+
timeoutSeconds: 60000
26+
27+
- name: Checkout the repo
28+
uses: actions/checkout@v2
29+
with:
30+
fetch-depth: '0'
31+
ref: ${{ github.head_ref }}
32+
33+
- name: Build the book
34+
run: |
35+
./build_html.sh
36+
37+
# Push the book's HTML to github-pages
38+
- name: GitHub Pages action
39+
uses: peaceiris/[email protected]
40+
with:
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
publish_dir: source/_build/html
43+
keep_files: true
44+
destination_dir: pull${{ github.event.number }}
45+
# force_orphan: true # once peaceiris updates to v4, change this to true and keep_files: true for the PR / main branch deploy previews
46+
47+
- name: Post URLS to PR thread
48+
uses: mshick/[email protected]
49+
with:
50+
message: |
51+
Hello! I've built a preview of your PR so that you can compare it to the current `main` branch.
52+
* PR deploy preview available [here](https://python.datasciencebook.ca/pull${{ github.event.number }}/index.html)
53+
* Current `main` deploy preview available [here](https://python.datasciencebook.ca/dev/index.html)
54+
* Public production build available [here](https://python.datasciencebook.ca)
Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
name: Rebuild and publish new ubcdsci/py-intro-to-ds image on DockerHub
22
on:
3-
push:
4-
branches:
5-
- main
6-
paths:
7-
- Dockerfile
3+
pull_request:
4+
types: [opened, synchronize]
5+
86
jobs:
97
rebuild-docker:
8+
name: Rebuild docker image
109
runs-on: ubuntu-latest
1110
permissions:
1211
contents: write
1312
steps:
14-
- name: Checkout main
13+
- name: Checkout PR branch
1514
uses: actions/checkout@v3
1615
with:
1716
fetch-depth: '0'
18-
ref: 'main'
17+
ref: ${{ github.head_ref }}
18+
- name: Check if Dockerfile needs to be rebuilt
19+
id: check-stale
20+
run: |
21+
echo "Checking if Dockerfile was modified since last commit on this PR"
22+
echo "GitHub PR action type: ${{ github.event.action }}"
23+
if [ "${{ github.event.action }}" == "opened" ]; then
24+
echo "GitHub base ref: ${{ github.event.pull_request.base.sha }}"
25+
echo "GitHub head ref: ${{ github.event.pull_request.head.sha }}"
26+
BEFORE=${{ github.event.pull_request.base.sha }}
27+
AFTER=${{ github.event.pull_request.head.sha }}
28+
else
29+
echo "GitHub event before: ${{ github.event.before }}"
30+
echo "GitHub event after: ${{ github.event.after }}"
31+
BEFORE=${{ github.event.before }}
32+
AFTER=${{ github.event.after }}
33+
fi
34+
if git diff --quiet $BEFORE $AFTER Dockerfile; then
35+
echo "PR synchronized, but Dockerfile was not edited. Not rebuilding the image."
36+
echo "stale_dockerfile=false" >> "$GITHUB_OUTPUT"
37+
else
38+
echo "PR synchronized, and Dockerfile was edited, so rebuilding the image."
39+
echo "stale_dockerfile=true" >> "$GITHUB_OUTPUT"
40+
fi
1941
- name: Rebuild and publish image
42+
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
2043
id: rebuild
2144
uses: elgohr/Publish-Docker-Github-Action@v5
2245
with:
@@ -26,25 +49,28 @@ jobs:
2649
dockerfile: Dockerfile
2750
snapshot: true
2851
- name: Update build_html.sh script
52+
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
2953
run: |
3054
git config --local user.email "[email protected]"
3155
git config --local user.name "GitHub Action"
32-
git pull origin main
56+
git pull origin ${{ github.head_ref }}
3357
sed 's/ubcdsci\/py-intro-to-ds:[[:alnum:]]\+/ubcdsci\/py-intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' build_html.sh > build_html.tmp && mv build_html.tmp build_html.sh
3458
chmod u+x build_html.sh
3559
git add build_html.sh
3660
git commit -m "update build_html.sh script with new docker image"
3761
- name: Update build_pdf.sh script
62+
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
3863
run: |
3964
git config --local user.email "[email protected]"
4065
git config --local user.name "GitHub Action"
41-
git pull origin main
66+
git pull origin ${{ github.head_ref }}
4267
sed 's/ubcdsci\/py-intro-to-ds:[[:alnum:]]\+/ubcdsci\/py-intro-to-ds:${{ steps.rebuild.outputs.snapshot-tag }}/g' build_pdf.sh > build_pdf.tmp && mv build_pdf.tmp build_pdf.sh
4368
chmod u+x build_pdf.sh
4469
git add build_pdf.sh
4570
git commit -m "update build_pdf.sh script with new docker image"
4671
- name: Push changes to build scripts
72+
if: ${{ steps.check-stale.outputs.stale_dockerfile == 'true' }}
4773
uses: ad-m/github-push-action@master
4874
with:
4975
github_token: ${{ secrets.GITHUB_TOKEN }}
50-
branch: 'main'
76+
branch: ${{ github.head_ref }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ source/*.py
99
*.swp
1010
*.swo
1111
source/__pycache__
12+
.local/
13+
.viminfo

Dockerfile

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,29 @@ WORKDIR "${HOME}"
1313
# remove the "work/" directory added in an earlier layer...
1414
RUN rm -rf work
1515

16-
17-
RUN pip install docutils==0.17.1 # Need to pin docutils to an old version for now, due to https://github.com/executablebooks/jupyter-book/issues/2022
18-
RUN pip install referencing
19-
RUN pip install jupyter-book
20-
# Pinning pandas until altair 5.1.2 to avoid future warning https://github.com/altair-viz/altair/issues/3181
21-
RUN pip install numpy jinja2 pandas"<2.1" altair">=5.1.1" "vegafusion[embed]" vl-convert-python">=0.13" click ibis-framework ghp-import jupytext nodejs
22-
23-
# forces scikit-learn to grab latest to avoid bug in 1.3.0 related to checking for c-contiguity breaking figures in classification 2. See https://github.com/scikit-learn/scikit-learn/pull/26772
24-
# TODO: remove this once scikit-learn 1.4.x or beyond releases and is incorporated into jupyter/scipy-notebook
25-
RUN pip install -U git+https://github.com/scikit-learn/scikit-learn.git@main
26-
2716
# disable warnings that pollute build logs; seems to be related to the update to python 3.11
2817
# https://discourse.jupyter.org/t/debugger-warning-it-seems-that-frozen-modules-are-being-used-python-3-11-0/16544/12
2918
ENV PYDEVD_DISABLE_FILE_VALIDATION=1
3019

3120
## Install various python packages
32-
# commented out for now due to various package version conflicts
33-
# installing via pip instead above
34-
#RUN mamba install --quiet --yes \
35-
# 'numpy' \
36-
# 'jinja2' \
37-
# 'altair_data_server' \
38-
# 'altair_saver' \
39-
# 'click' \
40-
# 'ibis-framework' \
41-
# 'ghp-import' \
42-
# 'jupytext' \
43-
# 'jupyter-book' \
44-
# 'nodejs' \
45-
# && mamba clean --all -f -y \
46-
# && fix-permissions "${CONDA_DIR}" \
47-
# && fix-permissions "/home/${NB_USER}"
48-
21+
RUN mamba install --quiet --yes \
22+
'numpy' \
23+
'pandas>=2.1.3' \
24+
'jinja2' \
25+
'altair>=5.1.2' \
26+
'vl-convert-python>=0.14' \
27+
'vegafusion[embed]' \
28+
'click' \
29+
'ibis-framework' \
30+
'ghp-import' \
31+
'jupytext' \
32+
'jupyter-book' \
33+
'scikit-learn>=1.3.2' \
34+
'nodejs' \
35+
'plotly' \
36+
'lxml' \
37+
'referencing' \
38+
'docutils==0.17.1' \
39+
&& mamba clean --all -f -y \
40+
&& fix-permissions "${CONDA_DIR}" \
41+
&& fix-permissions "/home/${NB_USER}"

README.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ See [the license file](LICENSE.md) for more information.
1818

1919
Building the book requires Docker (instructions here: [https://docs.docker.com/get-docker/](https://docs.docker.com/get-docker/)).
2020

21-
### Contributing
22-
Primary development in this repository happens on the `main` branch. If you want to contribute to the book,
23-
please branch off of `main` and make a pull request into `main`.
24-
25-
The `production` branch contains the source material for the live, publicly viewable HTML book.
26-
2721
### Build locally
2822

2923
You can build the HTML version of the book on your own machine by running
@@ -38,15 +32,34 @@ You can build the PDF version of the book on your own machine by running
3832
```
3933
in the root directory of this repository. The book can be viewed in a PDF reader by opening `source/_build/latex/python.pdf`.
4034

41-
### Update build environment
35+
### Contributing
36+
Primary development in this repository happens on the `main` branch. If you want to contribute to the book,
37+
please branch off of `main` and make a pull request into `main`. You cannot commit directly to `main`.
38+
39+
The `production` branch contains the source material corresponding to the current publicly-viewable version of the book website.
40+
41+
The `gh-pages` branch serves the current book website at https://python.datasciencebook.ca.
42+
43+
### Workflows
44+
45+
#### Book deployment
46+
47+
You can update the live, publicly viewable HTML book by making changes to the `source/` folder in the `production` branch (e.g. by merging `main` into `production`).
48+
GitHub will trigger a rebuild of the public HTML site, and store the built book in the root folder of the `gh-pages` branch.
49+
50+
#### `main` deploy previews
51+
52+
Any commit to `source/**` on the `main` branch (from a merged PR) will trigger a rebuild of the development preview site served at `https://python.datasciencebook.ca/dev`.
53+
The built preview book will be stored in the `dev/` folder on the `gh-pages` branch.
54+
55+
#### PR deploy previews
4256

43-
You can update the build environment for the book by making changes to `Dockerfile` in the root of the repository in the `main` branch.
44-
If you push any changes to the `Dockerfile` on the `main` branch, GitHub will trigger a rebuild of the docker image,
45-
push it to DockerHub, and update the `build_html.sh` script and book deploy GitHub action with the new image tag.
57+
Any PR to `source/` will trigger a build of a PR preview site at `https://python.datasciencebook.ca/pull###`, where `###` is the number of the pull request.
58+
The built preview book will be stored in the `pull###/` folder on the `gh-pages` branch.
4659

47-
### Update public html
60+
#### Build environment updates
4861

49-
You can update the live, publicly viewable HTML book by making changes to the `source/` folder in the `production` branch.
50-
If you push any changes to the `source/` folder on the `production` branch, GitHub will trigger a rebuild of the public HTML site.
62+
Any PR to `Dockerfile` will trigger a rebuild of the docker image, push it to DockerHub, and update the image tags in the `build_html.sh` and `build_pdf.sh` scripts on the PR automatically.
63+
This new build environment will be used for the PR deploy preview mentioned above.
5164

5265

build_html.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
chmod -R o+w source/
2-
docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20230831171718ddf538 /bin/bash -c "jupyter-book build source"
2+
docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20231112004031dd2207 /bin/bash -c "jupyter-book build source"

build_pdf.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1+
# Script to generate PDF book
2+
3+
# backup original index.Rmd
4+
cp source/index.md index_backup.md
5+
6+
# PDF book doesn't need the welcome page. I couldn't find a way to stop jupyterbook from including it.
7+
# so this script manually removes the welcome page before building the PDF. This is a bit painful, but it works...
8+
sed -n -i "/graphic/q;p" source/index.md
9+
echo "# Data Science: A First Introduction" >> source/index.md
10+
111
chmod -R o+w source/
2-
docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20230831171718ddf538 /bin/bash -c "export BOOK_BUILD_TYPE='PDF'; jupyter-book build source --builder pdflatex"
12+
docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20231112004031dd2207 /bin/bash -c "export BOOK_BUILD_TYPE='PDF'; jupyter-book build source --builder pdflatex"
13+
14+
# restore the backed up full index.Rmd
15+
mv index_backup.md source/index.md

source/_config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Book settings
22
title: "Data Science: A First Introduction (Python Edition)"
3-
author: "The DSCI100 Development Team"
3+
author: "Tiffany Timbers, Trevor Campbell, Melissa Lee, Joel Ostblom, and Lindsey Heagy"
44
copyright: "2022" # Copyright year to be placed in the footer
55
logo: "" # A path to the book logo
66
# Patterns to skip when building the book. Can be glob-style (e.g. "*skip.ipynb")
@@ -48,8 +48,8 @@ html:
4848
use_multitoc_numbering: true # Continuous numbering across parts/chapters
4949
extra_navbar: Powered by <a href="https://jupyterbook.org">Jupyter Book</a> # Will be displayed underneath the left navbar.
5050
extra_footer: "" # Will be displayed underneath the footer.
51-
google_analytics_id: "" # A GA id that can be used to track book views.
52-
home_page_in_navbar: true # Whether to include your home page in the left Navigation Bar
51+
google_analytics_id: "G-7XBFF4RSN2" # A GA id that can be used to track book views.
52+
home_page_in_navbar: false # Whether to include your home page in the left Navigation Bar
5353
baseurl: "" # The base URL where your book will be hosted. Used for creating image previews and social links. e.g.: https://mypage.com/mybook/
5454
comments:
5555
hypothesis: false
@@ -78,6 +78,8 @@ sphinx:
7878
local_extensions: # A list of local extensions to load by sphinx specified by "name: path" items
7979
config: # key-value pairs to directly over-ride the Sphinx configuration
8080
bibtex_reference_style: author_year
81+
html_js_files:
82+
- https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
8183
html_context:
8284
default_mode: light
8385

source/_static/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ img {
2525
margin-left: auto;
2626
margin-right: auto;
2727
}
28+
29+
span.pasted-text {
30+
font-weight: normal;
31+
}

source/_toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ parts:
44
- caption: Front Matter
55
chapters:
66
- file: preface-text.md
7-
#- file: foreword.md
7+
- file: foreword-text.md
88
- file: acknowledgements.md
99
- file: authors.md
1010
- caption: Chapters

0 commit comments

Comments
 (0)