forked from NVIDIA-AI-Blueprints/vulnerability-analysis
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (69 loc) · 3.12 KB
/
Makefile
File metadata and controls
85 lines (69 loc) · 3.12 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
# Ensure a consistent shell is used, avoiding potential issues with environment inheritance.
# https://www.gnu.org/software/make/manual/make.html#Makefile-Basics
SHELL = /bin/sh
# Clear the list of suffixes to disable built-in implicit rules.
.SUFFIXES:
# Directory for the main source code (override via `make lint-all SRC_DIR=./app`)
SRC_DIR ?= src
# Path to the LLM metrics test file
LLM_METRICS_TEST_FILE ?= tests/integration/generate_metrics.py
# Target branch for PR diffs in CI (override via `make lint-pr TARGET_BRANCH=develop`)
TARGET_BRANCH ?= rh-aiq-main
# Git remote for PR diffs in CI (override via `make lint-pr GIT_REMOTE=upstream`)
GIT_REMOTE ?= origin
# The pylint executable (override via `make lint PYLINT=pylint3`)
PYLINT ?= pylint
# The pytest executable (override via `make test PYTEST=pytest-xdist`)
PYTEST ?= pytest
# Extra options for pylint (override via `make lint PYLINT_OPTS="--disable=C0114"`)
PYLINT_OPTS ?=
# Extra options for pytest (override via `make test PYTEST_OPTS="-v -s --maxfail=1"`)
PYTEST_OPTS ?=
.PHONY: help lint lint-all lint-staged lint-pr test test-unit test-llm-metrics test-integration check
# Set the default target to "help"
.DEFAULT_GOAL := help
help: ## Display this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*## "}; {printf "\t%-20s %s\n", $$1, $$2}'
lint: lint-staged ## Lint staged files (default).
lint-all: ## Lint all source files.
@echo "--- Linting all source files ---"
@$(PYLINT) $(PYLINT_OPTS) $(SRC_DIR)
lint-staged: ## Lint staged files.
@echo "--- Linting staged files ---"
@{ \
FILES_TO_LINT=$$(git diff --name-only --cached --diff-filter=ACMRTUXB -- '*.py' ':(exclude)*/__init__.py'); \
if [ -z "$$FILES_TO_LINT" ]; then \
echo "No Python files staged for commit. Skipping."; \
else \
echo "Linting files:"; \
echo "$$FILES_TO_LINT" | sed 's/^/ /'; \
$(PYLINT) $(PYLINT_OPTS) $$FILES_TO_LINT; \
fi \
}
# TODO: During migration, linting errors are ignored to allow the pipeline to pass.
# Remove "|| true" from the pylint command below once the codebase is clean.
lint-pr: ## Lint PR changes (for CI).
@echo "--- Linting changed files in PR against $(GIT_REMOTE)/$(TARGET_BRANCH) ---"
@{ \
FILES_TO_LINT=$$(git diff --name-only "$(GIT_REMOTE)/$(TARGET_BRANCH)..." -- '*.py' ':(exclude)*/__init__.py'); \
if [ -z "$$FILES_TO_LINT" ]; then \
echo "No changed Python files in this PR. Skipping."; \
else \
echo "Linting files:"; \
echo "$$FILES_TO_LINT" | sed 's/^/ /'; \
$(PYLINT) $(PYLINT_OPTS) $$FILES_TO_LINT || true; \
fi \
}
test: test-unit test-llm-metrics ## Run all tests.
@echo "All tests have been run."
test-unit: ## Run unit tests.
@echo "Running unit tests in $(SRC_DIR)..."
@python -m pytest $(SRC_DIR) $(PYTEST_OPTS)
test-llm-metrics: ## Run LLM metrics tests.
@echo "Running LLM metrics tests..."
@python -m pytest $(LLM_METRICS_TEST_FILE) $(PYTEST_OPTS)
test-integration: ## Run integration tests (placeholder).
@echo "--- SKIPPING: Integration tests are not yet implemented. ---"
check: lint-all test ## Lint all files and run all tests.
@echo "Lint and all tests have been run."