Skip to content

Commit 413928e

Browse files
committed
Makefile functions, lint with black flake bandit
1 parent 87e180a commit 413928e

File tree

9 files changed

+67
-18
lines changed

9 files changed

+67
-18
lines changed

.bandit

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[bandit]
2+
targets: src,test,*.py
3+
exclude: dummy.py
4+
skips:
5+
tests:

.flake8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
ignore = E203, E266, E501, W503, F403, F401
3+
max-line-length = 127
4+
max-complexity = 10
5+
select = B,C,E,F,W,T4,B9

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,5 @@ DS_Store
138138
# logs
139139
logs/
140140

141+
# mypy
142+
.mypy_cache/

.mypy.ini

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Global options:
2+
3+
[mypy]
4+
python_version = 3.6
5+
warn_return_any = True
6+
warn_unused_configs = True
7+
ignore_missing_imports = True
8+
9+
# Per-module options:
10+
11+
[*.py]
12+
ignore_missing_imports = True
13+
14+
[src]
15+
ignore_missing_imports = True
16+
17+
[test]
18+
ignore_missing_imports = True

Makefile

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
CONDA_ENV_NAME=pyflask-base
12
APP_NAME=pyflask-service
2-
APP_DIR=app
3-
TESTS_DIR=tests
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
417

518
# Signifies our desired python version
619
# 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.
@@ -19,15 +32,22 @@ FILES = input output
1932

2033
# The @ makes sure that the command itself isn't echoed in the terminal
2134
help:
22-
@echo "-----------------------------Make help-----------------------------"
23-
@echo "make setup : Setup pyflask-service"
24-
@echo "make lint : Lint pyflask-service"
25-
@echo "make test : Test pyflask-service"
26-
@echo "make debug : Debug pyflask-service"
27-
@echo "make clean : Clean pyflask-service"
28-
@echo "make dev-run : Run pyflask-service in environment=development"
29-
@echo "make prod-run : Run pyflask-service in environment=prod"
30-
@echo "-------------------------------------------------------------------"
31-
32-
35+
@echo "$(BOLD_BLUE)-----------------------------MAKE GUIDE----------------------------$(RESET_STYLES)"
36+
@echo "$(BOLD_CYAN)make setup$(RESET_STYLES) : Setup pyflask-service"
37+
@echo "$(BOLD_CYAN)make lint$(RESET_STYLES) : Lint pyflask-service"
38+
@echo "$(BOLD_CYAN)make test$(RESET_STYLES) : Test pyflask-service"
39+
@echo "$(BOLD_CYAN)make debug$(RESET_STYLES) : Debug pyflask-service"
40+
@echo "$(BOLD_CYAN)make clean$(RESET_STYLES) : Clean pyflask-service"
41+
@echo "$(BOLD_CYAN)make dev-run$(RESET_STYLES) : Run pyflask-service in environment=development"
42+
@echo "$(BOLD_CYAN)make prod-run$(RESET_STYLES) : Run pyflask-service in environment=prod"
43+
@echo "$(BOLD_BLUE)-------------------------------------------------------------------$(RESET_STYLES)"
44+
45+
46+
lint: #: Run static analysis with black, flake8, pylint, bandit and mypy
47+
@echo "$(BOLD_CYAN)Blackifying $(RESET_STYLES)🍳"
48+
black $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
49+
@echo "$(BOLD_CYAN)Flaking️❄️$(RESET_STYLES)"
50+
flake8 $(APP_DIR) $(TEST_DIR) $(HOME_DIR_PY_FILES)
51+
@echo "$(BOLD_CYAN)Trying to loot️🕵️️$(RESET_STYLES)"
52+
bandit -l -i -r .
3353

scripts/service_rename.sh

100644100755
File mode changed.

service_master.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
if __name__ == "__main__":
10-
log.info(f"Created app instance. Initiating run . . .")
10+
log.info("Created app instance. Initiating run . . .")
1111
app.run(
1212
host=settings.API.SERVER.url,
1313
port=settings.API.SERVER.port,

src/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
log = Logger()
66

7-
log.info(f"Creating app instance . . .")
7+
log.info("Creating app instance . . .")
88
server = Server() # Generate singleton instance of server
99
app = server.get_app() # Get Flask app reference from server instance
10-
log.info(f"Registering blueprints . . .")
10+
log.info("Registering blueprints . . .")
1111
register_blueprints(app) # Register all blueprints to app reference
12-

src/routes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
def register_blueprints(app):
88
app.register_blueprint(health_blueprint)
9-
log.info(f"Registered health blueprint")
9+
log.info("Registered health blueprint")

0 commit comments

Comments
 (0)