Skip to content

Commit bf8c4da

Browse files
authored
Merge pull request #46 from aeturrell/uv
Switching to uv to build the book, and as the recommended Python distribution. Also, automating build and publish via actions with uv.
2 parents d62473c + 7884566 commit bf8c4da

34 files changed

+4291
-434
lines changed

.github/labels.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
# Labels names are important as they are used by Release Drafter to decide
3+
# regarding where to record them in changelog or if to skip them.
4+
#
5+
# The repository labels will be automatically configured using this file and
6+
# the GitHub Action https://github.com/marketplace/actions/github-labeler.
7+
- name: breaking
8+
description: Breaking Changes
9+
color: bfd4f2
10+
- name: bug
11+
description: Something isn't working
12+
color: d73a4a
13+
- name: build
14+
description: Build System and Dependencies
15+
color: bfdadc
16+
- name: ci
17+
description: Continuous Integration
18+
color: 4a97d6
19+
- name: dependencies
20+
description: Pull requests that update a dependency file
21+
color: 0366d6
22+
- name: documentation
23+
description: Improvements or additions to documentation
24+
color: 0075ca
25+
- name: duplicate
26+
description: This issue or pull request already exists
27+
color: cfd3d7
28+
- name: enhancement
29+
description: New feature or request
30+
color: a2eeef
31+
- name: github_actions
32+
description: Pull requests that update Github_actions code
33+
color: "000000"
34+
- name: good first issue
35+
description: Good for newcomers
36+
color: 7057ff
37+
- name: help wanted
38+
description: Extra attention is needed
39+
color: 008672
40+
- name: invalid
41+
description: This doesn't seem right
42+
color: e4e669
43+
- name: performance
44+
description: Performance
45+
color: "016175"
46+
- name: python
47+
description: Pull requests that update Python code
48+
color: 2b67c6
49+
- name: question
50+
description: Further information is requested
51+
color: d876e3
52+
- name: refactoring
53+
description: Refactoring
54+
color: ef67c4
55+
- name: removal
56+
description: Removals and Deprecations
57+
color: 9ae7ea
58+
- name: style
59+
description: Style
60+
color: c120e5
61+
- name: testing
62+
description: Testing
63+
color: b1fc6f
64+
- name: wontfix
65+
description: This will not be worked on
66+
color: ffffff

.github/release-drafter.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
categories:
2+
- title: ":boom: Breaking Changes"
3+
label: "breaking"
4+
- title: ":rocket: Features"
5+
label: "enhancement"
6+
- title: ":fire: Removals and Deprecations"
7+
label: "removal"
8+
- title: ":beetle: Fixes"
9+
label: "bug"
10+
- title: ":racehorse: Performance"
11+
label: "performance"
12+
- title: ":rotating_light: Testing"
13+
label: "testing"
14+
- title: ":construction_worker: Continuous Integration"
15+
label: "ci"
16+
- title: ":books: Documentation"
17+
label: "documentation"
18+
- title: ":hammer: Refactoring"
19+
label: "refactoring"
20+
- title: ":lipstick: Style"
21+
label: "style"
22+
- title: ":package: Dependencies"
23+
labels:
24+
- "dependencies"
25+
- "build"
26+
template: |
27+
## Changes
28+
29+
$CHANGES

.github/workflows/labeler.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: labeler
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
paths:
8+
- '.github/labels.yml'
9+
- '.github/workflows/labels.yml'
10+
pull_request:
11+
paths:
12+
- '.github/labels.yml'
13+
- '.github/workflows/labels.yml'
14+
15+
jobs:
16+
labeler:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: read
20+
issues: write
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- name: Run Labeler
25+
uses: crazy-max/ghaction-github-labeler@v5
26+
with:
27+
skip-delete: true
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
yaml-file: .github/labels.yml
30+
dry-run: ${{ github.event_name == 'pull_request' }}
31+
exclude: |
32+
help*
33+
*issue

.github/workflows/release.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
pages: write
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
release:
14+
name: Release
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out the repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 2
21+
22+
- name: Set up Python
23+
uses: actions/[email protected]
24+
with:
25+
python-version: "3.10"
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v5
29+
with:
30+
# Install a specific version of uv.
31+
version: "0.5.2"
32+
33+
- name: Check if there is a parent commit
34+
id: check-parent-commit
35+
run: |
36+
echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)"
37+
38+
- name: Detect and tag new version
39+
id: check-version
40+
if: steps.check-parent-commit.outputs.sha
41+
uses: salsify/[email protected]
42+
with:
43+
version-command: |
44+
uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version
45+
46+
- name: Bump version for developmental release
47+
if: "! steps.check-version.outputs.tag"
48+
run: |
49+
uv run version_bumper.py &&
50+
version=$(uvx --from=toml-cli toml get --toml-path=pyproject.toml project.version) &&
51+
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $version.dev.$(date +%s)
52+
53+
- name: Install dependencies
54+
run: |
55+
uv sync
56+
57+
- name: Build book
58+
run: uv run jupyter-book build . --verbose
59+
60+
- name: Publish
61+
if: steps.check-version.outputs.tag
62+
run: uv run ghp-import -n -p -f _build/html
63+
64+
- name: Publish the release notes
65+
uses: release-drafter/[email protected]
66+
with:
67+
publish: ${{ steps.check-version.outputs.tag != '' }}
68+
tag: ${{ steps.check-version.outputs.tag }}
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/tests.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: tests
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.10'
15+
- uses: pre-commit/[email protected]
16+
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out the repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 2
24+
25+
- name: Set up Python
26+
uses: actions/[email protected]
27+
with:
28+
python-version: "3.10"
29+
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v5
32+
with:
33+
# Install a specific version of uv.
34+
version: "0.5.2"
35+
36+
- name: set timezone
37+
run: |
38+
TZ="Europe/London" &&
39+
sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
40+
41+
- name: install linux deps
42+
run: |
43+
sudo apt-get -y install openssl graphviz nano texlive graphviz-dev unzip build-essential
44+
45+
- name: Install dependencies
46+
run: |
47+
uv sync
48+
49+
- name: build the book
50+
run: |
51+
uv run jupyter-book build . --verbose
52+
53+
- name: success
54+
run: |
55+
echo "Success in building book without errors!"

.pre-commit-config.yaml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,18 @@ repos:
1313
entry: nbstripout
1414
language: python
1515
types: [jupyter]
16-
- repo: https://github.com/psf/black
17-
rev: 22.3.0
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
# Ruff version.
18+
rev: v0.4.1
1819
hooks:
19-
- id: black
20-
name: black
21-
description: 'applies black formatter to .py files'
22-
entry: black
23-
language: python
24-
types: [python]
25-
- id: black-jupyter
26-
name: black-jupyter
27-
description:
28-
"Black: The uncompromising Python code formatter (with Jupyter Notebook support)"
29-
entry: black
30-
language: python
31-
minimum_pre_commit_version: 2.9.2
32-
require_serial: true
20+
# Run the linter.
21+
- id: ruff
22+
types_or: [python, pyi, jupyter]
23+
args: [ --fix ]
24+
- id: ruff
25+
types_or: [python, pyi, jupyter]
26+
name: sort imports with ruff
27+
args: [--select, I, --fix]
28+
# Run the formatter.
29+
- id: ruff-format
3330
types_or: [python, pyi, jupyter]
34-
additional_dependencies: [".[jupyter]"]
35-
- repo: https://github.com/pycqa/flake8
36-
rev: 3.9.2 # pick a git hash / tag to point to
37-
hooks:
38-
- id: flake8

Dockerfile

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
1-
# DOCKERFILE for Coding for Economists
2-
# Please note that you will need a lot of RAM dedicated to Docker to build this image (15Gb+, change this in your docker settings)
1+
# DOCKERFILE for Python for Data Science
32

4-
# Set base image (this also loads the Alpine Linux operating system)
5-
FROM continuumio/miniconda3:4.10.3-alpine
3+
# Set base image
4+
FROM python:3.10-slim-bookworm
65

76
WORKDIR /app
87

98
# Update Linux package list and install some key libraries, including latex
10-
RUN apk update && apk add openssl graphviz \
11-
nano texlive alpine-sdk build-base graphviz-dev \
12-
bash
9+
RUN apt-get -y update && apt-get install -y openssl graphviz \
10+
nano texlive graphviz-dev \
11+
bash build-essential git
1312

1413
# change default shell from ash to bash
1514
RUN sed -i -e "s/bin\/ash/bin\/bash/" /etc/passwd
1615

17-
# Install mamba
18-
RUN conda install mamba -n base -c conda-forge
16+
# Create the environment:
17+
COPY uv.lock .
18+
COPY pyproject.toml .
1919

20-
# Ensure pip's setuptools is latest
21-
RUN pip install --upgrade setuptools wheel
20+
# Install uv
21+
COPY --from=ghcr.io/astral-sh/uv:0.5.14 /uv /bin/uv
2222

23-
# Create the environment:
24-
COPY environment.yml .
2523
# Install everything at once:
26-
RUN mamba env create -f environment.yml
27-
# Do a debug or incremental env install (builds quickly):
28-
# RUN mamba create -n python4DS -c conda-forge python=3.9 numpy pandas -y
29-
30-
# Make RUN commands use the new environment:
31-
SHELL ["conda", "run", "-n", "py4ds2e", "/bin/bash", "-c"]
24+
RUN uv sync --frozen
3225

33-
RUN mamba list
26+
RUN uv pip list
3427

3528
# Copy the current directory contents into the container at /app
3629
COPY . /app
3730

38-
RUN echo "Success building the python4DS container!"
31+
RUN echo "Success building the Python4DS container!"

_config.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
title: Python for Data Science
55
author: The Py4DS Community
66
logo: logo.png
7-
7+
exclude_patterns: [_build, Thumbs.db, .DS_Store, "**.ipynb_checkpoints", ".venv"]
88
# Force re-execution of notebooks on each build.
99
# See https://jupyterbook.org/content/execute.html
1010
execute:
1111
execute_notebooks: force
1212
timeout: 120
13-
exclude_patterns: [README.md]
13+
exclude_patterns: ["README.md"]
14+
allow_errors: false
15+
nb_output_stderr: show
16+
1417

1518
# Define the name of the latex output file for PDF builds
1619
latex:
@@ -32,9 +35,19 @@ html:
3235
use_issues_button: true
3336
use_repository_button: true
3437
favicon: "favicon.ico" # A path to a favicon image
35-
google_analytics_id: "G-LXJC37BJVX" # A GA id that can be used to track book views.
38+
analytics:
39+
google_analytics_id: "G-LXJC37BJVX" # A GA id that can be used to track book views.
3640

3741
launch_buttons:
3842
colab_url: "https://colab.research.google.com"
3943
notebook_interface: "jupyterlab" # or "classic"
40-
binderhub_url: "https://mybinder.org"
44+
binderhub_url: "https://mybinder.org"
45+
46+
sphinx:
47+
config:
48+
html_js_files:
49+
- https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
50+
bibtex_reference_style: author_year
51+
suppress_warnings: ["mystnb.unknown_mime_type"]
52+
nb_execution_show_tb: true
53+
nb_execution_raise_on_error: true # Make build fail any content errors (don't want to publish if errors)

0 commit comments

Comments
 (0)