Skip to content

Add support to run tests, linting, and mypy in Docker #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
with:
python-version: 3.8
architecture: x64
- run: make setup
- run: make check
- run: make setup-venv
- run: make checks
- run: bash <(curl -s https://codecov.io/bash)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea/
.vscode/
.venv/
_build/
notebooks/
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ARG BASE_IMAGE=python:3.8

FROM ${BASE_IMAGE} as base

LABEL maintainer='eugeneyan <[email protected]>'

# Use the opt directory as our dev directory
WORKDIR /opt

ENV PYTHONUNBUFFERED TRUE

COPY requirements.dev .
COPY requirements.prod .

# Install python dependencies
RUN pip install --upgrade pip \
&& pip install --no-cache-dir wheel \
&& pip install --no-cache-dir -r requirements.dev \
&& pip install --no-cache-dir -r requirements.prod \
&& pip list
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
setup:
.PHONY: setup-venv setup clean-pyc clean-test test mypy lint docs check

setup-venv:
python -m venv .venv && . .venv/bin/activate
pip install --upgrade pip
pip install -r requirements.dev
pip install -r requirements.prod

setup:
DOCKER_BUILDKIT=1 docker build -t dev -f Dockerfile .

clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
Expand All @@ -13,8 +18,11 @@ clean-pyc:
clean-test:
rm -f .coverage
rm -f .coverage.*
find . -name '.pytest_cache' -exec rm -fr {} +

clean: clean-pyc clean-test
find . -name '.my_cache' -exec rm -fr {} +
rm -rf logs/

test: clean
. .venv/bin/activate && py.test tests --cov=src --cov-report=term-missing --cov-fail-under 95
Expand All @@ -30,4 +38,10 @@ docs: FORCE
cd docs; . .venv/bin/activate && sphinx-build -b html ./source ./build
FORCE:

check: test lint mypy
checks: test lint mypy clean

run-checks:
docker run --rm -it --name run-checks -v $(shell pwd):/opt -t dev make checks

bash:
docker run --rm -it --name run-checks -v $(shell pwd):/opt -t dev bash
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ make setup -B
make check
```

Make a pull request to this repo to see the checks in action 😎
Make a pull request to this repo to see the checks in action 😎

Here's a [sample pull request](https://github.com/eugeneyan/python-collab-template/pull/1) which initially failed ❌ the checks, and then passed ✅.

Expand Down Expand Up @@ -175,3 +175,6 @@ jobs:
```

### 👉 View the [article](https://eugeneyan.com/writing/setting-up-python-project-for-automation-and-collaboration/) for the walkthrough.

### Todo
- [ ] Update requirements.txt to use `poetry`