|
1 | | -PYTHON_VERSIONS = 3.9 3.10 3.11 |
| 1 | +.DEFAULT_GOAL := help |
| 2 | + |
| 3 | + |
2 | 4 | PYTHON_VERSION ?= 3.10 |
3 | 5 | IMAGE = testcontainers-python:${PYTHON_VERSION} |
4 | | -RUN = docker run --rm -it |
5 | | -# Get all directories that contain a setup.py and get the directory name. |
6 | 6 | PACKAGES = core $(addprefix modules/,$(notdir $(wildcard modules/*))) |
7 | 7 |
|
8 | | -# All */dist folders for each of the packages. |
9 | | -DISTRIBUTIONS = $(addsuffix /dist,${PACKAGES}) |
10 | 8 | UPLOAD = $(addsuffix /upload,${PACKAGES}) |
11 | | -# All */tests folders for each of the test suites. |
12 | 9 | TESTS = $(addsuffix /tests,$(filter-out meta,${PACKAGES})) |
13 | 10 | TESTS_DIND = $(addsuffix -dind,${TESTS}) |
14 | 11 | DOCTESTS = $(addsuffix /doctests,$(filter-out modules/README.md,${PACKAGES})) |
15 | | -# All linting targets. |
16 | | -LINT = $(addsuffix /lint,${PACKAGES}) |
17 | | - |
18 | | -# Targets to build a distribution for each package. |
19 | | -dist: ${DISTRIBUTIONS} |
20 | | -${DISTRIBUTIONS} : %/dist : %/setup.py |
21 | | - cd $* \ |
22 | | - && python setup.py bdist_wheel \ |
23 | | - && twine check dist/* |
24 | | - |
25 | | -# Targets to run the test suite for each package. |
26 | | -tests : ${TESTS} |
27 | | -${TESTS} : %/tests : |
| 12 | + |
| 13 | + |
| 14 | +install: ## Set up the project for development |
| 15 | + poetry install --all-extras |
| 16 | + poetry run pre-commit install |
| 17 | + |
| 18 | +build: ## Build the python package |
| 19 | + poetry build && poetry run twine check dist/* |
| 20 | + |
| 21 | +tests: ${TESTS} ## Run tests for each package |
| 22 | +${TESTS}: %/tests: |
28 | 23 | poetry run pytest -v --cov=testcontainers.$* $*/tests |
29 | 24 |
|
30 | | -# Target to combine and report coverage. |
31 | | -coverage: |
| 25 | +coverage: ## Target to combine and report coverage. |
32 | 26 | poetry run coverage combine |
33 | 27 | poetry run coverage report |
34 | 28 | poetry run coverage xml |
35 | 29 | poetry run coverage html |
36 | 30 |
|
37 | | -# Target to lint the code. |
38 | | -lint: |
39 | | - pre-commit run -a |
40 | | - |
41 | | -# Targets to publish packages. |
42 | | -upload : ${UPLOAD} |
43 | | -${UPLOAD} : %/upload : |
44 | | - if [ ${TWINE_REPOSITORY}-$* = testpypi-meta ]; then \ |
45 | | - echo "Cannot upload meta package to testpypi because of missing permissions."; \ |
46 | | - else \ |
47 | | - twine upload --non-interactive --skip-existing $*/dist/*; \ |
48 | | - fi |
49 | | - |
50 | | -# Targets to build docker images |
51 | | -image: |
| 31 | +lint: ## Lint all files in the project, which we also run in pre-commit |
| 32 | + poetry run pre-commit run -a |
| 33 | + |
| 34 | +image: ## Make the docker image for dind tests |
52 | 35 | poetry export -f requirements.txt -o build/requirements.txt |
53 | | - docker build --build-arg version=${PYTHON_VERSION} -t ${IMAGE} . |
| 36 | + docker build --build-arg PYTHON_VERSION=${PYTHON_VERSION} -t ${IMAGE} . |
54 | 37 |
|
55 | | -# Targets to run tests in docker containers |
56 | | -tests-dind : ${TESTS_DIND} |
| 38 | +DOCKER_RUN = docker run --rm -v /var/run/docker.sock:/var/run/docker.sock |
57 | 39 |
|
58 | | -${TESTS_DIND} : %/tests-dind : image |
59 | | - ${RUN} -v /var/run/docker.sock:/var/run/docker.sock ${IMAGE} \ |
60 | | - bash -c "make $*/lint $*/tests" |
| 40 | +tests-dind: ${TESTS_DIND} ## Run the tests in docker containers to test `dind` |
| 41 | +${TESTS_DIND}: %/tests-dind: image |
| 42 | + ${DOCKER_RUN} ${IMAGE} \ |
| 43 | + bash -c "make $*/tests" |
61 | 44 |
|
62 | | -# Target to build the documentation |
63 | | -docs : |
| 45 | +docs: ## Build the docs for the project |
64 | 46 | poetry run sphinx-build -nW . docs/_build |
65 | 47 |
|
66 | 48 | # Target to build docs watching for changes as per https://stackoverflow.com/a/21389615 |
67 | 49 | docs-watch : |
68 | 50 | poetry run sphinx-autobuild . docs/_build # requires 'pip install sphinx-autobuild' |
69 | 51 |
|
70 | | -doctests : ${DOCTESTS} |
| 52 | +doctests: ${DOCTESTS} ## Run doctests found across the documentation. |
71 | 53 | poetry run sphinx-build -b doctest . docs/_build |
72 | 54 |
|
73 | | -${DOCTESTS} : %/doctests : |
| 55 | +${DOCTESTS}: %/doctests: ## Run doctests found for a module. |
74 | 56 | poetry run sphinx-build -b doctest -c doctests $* docs/_build |
75 | 57 |
|
76 | | -# Remove any generated files. |
77 | | -clean : |
| 58 | + |
| 59 | +clean: ## Remove generated files. |
78 | 60 | rm -rf docs/_build |
79 | | - rm -rf */build |
80 | | - rm -rf */dist |
| 61 | + rm -rf build |
| 62 | + rm -rf dist |
81 | 63 | rm -rf */*.egg-info |
82 | 64 |
|
| 65 | +clean-all: clean ## Remove all generated files and reset the local virtual environment |
| 66 | + rm -rf .venv |
| 67 | + |
83 | 68 | # Targets that do not generate file-level artifacts. |
84 | | -.PHONY : clean dists ${DISTRIBUTIONS} docs doctests image tests ${TESTS} |
| 69 | +.PHONY: clean docs doctests image tests ${TESTS} |
| 70 | + |
| 71 | + |
| 72 | +# Implements this pattern for autodocumenting Makefiles: |
| 73 | +# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html |
| 74 | +# |
| 75 | +# Picks up all comments that start with a ## and are at the end of a target definition line. |
| 76 | +.PHONY: help |
| 77 | +help: ## Display command usage |
| 78 | + @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
0 commit comments