forked from meffie/molecule-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt tox to run unit tests and other development tasks. Keep a Makefile for convenience, but tox can be used directly if make is not available.
- Loading branch information
Showing
2 changed files
with
159 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,74 @@ | ||
|
||
.PHONY: help init lint import test sdist wheel rpm deb upload clean distclean | ||
# Copyright 2020-2024 Sine Nomine Associates | ||
# | ||
# This is a helper makefile to run tox. Run tox directly if make is not | ||
# available: | ||
# | ||
# $ python3 -m venv .venv | ||
# $ source .venv/bin/activate | ||
# (venv) $ pip install -U pip setuptools | ||
# (venv) $ pip install tox | ||
# (venv) $ tox | ||
# | ||
|
||
PYTHON3=python3 | ||
BIN=.venv/bin | ||
PIP=$(BIN)/pip | ||
PYTHON=$(BIN)/python | ||
PYFLAKES=$(BIN)/pyflakes | ||
YAMLLINT=$(BIN)/yamllint | ||
PYTEST=$(BIN)/pytest | ||
TWINE=$(BIN)/twine | ||
BASH=/bin/bash | ||
PIP=.venv/bin/pip | ||
TOX=.venv/bin/tox | ||
|
||
.PHONY: help | ||
help: | ||
@echo "usage: make <target>" | ||
@echo "" | ||
@echo "targets:" | ||
@echo " init create python virtual env" | ||
@echo " lint run linter" | ||
@echo " import import external ansible roles" | ||
@echo " test run tests" | ||
@echo " sdist create source distribution" | ||
@echo " wheel create wheel distribution" | ||
@echo " rpm create rpm package" | ||
@echo " deb create deb package" | ||
@echo " upload upload to pypi.org" | ||
@echo " init create python venv to run tox" | ||
@echo " lint run lint checks" | ||
@echo " check run quick tests" | ||
@echo " test run all tests" | ||
@echo " docs generate html docs" | ||
@echo " preview local preview html docs" | ||
@echo " release upload to pypi.org" | ||
@echo " clean remove generated files" | ||
@echo " distclean remove generated files and virtual env" | ||
@echo " distclean remove generated files and venvs" | ||
|
||
.venv: | ||
.venv/bin/activate: Makefile | ||
$(PYTHON3) -m venv .venv | ||
$(PIP) install -U pip wheel | ||
$(PIP) install -r requirements.txt | ||
$(PIP) install -e . | ||
$(PIP) install -U pip | ||
$(PIP) install tox | ||
touch .venv/bin/activate | ||
|
||
init: .venv | ||
.PHONY: init | ||
init: .venv/bin/activate | ||
|
||
.PHONY: lint | ||
lint: init | ||
$(PYFLAKES) src/*/*.py | ||
$(PYFLAKES) src/*/modules/*.py | ||
$(PYFLAKES) tests/*.py | ||
$(YAMLLINT) src/*/playbooks/*.yml | ||
$(YAMLLINT) tests/*/molecule/*/*.yml | ||
$(PYTHON) setup.py -q checkdocs | ||
|
||
test: init lint | ||
$(BASH) -c 'source $(BIN)/activate && $(PYTEST) -v -s' | ||
|
||
check: init lint | ||
$(BASH) -c 'source $(BIN)/activate && $(PYTEST) -v' | ||
$(TOX) -e lint | ||
|
||
sdist: init | ||
$(PYTHON) setup.py sdist | ||
.PHONY: check | ||
check: lint | ||
$(TOX) -e py312 | ||
|
||
wheel: init | ||
$(PYTHON) setup.py bdist_wheel | ||
.PHONY: test | ||
test: lint | ||
$(TOX) | ||
|
||
rpm: init | ||
$(PYTHON) setup.py bdist_rpm | ||
.PHONY: docs | ||
docs: init | ||
$(TOX) -e docs | ||
|
||
deb: init | ||
$(PYTHON) setup.py --command-packages=stdeb.command bdist_deb | ||
.PHONY: preview | ||
preview: docs | ||
xdg-open docs/build/html/index.html | ||
|
||
upload: init sdist wheel | ||
$(TWINE) upload dist/* | ||
.PHONY: release upload | ||
release upload: init | ||
$(TOX) -e release | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf .pytest_cache | ||
rm -rf src/*/__pycache__ | ||
rm -rf tests/__pycache__ | ||
rm -rf tests/molecule/*/library/__pycache__/ | ||
rm -rf .pytest_cache src/*/__pycache__ tests/__pycache__ | ||
rm -rf build dist | ||
|
||
distclean: clean | ||
rm -rf .eggs *.egg-info src/*.egg-info | ||
rm -rf .venv | ||
rm -rf docs/build | ||
|
||
.PHONY: reallyclean distclean | ||
reallyclean distclean: clean | ||
rm -rf .config .venv .tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
[tox] | ||
minversion = 4.11.4 | ||
env_list = py{310,311,312}-mol{600,603} | ||
|
||
# | ||
# Usage: tox [-e <enviroment>] [-- <pytest-options>] | ||
# tox -l # to list environments | ||
# | ||
[testenv] | ||
description = Run the tests | ||
package = wheel | ||
wheel_build_env = .pkg | ||
deps = | ||
pytest==7.4.4 | ||
ansible==9.1.0 | ||
molecule-plugins[docker]==23.5.0 | ||
mol600: molecule==6.0.0 | ||
mol603: molecule==6.0.3 | ||
passenv = | ||
SSH_* | ||
PROXMOX_* | ||
commands = | ||
pytest -v tests {posargs} | ||
|
||
# | ||
# Usage: tox -e dev | ||
# | ||
# To activate the development environment: | ||
# | ||
# deactivate | ||
# source .tox/dev/bin/activate | ||
# | ||
# Then run molecule in the tests directory: | ||
# | ||
# cd tests | ||
# BOX=<box> BOX_VERSION=<version> molecule test [-s <scenario>] | ||
# cd .. | ||
# | ||
# Or run the tests with pytest: | ||
# | ||
# pytest --co tests # list tests | ||
# pytest -v [-k <pattern>] tests # run tests | ||
# | ||
[testenv:dev] | ||
description = Development environment | ||
basepython = python3.12 | ||
usedevelop = True | ||
deps = | ||
pytest==7.4.4 | ||
ansible==9.1.0 | ||
molecule-plugins[docker]==23.5.0 | ||
molecule==6.0.3 | ||
passenv = | ||
SSH_* | ||
PROXMOX_* | ||
commands = | ||
|
||
# | ||
# Usage: tox -e lint | ||
# | ||
[testenv:lint] | ||
description = Run static checks | ||
basepython = python3.12 | ||
deps = | ||
collective.checkdocs==0.2 | ||
flake8==7.0.0 | ||
pyflakes==3.2.0 | ||
pylint==3.0.3 | ||
setuptools==69.0.3 | ||
yamllint==1.33.0 | ||
commands = | ||
pyflakes src tests | ||
yamllint src tests | ||
#flake8 src tests | ||
python setup.py -q checkdocs | ||
|
||
# | ||
# Usage: tox -e docs | ||
# | ||
[testenv:docs] | ||
description = Build documentation | ||
basepython = python3.12 | ||
changedir = docs | ||
deps = | ||
Sphinx==7.2.6 | ||
sphinx-rtd-theme==2.0.0 | ||
commands = | ||
sphinx-build -M html source build | ||
|
||
# | ||
# Usage: tox -e release | ||
# | ||
# Note: Set TWINE env vars or ~/.pypirc before running. | ||
# | ||
[testenv:release] | ||
basepython = python3.12 | ||
passenv = | ||
TWINE_USERNAME | ||
TWINE_PASSWORD | ||
TWINE_REPOSITORY_URL | ||
deps = | ||
build==1.0.3 | ||
twine==4.0.2 | ||
commands = | ||
python -m build | ||
twine check dist/* | ||
twine upload --skip-existing dist/* |