|
| 1 | +# REDNAFI |
| 2 | +# This only works with embedded venv not virtualenv |
| 3 | +# Install venv: python3.8 -m venv venv |
| 4 | +# Activate venv: source venv/bin/activate |
| 5 | + |
| 6 | +# Usage (line =black line length, path = action path, ignore= exclude folders) |
| 7 | +# ------ |
| 8 | +# make pylinter [make pylinter line=88 path=.] |
| 9 | +# make pyupgrade |
| 10 | + |
| 11 | +path := . |
| 12 | +line := 88 |
| 13 | +ignore := *env |
| 14 | + |
| 15 | +all: |
| 16 | + @echo |
| 17 | + |
| 18 | +.PHONY: checkvenv |
| 19 | +checkvenv: |
| 20 | +# raises error if environment is not active |
| 21 | +ifeq ("$(VIRTUAL_ENV)","") |
| 22 | + @echo "Venv is not activated!" |
| 23 | + @echo "Activate venv first." |
| 24 | + @echo |
| 25 | + exit 1 |
| 26 | +endif |
| 27 | + |
| 28 | +.PHONY: pyupgrade |
| 29 | +pyupgrade: checkvenv |
| 30 | +# checks if pip-tools is installed |
| 31 | +ifeq ("$(wildcard venv/bin/pip-compile)","") |
| 32 | + @echo "Installing Pip-tools..." |
| 33 | + @pip install pip-tools |
| 34 | +endif |
| 35 | + |
| 36 | +ifeq ("$(wildcard venv/bin/pip-sync)","") |
| 37 | + @echo "Installing Pip-tools..." |
| 38 | + @pip install pip-tools |
| 39 | +endif |
| 40 | + |
| 41 | +# pip-tools |
| 42 | + @pip-compile --upgrade requirements-dev.txt |
| 43 | + @pip-compile --upgrade requirements.txt |
| 44 | + @pip-sync requirements-dev.txt requirements.txt |
| 45 | + |
| 46 | + |
| 47 | +.PHONY: pylinter |
| 48 | +pylinter: checkvenv |
| 49 | +# checks if black is installed |
| 50 | +ifeq ("$(wildcard venv/bin/black)","") |
| 51 | + @echo "Installing Black..." |
| 52 | + @pip install black |
| 53 | +endif |
| 54 | + |
| 55 | +# checks if isort is installed |
| 56 | +ifeq ("$(wildcard venv/bin/isort)","") |
| 57 | + @echo "Installing Isort..." |
| 58 | + @pip install isort |
| 59 | +endif |
| 60 | + |
| 61 | +# checks if flake8 is installed |
| 62 | +ifeq ("$(wildcard venv/bin/flake8)","") |
| 63 | + @echo -e "Installing flake8..." |
| 64 | + @pip install flake8 |
| 65 | + @echo |
| 66 | +endif |
| 67 | + |
| 68 | +# black |
| 69 | + @echo "Applying Black" |
| 70 | + @echo "----------------\n" |
| 71 | + @black --line-length $(line) --exclude $(ignore) $(path) |
| 72 | + @echo |
| 73 | + |
| 74 | +# isort |
| 75 | + @echo "Applying Isort" |
| 76 | + @echo "----------------\n" |
| 77 | + @isort --atomic --profile black $(path) |
| 78 | + @echo |
| 79 | + |
| 80 | +# flake8 |
| 81 | + @echo "Applying Flake8" |
| 82 | + @echo "----------------\n" |
| 83 | + @flake8 --max-line-length "$(line)" \ |
| 84 | + --max-complexity "18" \ |
| 85 | + --select "B,C,E,F,W,T4,B9" \ |
| 86 | + --ignore "E203,E266,E501,W503,F403,F401,E402" \ |
| 87 | + --exclude ".git,__pycache__,old, build, \ |
| 88 | + dist, venv" $(path) |
0 commit comments