Skip to content
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

added linting as pre-commit hook to Makefile #248

Closed
wants to merge 1 commit into from
Closed
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
57 changes: 36 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ SHELL := /bin/bash

.SILENT: build clean devenv docs publish test lint
.IGNORE: clean
.ONESHELL:

BLUE:=\033[0;34m
NC:=\033[0m # No Color
Expand All @@ -14,8 +15,8 @@ DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

# build the package from the source
build: devenv
. venv/bin/activate; \
python -m build; \
. venv/bin/activate;
python -m build;
twine check --strict dist/*

clean:
Expand All @@ -28,38 +29,52 @@ clean:
rm -f test-*.yml

devenv:
if [ ! -d "$(DIR)/venv" ]; then \
echo "Creating venv"; \
python -m venv venv/; \
if [ ! -d "$(DIR)/venv" ]; then
echo "Creating venv";
python -m venv venv/;
fi
@if ! venv/bin/python -c "import kafe2" 2>/dev/null; then \
echo "Installing kafe2 in editable mode"; \
. venv/bin/activate; \
pip install --upgrade -e .[dev]; \
@if ! venv/bin/python -c "import kafe2" 2>/dev/null; then
echo "Installing kafe2 in editable mode";
. venv/bin/activate;
pip install --upgrade -e .[dev];
fi
if [ ! -f "$(DIR)/.git/hooks/pre-commit" ]; then
echo "Creating pre-commit hook";
cat <<'EOF' > $(DIR)/.git/hooks/pre-commit
#!/bin/bash
if make lint; then
echo "Linting passed."
exit 0
else
echo "Linting failed. Aborting commit."
exit 1
fi
EOF
chmod +x $(DIR)/.git/hooks/pre-commit
fi

docs: devenv
echo "Generating Docs"
. venv/bin/activate; \
cd doc; \
$(MAKE) html; \
$(MAKE) latex;
. venv/bin/activate;
cd doc;
$(MAKE) html;
$(MAKE) late

publish: build
echo "uploading build to PyPI"
. venv/bin/activate; twine upload ./dist/*

test: devenv
echo "Running Pytest and Coverage"
. venv/bin/activate; \
pytest; \
. venv/bin/activate;
pytest;
coverage run

lint: devenv
. venv/bin/activate; \
echo -e "$(BLUE)${BOLD}ISORT${NC}$(NORM)"; \
isort --check --diff ./kafe2; \
echo -e "$(BLUE)${BOLD}BLACK${NC}$(NORM)"; \
black --check --diff ./kafe2; \
echo -e "$(BLUE)${BOLD}FLAKE8${NC}$(NORM)"; \
. venv/bin/activate;
echo -e "$(BLUE)${BOLD}ISORT${NC}$(NORM)";
isort --check --diff ./kafe2;
echo -e "$(BLUE)${BOLD}BLACK${NC}$(NORM)";
black --check --diff ./kafe2;
echo -e "$(BLUE)${BOLD}FLAKE8${NC}$(NORM)";
flake8 --config .flake8 ./kafe2;
Loading