-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
85 lines (70 loc) · 2.77 KB
/
Copy pathmakefile
File metadata and controls
85 lines (70 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
##########################################
# Makefile to Launchpad GDPR Obfuscator Service - (Linux | GitBash | GitHub Actions)
##########################################
PROJECT_NAME = Obfuscation-Service
WD=$(shell pwd)
PYTHONPATH=${WD}/src:${WD}
SHELL := /bin/bash
PYTHON = python
PIP = pip
ACTIVATE_ENV := source venv/bin/activate
PYTHON_INTERPRETER = python3
# Helper to run commands inside venv
define execute_in_env
$(ACTIVATE_ENV) && $1
endef
# create python interpreter enviorment.
create-environment:
@echo ">>> Creating python virtual enviorment for: $(PROJECT_NAME)..."
@echo ">>> Checking python3 version"
( \
$(PYTHON_INTERPRETER) --version; \
)
@echo ">>> Setting up virtualenvironment..."
( \
$(PIP) install -q virtualenv virtualenvwrapper; \
virtualenv venv --python=$(PYTHON_INTERPRETER); \
)
@echo ">>> Upgrading pip inside venv..."
$(call execute_in_env, $(PIP) install --upgrade pip)
@echo ">>> Virtual environment created successfully!"
# Install all requirements
requirements: create-environment
$(call execute_in_env, $(PIP) install -r requirements.txt)
##################################################################
# Quality, Security & Testing
# Run bandit (security scanner) on every python file
security-test:
$(call execute_in_env, bandit -lll -r */*.py)
@echo ">>> Security scan completed successfully!"
# Run black (code formatter)
run-black:
$(call execute_in_env, black ./src ./tests)
@echo ">>> Code formatted successfully!"
# Run flake8 (code linter)
lint:
$(call execute_in_env, flake8 --max-line-length=100 src tests)
@echo ">>> Linting completed successfully!"
# Run tests
unit-test:
$(call execute_in_env, PYTHONPATH=$(PYTHONPATH) $(PYTHON_INTERPRETER) -m pytest tests -vv -s --color=yes)
@echo ">>> Unit tests completed successfully!"
# Vulnerability check
audit:
$(call execute_in_env, pip-audit)
@echo ">>> Vulnerability audit completed successfully!"
# Run all tests in one
run-checks: unit-test run-black security-test audit lint
@echo ">> All checks passed successfully! Obfuscation-Service is PEP8 compliant! <<"
# Run coverage check and create a coverage.txt file
check-coverage-txt:
@echo ">>> Generating Integrated Quality & Security Report..."
$(call execute_in_env, PYTHONPATH=$(PYTHONPATH) $(PYTHON_INTERPRETER) -m coverage run -m pytest tests)
@echo "--- UNIT TEST COVERAGE REPORT ---" > coverage.txt
$(call execute_in_env, $(PYTHON_INTERPRETER) -m coverage report -m > coverage.txt)
@echo -e "\n--- SECURITY SCAN REPORT (BANDIT) ---" >> coverage.txt
-$(call execute_in_env, bandit -lll -r src/ >> coverage.txt 2>&1)
@echo -e "\n--- VULNERABILITY AUDIT REPORT (PIP-AUDIT) ---" >> coverage.txt
-$(call execute_in_env, pip-audit >> coverage.txt 2>&1)
@rm -f .coverage
@echo "Integrated report as coverage.txt created successfully!"