From 9e5451796fadf66c5069a4676ea27677f290bcfa Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Thu, 10 Apr 2025 03:21:56 +0400 Subject: [PATCH] Dev container (#36) * Create .python-version * Create .gitignore * Create Makefile * remove Dockerfile * remove docker workflow * startup.sh * devcontainer * README with link * Update Makefile * obsolete python-version * Update README.md * Update README.md * Update README.md * Update devcontainer.json no browser option for devContainer * introducing a first test * introducing a first test * introducing a manual release job * introducing a manual release job * Update README.md --------- Co-authored-by: Jonathan Taylor --- .devcontainer/devcontainer.json | 22 ++++++++++++ .devcontainer/startup.sh | 5 +++ .docker/Dockerfile | 11 ------ .dockerignore | 5 --- .github/workflows/docker.yml | 42 ----------------------- .github/workflows/release.yml | 21 ++++++++++++ .github/workflows/test.yml | 60 +++++++++++++++++++++++++++++++++ .gitignore | 1 + Makefile | 23 +++++++++++++ README.md | 9 ++--- 10 files changed, 137 insertions(+), 62 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/startup.sh delete mode 100644 .docker/Dockerfile delete mode 100644 .dockerignore delete mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 Makefile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..edf1dfe --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +{ + "name": "Jupyter Environment", + "image": "mcr.microsoft.com/devcontainers/python:3", + "features": { + "ghcr.io/devcontainers/features/python:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-toolsai.jupyter", + "ms-toolsai.jupyter-keymap", + "ms-toolsai.jupyter-renderers", + "ms-toolsai.vscode-jupyter-cell-tags", + "ms-toolsai.vscode-jupyter-slideshow" + ] + } + }, + "onCreateCommand": ".devcontainer/startup.sh", + "forwardPorts": [8888], + "postStartCommand": "uv run jupyter lab --no-browser --ip=0.0.0.0 --port=8888 --NotebookApp.token='' --NotebookApp.password=''" +} diff --git a/.devcontainer/startup.sh b/.devcontainer/startup.sh new file mode 100755 index 0000000..1e96767 --- /dev/null +++ b/.devcontainer/startup.sh @@ -0,0 +1,5 @@ +#!/bin/bash +curl -LsSf https://astral.sh/uv/install.sh | sh +uv venv --python 3.12 +uv pip install --no-cache-dir jupyterlab +uv pip install --no-cache-dir -r requirements.txt diff --git a/.docker/Dockerfile b/.docker/Dockerfile deleted file mode 100644 index d6c7075..0000000 --- a/.docker/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -FROM docker.io/jupyter/base-notebook:lab-4.0.5 - -COPY requirements.txt . - -# Install Python deps, the user approach is documented here: -# https://pythonspeed.com/articles/multi-stage-docker-python/ -RUN pip install --user --no-cache-dir -r requirements.txt - -COPY --chown=jovyan:users . ${HOME}/work - - diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index a4b83e2..0000000 --- a/.dockerignore +++ /dev/null @@ -1,5 +0,0 @@ -.github -.git -.docker -.dockerignore -*.Rmd diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 207016d..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Publish Docker image - -on: - workflow_dispatch: - push: - branches: - - stable - tags: - - v* - -jobs: - - push_to_registry: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: jetaylor74/islp_labs - tags: | - type=ref,event=branch - type=semver,pattern={{raw}} - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - context: . - file: .docker/Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8e2aa27 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,21 @@ +name: Bump version and publish + +on: + #push: + workflow_dispatch + +permissions: + contents: write + +jobs: + tagging: + runs-on: ubuntu-latest + outputs: + new_tag: ${{ steps.tag_step.outputs.new_tag }} + + steps: + - name: Generate Tag + id: tag_step + uses: tschm/cradle/actions/tag@v0.1.57 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..764b979 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,60 @@ +# testing all notebooks +name: TEST + +on: + - push + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: ['3.11', '3.12'] + #notebook: [ Ch02-statlearn-lab.ipynb ]. # Ch02 is tricky but we have a solution for it + notebook: [ Ch03-linreg-lab.ipynb ] + # Ch04-classification-lab.ipynb, + # Ch05-resample-lab.ipynb, + # Ch06-varselect-lab.ipynb, + # Ch07-nonlin-lab.ipynb, + # Ch08-baggboost-lab.ipynb, + # Ch09-svm-lab.ipynb, + # Ch10-deeplearning-lab.ipynb, + # Ch11-surv-lab.ipynb, + # Ch12-unsup-lab.ipynb, + # Ch13-multiple-lab.ipynb] + #exclude: + # - python-version: '3.11' + # notebook: Ch10-deeplearning-lab.ipynb + + fail-fast: false + + steps: + - uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v5 + #with: + # version: "0.5.15" + + + #- name: Set up Python + # shell: bash + # run: | + # uv python install ${{ matrix.python-version }} + + - name: Create venv + shell: bash + run: uv venv --python ${{ matrix.python-version }} + + - name: Install requirements + shell: bash + run: | + uv pip install --upgrade pip + uv pip install -r requirements.txt + uv pip install pytest nbmake + + - name: Test + shell: bash + run: | + uv run pytest --nbmake --nbmake-timeout=3600 -vv ${{ matrix.notebook }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 73725b4..293d729 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ share/python-wheels/ # IDEs .vscode/ .idea/ + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7ffd70f --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +.DEFAULT_GOAL := help + +venv: + @curl -LsSf https://astral.sh/uv/install.sh | sh + @uv venv --python 3.12 + + +.PHONY: install +install: venv ## Install all dependencies (in the virtual environment) defined in requirements.txt + @uv pip install --upgrade pip + @uv pip install -r requirements.txt + + +.PHONY: help +help: ## Display this help screen + @echo -e "\033[1mAvailable commands:\033[0m" + @grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort + + +.PHONY: jupyter +jupyter: install ## Install and start jupyter Lab + @uv run pip install jupyterlab + @uv run jupyter lab diff --git a/README.md b/README.md index d1e2212..3085117 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # ISLP_labs + +[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/intro-stat-learning/ISLP_Labs) + [![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-) @@ -10,8 +13,6 @@ - Robert Tibshirani - Daniela Witten - -[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/intro-stat-learning/ISLP_labs/v2.2) ### ISLP @@ -23,7 +24,7 @@ if necessary, which is not included as a requirement of the labs. ### Up-to-date version of labs for ISLP. This repo will track labs for ISLP as their source code changes. The -intent is that building a conda environment with +intent is that building a virtual environment with `requirements.txt` will reproduce the results in this repo. To install the current version of the requirements run @@ -32,7 +33,7 @@ To install the current version of the requirements run pip install -r https://raw.githubusercontent.com/intro-stat-learning/ISLP_labs/v2.2/requirements.txt; ``` -The labs can now be run from this directory: +The labs can now be run via: ``` jupyter lab Ch02-statlearn-lab.ipynb