|
| 1 | +CONDA_ENV_NAME=pyflask-base |
| 2 | +APP_NAME=pyflask-service |
| 3 | +APP_DIR=src |
| 4 | +TEST_DIR=test |
| 5 | +HOME_DIR_PY_FILES=*.py |
| 6 | + |
| 7 | +# echo _FormatCode_ guide: |
| 8 | +# 0 Reset all styles |
| 9 | +# 1 Bold |
| 10 | +# 32 Green |
| 11 | +# 34 Blue |
| 12 | +# 35 Magenta |
| 13 | +# 36 Cyan |
| 14 | +RESET_STYLES=\033[0m |
| 15 | +BOLD_BLUE=\033[1m\033[34m |
| 16 | +BOLD_CYAN=\033[1m\033[36m |
| 17 | + |
| 18 | +# Signifies our desired python version |
| 19 | +# Makefile macros (or variables) are defined a little bit differently than traditional bash, keep in mind that in the Makefile there's top-level Makefile-only syntax, and everything else is bash script syntax. |
| 20 | +PYTHON = python3 |
| 21 | + |
| 22 | +# .PHONY defines parts of the makefile that are not dependant on any specific file |
| 23 | +# This is most often used to store functions |
| 24 | +.PHONY = help setup format lint test debug clean |
| 25 | + |
| 26 | +# Defining an array variable |
| 27 | +FILES = input output |
| 28 | + |
| 29 | +# Defines the default target that `make` will to try to make, or in the case of a phony target, execute the specified commands |
| 30 | +# This target is executed whenever we just type `make` |
| 31 | +.DEFAULT_GOAL = help |
| 32 | + |
| 33 | + |
| 34 | +# The @ makes sure that the command itself isn't echoed in the terminal |
| 35 | +help: |
| 36 | + @echo "$(BOLD_BLUE)-----------------------------MAKE GUIDE----------------------------$(RESET_STYLES)" |
| 37 | + @echo "$(BOLD_CYAN)make setup$(RESET_STYLES) : Setup pyflask-service" |
| 38 | + @echo "$(BOLD_CYAN)make format$(RESET_STYLES) : Format and fix python code pyflask-service" |
| 39 | + @echo "$(BOLD_CYAN)make lint$(RESET_STYLES) : Lint pyflask-service" |
| 40 | + @echo "$(BOLD_CYAN)make test$(RESET_STYLES) : Test pyflask-service" |
| 41 | + @echo "$(BOLD_CYAN)make debug$(RESET_STYLES) : Debug pyflask-service" |
| 42 | + @echo "$(BOLD_CYAN)make clean$(RESET_STYLES) : Clean pyflask-service" |
| 43 | + @echo "$(BOLD_CYAN)make dev-run$(RESET_STYLES) : Run pyflask-service in environment=development" |
| 44 | + @echo "$(BOLD_CYAN)make prod-run$(RESET_STYLES) : Run pyflask-service in environment=prod" |
| 45 | + @echo "$(BOLD_BLUE)-------------------------------------------------------------------$(RESET_STYLES)" |
| 46 | + |
| 47 | + |
| 48 | +setup: #: Use pip-tools, pip-compile, pip install |
| 49 | + @echo "$(BOLD_CYAN)Setting up pyflask base$(RESET_STYLES)" |
| 50 | + # Check for venv, conda else exit |
| 51 | + @echo "$(BOLD_CYAN)Installing pip-tools . . .$(RESET_STYLES)" |
| 52 | + pip install pip-tools |
| 53 | + @echo "$(BOLD_CYAN)Generating requirements$(RESET_STYLES)" |
| 54 | + pip-compile -q --build-isolation --output-file=requirements/requirements.txt requirements/requirements.in |
| 55 | + @echo "$(BOLD_CYAN)Generating dev requirements$(RESET_STYLES)" |
| 56 | + pip-compile -q --build-isolation --output-file=requirements/dev-requirements.txt requirements/dev-requirements.in |
| 57 | + @echo "$(BOLD_CYAN)Syncing requirements$(RESET_STYLES)" |
| 58 | + pip-sync -q requirements/requirements.txt requirements/dev-requirements.txt |
| 59 | + @echo "$(BOLD_CYAN)Installing requirements$(RESET_STYLES)" |
| 60 | + pip install -r requirements/requirements.txt |
| 61 | + @echo "$(BOLD_CYAN)Installing dev requirements$(RESET_STYLES)" |
| 62 | + pip install -r requirements/dev-requirements.txt |
| 63 | + @echo "$(BOLD_CYAN)Adding pre-commit hooks$(RESET_STYLES)" |
| 64 | + pre-commit install |
| 65 | + |
| 66 | + |
| 67 | +format: #: Format and fix python code with black, isort, autoflake |
| 68 | + @echo "$(BOLD_CYAN)Blackifying $(RESET_STYLES)🍳" |
| 69 | + black --version |
| 70 | + black $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) |
| 71 | + @echo "$(BOLD_CYAN)ISorting 〽️$(RESET_STYLES)️" |
| 72 | + isort --recursive $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) |
| 73 | + @echo "$(BOLD_CYAN)Flaking️❄️$(RESET_STYLES)" |
| 74 | + flake8 --version |
| 75 | + autoflake --remove-all-unused-imports --remove-unused-variables --remove-duplicate-keys --ignore-init-module-imports -i -r $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) |
| 76 | + |
| 77 | + |
| 78 | +lint: #: Run static analysis with flake8, mypy and bandit |
| 79 | + @echo "$(BOLD_CYAN)Flake linting ❄️$(RESET_STYLES)" |
| 80 | + flake8 --version |
| 81 | + flake8 $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) |
| 82 | + @echo "$(BOLD_CYAN)Static typing️️$(RESET_STYLES)⌨️" |
| 83 | + mypy --version |
| 84 | + mypy $(APP_DIR) $(HOME_DIR_PY_FILES) |
| 85 | + @echo "$(BOLD_CYAN)Securing with bandit️🕵️️$(RESET_STYLES)" |
| 86 | + bandit --version |
| 87 | + bandit -l -i -r . --format=custom |
| 88 | + @echo "$(BOLD_CYAN)Running pre-commit hooks 🏁️️️$(RESET_STYLES)" |
| 89 | + pre-commit run --all-files |
| 90 | + @echo "$(BOLD_CYAN)All checks passed 🏳️️️️$(RESET_STYLES)" |
| 91 | + |
0 commit comments