Pre-commit helper

This commit is contained in:
Faustin Lammler 2022-10-12 11:28:48 +02:00
parent 32dba5411d
commit bc0663c9f3
No known key found for this signature in database
GPG Key ID: 390A2F27832A5C79
2 changed files with 35 additions and 4 deletions

View File

@ -6,6 +6,9 @@ help:
@grep -E '^[a-zA-Z1-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 }'
venv: ## Create python3 venv if it does not exists
[[ -d $(VENV_DIR) ]] || $(shell command -v python3) -m venv $(VENV_DIR)
install: ## Install all necessary tools
$(MAKE) \
venv \
@ -13,9 +16,6 @@ install: ## Install all necessary tools
@echo -e "\n--> You should now activate the python3 venv with:"
@echo -e "source $(VENV_DIR)/bin/activate"
venv: ## Create python3 venv if it does not exists
[[ -d $(VENV_DIR) ]] || $(shell command -v python3) -m venv $(VENV_DIR)
install-pip-packages: ## Install python3 requirements
$(info --> Install requirements via `pip3`)
@( \
@ -26,5 +26,17 @@ install-pip-packages: ## Install python3 requirements
upgrade-pip-packages: ## Upgrade python3 requirements
$(shell command -v pip3) install -U -r requirements.txt
install-pre-commit: ## Install pre-commit tool
$(info --> Install pre-commit tool via `pip3`)
pip3 install pre-commit
pre-commit-run: ## Run pre-commit hooks with $PRE_COMMIT_ARGS default to (diff master...[current_branch])
$(info --> run pre-commit on changed files (pre-commit run))
pre-commit run $(PRE_COMMIT_ARGS) --color=always
pre-commit-run-all: ## Run pre-commit on the whole repository
$(info --> run pre-commit on the whole repo (pre-commit run -a))
pre-commit run -a --color=always
clean: ## Clean venv
[[ ! -d $(VENV_DIR) ]] || rm -rf $(VENV_DIR)

View File

@ -21,7 +21,26 @@ ansible modules that depend on [PyMySQL](https://github.com/PyMySQL/PyMySQL).
Only Python 3.X versions are supported and tested. Python 2.7 is probalbly
working but not tested.
## Testing (Molecule)
### pre-commit
Any code submitted to this project is checked with the
[pre-commit](https://pre-commit.com/) framework. To make sure that your
code will pass the checks, you can execute the pre-commit checks locally before
"git pushing" your code.
Here is how:
```console
make venv
source .venv/bin/activate
make install-pre-commit
make pre-commit-run
```
You can also [install](https://pre-commit.com/#install) the pre-commit tool so
that any commit will be checked automatically.
### Testing (Molecule)
The role is tested with the [Molecule
project](https://molecule.readthedocs.io/en/latest/index.html). By default this