@@ -14,9 +14,8 @@ space_char +=
1414comma := ,
1515COMPONENT_PYTHONPATH = $(subst $(space_char ) ,:,$(realpath $(COMPONENTS ) ) )
1616
17- PYTHON_TARGET := 3.10
18-
19- REQUIREMENTS := test-requirements.txt requirements.txt
17+ PYTHON_VERSION := $(shell python3 --version | sed -r 's/.* ([[0-9]+\.[0-9]+) \.[0-9]+.*/\1/g')
18+ REQUIREMENTS := test-requirements-$(PYTHON_VERSION ) .txt requirements.txt
2019# Grab the version of pip from the Makefile in the st2 repository
2120#
2221# 1. Grab the st2 branch name from ST2_BRANCH
@@ -73,7 +72,7 @@ pylint: requirements .pylint
7372 . $(VIRTUALENV_DIR ) /bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/actions/scripts/* /* .py || exit 1;
7473 . $(VIRTUALENV_DIR ) /bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/sensors/* .py || exit 1;
7574 . $(VIRTUALENV_DIR ) /bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/asserts/actions/* .py || exit 1;
76-
75+
7776.PHONY : flake8
7877flake8 : requirements .flake8
7978
@@ -140,3 +139,35 @@ $(VIRTUALENV_DIR)/bin/activate:
140139 echo ' functions -e old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
141140 echo 'end' >> $(VIRTUALENV_DIR)/bin/activate.fish
142141 touch $(VIRTUALENV_DIR)/bin/activate.fish
142+
143+ .PHONY : piptools
144+ piptools : virtualenv
145+ @echo
146+ @echo " ================== Install pip-tools ===================="
147+ @echo
148+ " $( VIRTUALENV_DIR) /bin/pip" install pip-tools
149+
150+ .PHONY : generate_requirements
151+ generate_requirements : piptools
152+ @echo
153+ @echo " ================== Generate requirements file ===================="
154+ @echo
155+ " $( VIRTUALENV_DIR) /bin/pip-compile" --output-file=$(ROOT_DIR ) /test-requirements-$(PYTHON_VERSION ) .txt $(ROOT_DIR ) /test-requirements.in
156+
157+ .PHONY : check_generated_files
158+ check_generated_files :
159+ # Verify that all the files that are automatically generated have been regenerated and committed.
160+ @echo " ==================== Check requirements file ===================="
161+ make generate_requirements
162+ export NEED_COMMIT=0; \
163+ export REQ_FILE=" $( ROOT_DIR) /test-requirements-$( PYTHON_VERSION) .txt"
164+ export FILE=$$(git status -s "$$REQ_FILE" ) ; \
165+ if grep -E " M $$ REQ_FILE" <<< $$ FILE ; then \
166+ echo " $$ REQ_FILE hasn't been re-generated and committed. Please run \" make generate_requirements\" then include and commit the generated file." ; \
167+ export NEED_COMMIT=1; \
168+ git diff " $$ REQ_FILE" | cat; \
169+ elif grep -E " \?\? $$ REQ_FILE" <<< $$ FILE ; then \
170+ echo " $$ REQ_FILE does not appear to be under git control!? Please add it to git or remove it from the directory." ; \
171+ fi ; \
172+ test $$ NEED_COMMIT -eq 1 && exit 2 || true
173+ @echo " All automatically generated files are up to date."
0 commit comments