diff --git a/.github/workflows/docker_tests.yaml b/.github/workflows/docker_tests.yaml new file mode 100644 index 0000000..37bda0a --- /dev/null +++ b/.github/workflows/docker_tests.yaml @@ -0,0 +1,44 @@ +# Run python unit tests + +name: docker tests + +on: + push: + schedule: + - + cron: "0 0 * * 1" + branches: [ $default-branch ] + +jobs: + unittests: + runs-on: ubuntu-latest + steps: + - + name: Checkout code + uses: actions/checkout@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + target: dev + push: false + tags: ${{ secrets.REPO_NAME }}:gha + cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.REPO_NAME }}:cache + cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.REPO_NAME }}:cache,mode=max + outputs: type=docker + - + name: Unit tests + run: docker run ${{ secrets.REPO_NAME }}:gha pytest + - + name: Style tests + run: docker run ${{ secrets.REPO_NAME }}:gha pre-commit run --all-files diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 8080c2b..e9bb5cb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -17,28 +17,25 @@ jobs: name: Checkout code uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 + name: Set up Python + uses: actions/setup-python@v4 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + python-version: "3.10" - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: . - target: dev - push: false - tags: ${{ secrets.REPO_NAME }}:gha - cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.REPO_NAME }}:cache - cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.REPO_NAME }}:cache,mode=max - outputs: type=docker + name: Install requirements + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade build + python -m pip install -r requirements/prod.txt + python -m pip install -r requirements/dev.txt + - + name: Build + run: | + python -m build + python -m pip install -e . --no-deps - name: Unit tests - run: docker run ${{ secrets.REPO_NAME }}:gha pytest + run: pytest - name: Style tests - run: docker run ${{ secrets.REPO_NAME }}:gha pre-commit run --all-files + run: pre-commit run --all-files diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8a15e53..5367f7f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -88,10 +88,10 @@ repos: # - id: setup-cfg-fmt - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.971 + rev: v0.982 hooks: - id: mypy - args: [] + args: [--show-error-codes] additional_dependencies: - numpy diff --git a/Dockerfile b/Dockerfile index 2d73c32..fea95cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10.6-slim-buster as base +FROM python:3.10.8-slim-buster as base # Install things RUN apt-get update diff --git a/README.md b/README.md index fcf917c..b1466c9 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,34 @@ This repository is a template for future repositories. Features: - Can be packaged with `pip` - Working `pytest` tests in `tests` directory - Install with `requirements/prod.txt` and `requirements/dev.txt` -- environment installed inside a Docker Container +- Environment installed inside a Docker Container - `README.md` file with repeatable instructions - Style checks using `flake8`, `mypy`, and `black` bundled into a single `pre-commit` action - GitHub Actions automates style and unit tests across matrixed Python versions - Uses Python 3.10 because stable [TensorFlow](https://www.tensorflow.org/install/pip) doesn't yet support Python 3.11 -## Develop in Docker +## Develop without Docker +1. Create a Python virtual environment in `3.10.8` + ``` + python -m venv + ``` +2. In this virtual environment, install necessary requirements files + ``` + python -m pip install -r requirements/dev.txt + python -m pip install -r requirements/prod.txt + ``` +3. Build and install + ``` + python -m build + python -m pip install -e . --no-deps + ``` +4. Test things + ``` + pre-commit run --all-files + pytest + ``` + +## Develop with Docker Code development is in a Docker image, use these steps to spin up the image 1. Download and install [Docker](https://docs.docker.com/engine/install/) 2. Clone this repository @@ -31,32 +52,21 @@ Code development is in a Docker image, use these steps to spin up the image exit ``` -## Develop without Docker -1. Create a Python virtual environment - ``` - python3 -m venv - ``` -2. In this virtual environment, install necessary requirements files - ``` - python -m pip install -r requirements/dev.txt - python -m pip install -r requirements/prod.txt - ``` -3. Build and install - ``` - python -m build - python -m pip install -e . --no-deps - ``` -4. Test things - ``` - pre-commit run --all-files - pytest - ``` - -## Updating requirements folder +## Updating requirements directory 1. Use pip-compile to build a new pinned requirements file. ``` pip-compile requirements/prod.in --output-file=requirements/prod.txt pip-compile requirements/dev.in --output-file=requirements/dev.txt + ``` +2. If using Docker, rebuild the container using the commands above. + ``` exit ``` -2. Rebuild the container using the commands above. + +## When cloning this template: +1. Change the python version across config files +2. Change the Docker image names +3. Docker GitHub Actions will fail until certain Secrets are uploaded + 1. `REPO_NAME`: The name of the Docker repository + 2. `DOCKERHUB_USERNAME`: The DockerHub username + 3. `DOCKERHUB_TOKEN`: A token for access to the repository diff --git a/requirements/dev.in b/requirements/dev.in index 7829600..ac2cbec 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -1,6 +1,6 @@ black==22.6.0 identify>=2.5.3,<3 -mypy>=0.971,<1 +mypy>=0.982,<1 pip-tools>=6.8.0,<7 pre-commit>=2.20.0,<3 pytest>=7.1.2,<8 diff --git a/requirements/dev.txt b/requirements/dev.txt index f7cf067..3771d5f 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -26,7 +26,7 @@ identify==2.5.3 # pre-commit iniconfig==1.1.1 # via pytest -mypy==0.971 +mypy==0.982 # via -r requirements/dev.in mypy-extensions==0.4.3 # via