Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ dmypy.json

# MacOS
DS_Store
.DS_Store

# logs
logs/
Expand Down
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
- id: flake8
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.3.2
hooks:
- id: isort
39 changes: 21 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ FILES = input output
help:
@echo "$(BOLD_BLUE)-----------------------------MAKE GUIDE----------------------------$(RESET_STYLES)"
@echo "$(BOLD_CYAN)make setup$(RESET_STYLES) : Setup pyflask-service"
@echo "$(BOLD_CYAN)make format$(RESET_STYLES) : Format and fix python code pyflask-service"
@echo "$(BOLD_CYAN)make format$(RESET_STYLES) : Format and fix python code in pyflask-service"
@echo "$(BOLD_CYAN)make lint$(RESET_STYLES) : Lint pyflask-service"
@echo "$(BOLD_CYAN)make test$(RESET_STYLES) : Test pyflask-service"
@echo "$(BOLD_CYAN)make debug$(RESET_STYLES) : Debug pyflask-service"
Expand All @@ -46,46 +46,49 @@ help:


setup: #: Use pip-tools, pip-compile, pip install
@echo "$(BOLD_CYAN)Setting up pyflask base$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Setting up pyflask base$(RESET_STYLES)"
# Check for venv, conda else exit
@echo "$(BOLD_CYAN)Installing pip-tools . . .$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Installing pip-tools . . .$(RESET_STYLES)"
pip install pip-tools
@echo "$(BOLD_CYAN)Generating requirements$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Generating requirements$(RESET_STYLES)"
pip-compile -q --build-isolation --output-file=requirements/requirements.txt requirements/requirements.in
@echo "$(BOLD_CYAN)Generating dev requirements$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Generating dev requirements$(RESET_STYLES)"
pip-compile -q --build-isolation --output-file=requirements/dev-requirements.txt requirements/dev-requirements.in
@echo "$(BOLD_CYAN)Syncing requirements$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Syncing requirements$(RESET_STYLES)"
pip-sync -q requirements/requirements.txt requirements/dev-requirements.txt
@echo "$(BOLD_CYAN)Installing requirements$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Installing requirements$(RESET_STYLES)"
pip install -r requirements/requirements.txt
@echo "$(BOLD_CYAN)Installing dev requirements$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Installing dev requirements$(RESET_STYLES)"
pip install -r requirements/dev-requirements.txt
@echo "$(BOLD_CYAN)Adding pre-commit hooks$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Adding pre-commit hooks$(RESET_STYLES)"
pre-commit install


format: #: Format and fix python code with black, isort, autoflake
@echo "$(BOLD_CYAN)Blackifying $(RESET_STYLES)🍳"
@echo "\n$(BOLD_CYAN)Blackifying$(RESET_STYLES) 🍳"
black --version
black $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
@echo "$(BOLD_CYAN)ISorting 〽️$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)ISorting$(RESET_STYLES) 〽️️"
isort --recursive $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
@echo "$(BOLD_CYAN)Flaking️❄️$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Flaking$(RESET_STYLES) ❄️"
flake8 --version
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)


lint: #: Run static analysis with flake8, mypy and bandit
@echo "$(BOLD_CYAN)Flake linting ❄️$(RESET_STYLES)"
lint: #: Run static analysis with flake8, radon, mypy and bandit
@echo "\n$(BOLD_CYAN)Linting with flake8$(RESET_STYLES) ❄️"
flake8 --version
flake8 $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
@echo "$(BOLD_CYAN)Static typing️️$(RESET_STYLES)⌨️"
@echo "\n$(BOLD_CYAN)Checking cyclomatic complexity with radon$(RESET_STYLES) 💫️"
radon --version
radon cc $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES) --total-average -nc
@echo "\n$(BOLD_CYAN)Static typing with mypy$(RESET_STYLES) ⌨️"
mypy --version
mypy $(APP_DIR) $(HOME_DIR_PY_FILES)
@echo "$(BOLD_CYAN)Securing with bandit️🕵️️$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Securing with bandit$(RESET_STYLES) 🕵️️"
bandit --version
bandit -l -i -r . --format=custom
@echo "$(BOLD_CYAN)Running pre-commit hooks 🏁️️️$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)Running pre-commit hooks$(RESET_STYLES) 🏁️️️"
pre-commit run --all-files
@echo "$(BOLD_CYAN)All checks passed 🏳️️️️$(RESET_STYLES)"
@echo "\n$(BOLD_CYAN)All checks passed$(RESET_STYLES) 🏳️️️️"

33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
pyflask-microservice-base
------------------------------------------------------------------------------
An "optionally opinionated and structured" flask boilerplate microservice for ideal development
An "optionally opinionated and structured" flask boilerplate microservice for jump-starting development

![Built with](https://img.shields.io/badge/-Built%20with-073551?style=flat-square)
![Python](https://img.shields.io/badge/-Python-3776AB?style=flat-square&logo=Python&logoColor=white)
![Flask](https://img.shields.io/badge/-Flask-000000?style=flat-square&logo=flask&logoColor=white)
![License](https://img.shields.io/github/license/pritam001/pyflask-microservice-base?style=flat-square&label=License)
![WIP](https://img.shields.io/badge/%20%F0%9F%9A%A7%20-Dev%20in%20progress-important)


Tools
------------------------------------------------------------------------------
[![Min Python Version 3.8+](https://img.shields.io/badge/python-3.8+-3776AB.svg?style=flat-square)](https://www.python.org/download/releases/3.8.0/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)
[![Static Analysis: flake8](https://img.shields.io/badge/static%20analysis-flake8-cccccc.svg?style=flat-square)](https://www.python.org/dev/peps/pep-0008/)
[![Static Typing: mypy](https://img.shields.io/badge/static%20typing-mypy-blue.svg?style=flat-square)](https://www.python.org/dev/peps/pep-0008/)
[![Security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg?style=flat-square)](https://github.com/PyCQA/bandit)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=flat-square&logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

[![Min Python Version 3.8+](https://img.shields.io/badge/python-3.8+-3776AB.svg?style=flat)](https://www.python.org/download/releases/3.8.0/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat)](https://github.com/psf/black)
[![Static Analysis: flake8](https://img.shields.io/badge/static%20analysis-flake8-cccccc.svg?style=flat)](https://github.com/PyCQA/flake8/)
[![Cyclomatic Complexity: radon](https://img.shields.io/badge/cyclomatic%20complexity-radon-ff5252.svg?style=flat)](https://github.com/rubik/radon)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://timothycrosley.github.io/isort/)
[![Static Typing: mypy](https://img.shields.io/badge/static%20typing-mypy-blue.svg?style=flat)](https://github.com/python/mypy/)
[![Security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg?style=flat)](https://github.com/PyCQA/bandit)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=flat&logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)

Development Status
------------------------------------------------------------------------------
![WIP](https://img.shields.io/badge/%20%F0%9F%9A%A7%20-Work%20in%20progress-important)

Usage Guide
------------------------------------------------------------------------------
Expand All @@ -38,10 +38,19 @@ Steps for creating boilerplate project in GitHub
\** [Guide to Conda environment](https://github.com/pritam001/pyflask-microservice-base/blob/master/documentation/conda.md)


Make Guide
------------------------------------------------------------------------------
Type `make help` for available commands

<p align="center"><img src="documentation/assets/make-help.gif" /></p>


Linting Guide
------------------------------------------------------------------------------
`make format` : Format and fix python code with black, isort, autoflake

`make lint` : Run static analysis with flake8, mypy and bandit
<p align="center"><img src="documentation/assets/make-format.gif" /></p>

`make lint` : Run static analysis with flake8, radon, mypy and bandit

<p align="center"><img src="documentation/assets/make-lint.gif" /></p>
Binary file added documentation/assets/make-format.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/assets/make-help.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added documentation/assets/make-lint.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements/dev-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ isort
mypy
# Security oriented static analyser for python code
bandit
# Complexity analysis
radon

# Flake8
flake8
Expand Down
8 changes: 6 additions & 2 deletions requirements/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ bandit==1.6.2 # via -r requirements/dev-requirements.in
black==19.10b0 # via -r requirements/dev-requirements.in
cfgv==3.2.0 # via pre-commit
click==7.1.2 # via black
colorama==0.4.3 # via radon
distlib==0.3.1 # via virtualenv
filelock==3.0.12 # via virtualenv
flake8-blind-except==0.1.1 # via -r requirements/dev-requirements.in
Expand All @@ -21,17 +22,19 @@ flake8-comprehensions==3.2.3 # via -r requirements/dev-requirements.in
flake8-flask==0.9.3 # via -r requirements/dev-requirements.in
flake8-logging-format==0.6.0 # via -r requirements/dev-requirements.in
flake8-plugin-utils==1.3.1 # via flake8-breakpoint, flake8-pytest-style, flake8-return
flake8-polyfill==1.0.2 # via pep8-naming
flake8-polyfill==1.0.2 # via pep8-naming, radon
flake8-print==3.1.4 # via -r requirements/dev-requirements.in
flake8-pytest-style==1.2.3 # via -r requirements/dev-requirements.in
flake8-pytest==1.3 # via -r requirements/dev-requirements.in
flake8-return==1.1.2 # via -r requirements/dev-requirements.in
flake8==3.8.3 # via -r requirements/dev-requirements.in, flake8-builtins, flake8-comprehensions, flake8-flask, flake8-polyfill, flake8-print, flake8-pytest
future==0.18.2 # via radon
gitdb==4.0.5 # via gitpython
gitpython==3.1.7 # via bandit
identify==1.4.25 # via pre-commit
isort==4.3.21 # via -r requirements/dev-requirements.in, pylint
lazy-object-proxy==1.4.3 # via astroid
mando==0.6.4 # via radon
mccabe==0.6.1 # via flake8, pylint
mypy-extensions==0.4.3 # via mypy
mypy==0.782 # via -r requirements/dev-requirements.in
Expand All @@ -45,8 +48,9 @@ pyflakes==2.2.0 # via autoflake, flake8
pylint==2.5.3 # via -r requirements/dev-requirements.in
pyyaml==5.3.1 # via bandit, pre-commit
r2c-py-ast==0.1.0b1 # via flake8-flask
radon==4.2.0 # via -r requirements/dev-requirements.in
regex==2020.7.14 # via black
six==1.15.0 # via astroid, bandit, flake8-print, virtualenv
six==1.15.0 # via astroid, bandit, flake8-print, mando, virtualenv
smmap==3.0.4 # via gitdb
stevedore==3.2.0 # via bandit
toml==0.10.1 # via black, pre-commit, pylint
Expand Down