Skip to content

Commit

Permalink
feat: add Python test matrix (superlinear-ai#102)
Browse files Browse the repository at this point in the history
* feat: add Python test matrix

* fix: don't interpolate test matrix with jinja

* ci: improve step names
  • Loading branch information
lsorber authored Sep 21, 2022
1 parent a684720 commit 7eb30ef
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: "3.8"

- name: Scaffold Python package
run: |
pip install --no-input cruft
cruft create --no-input --extra-context '{"package_name": "My Package", "python_version": "${{ matrix.python-version }}", "with_fastapi_api": "1", "with_typer_cli": "1"}' .
cruft create --no-input --extra-context '{"package_name": "My Package", "python_version": "3.8", "with_fastapi_api": "1", "with_typer_cli": "1"}' .
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: "16"

- name: Install @devcontainers/cli
run: npm install --location=global @devcontainers/cli

- name: Start Dev Container
- name: Start Dev Container with Python ${{ matrix.python-version }}
env:
DOCKER_BUILDKIT: 1
run: |
git config --global init.defaultBranch main
git init
git add .
devcontainer up --workspace-folder .
PYTHON_VERSION=${{ matrix.python-version }} devcontainer up --workspace-folder .
working-directory: ./my-package/

- name: Lint package
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To update your Python project with the latest template:
| `package_url` <br> "https://github.com/user/spline-reticulator" | The URL to the package's repository. |
| `author_name` <br> "John Smith" | The full name of the primary author of the package. |
| `author_email` <br> "[email protected]" | The email address of the primary author of the package. |
| `python_version` <br> "3.10" | The minimum Python version that the package requires. |
| `python_version` <br> "3.8" | The minimum Python version that the package requires. |
| `with_fastapi_api` <br> ["0", "1"] | If "1", [FastAPI](https://github.com/tiangolo/fastapi) is added as a run time dependency, FastAPI API stubs and tests are added, `poe` commands for serving the API are added, and an `app` stage is added to the Dockerfile that packages the API. Additionally, the CI workflow will push the application as a Docker image instead of publishing the Python package. |
| `with_jupyter_lab` <br> ["0", "1"] | If "1", [JupyterLab](https://github.com/jupyterlab/jupyterlab) is added to Poetry's dev dependencies, and a `poe lab` command is added to start Jupyter Lab in the `notebooks/` directory. |
| `with_pydantic_typing` <br> ["0", "1"] | If "1", [Pydantic](https://github.com/samuelcolvin/pydantic) is added as a run time dependency, and the [Pydantic mypy plugin](https://pydantic-docs.helpmanual.io/mypy_plugin/) is enabled and configured. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ jobs:
test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ["{{ cookiecutter.python_version }}"]

name: Python {% raw %}${{{% endraw %} matrix.python-version }}

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -28,7 +35,7 @@ jobs:
DOCKER_BUILDKIT: 1
run: |
git config --global init.defaultBranch main
devcontainer up --workspace-folder .
PYTHON_VERSION={% raw %}${{{% endraw %} matrix.python-version }} devcontainer up --workspace-folder .
- name: Lint package
run: devcontainer exec --workspace-folder . poe lint
Expand Down
3 changes: 2 additions & 1 deletion {{ cookiecutter.__package_name_kebab_case }}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# syntax=docker/dockerfile:1
FROM python:{{ cookiecutter.python_version }}-slim AS base
ARG PYTHON_VERSION={{ cookiecutter.python_version }}
FROM python:$PYTHON_VERSION-slim AS base

# Configure Python to print tracebacks on crash [1], and to not buffer stdout and stderr [2].
# [1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONFAULTHANDLER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- poetry_auth
{%- endif %}
args:
PYTHON_VERSION: ${PYTHON_VERSION:-{{ cookiecutter.python_version }}}
UID: ${UID:-1000}
GID: ${GID:-1000}
stdin_open: true
Expand Down

0 comments on commit 7eb30ef

Please sign in to comment.