@@ -14,9 +14,9 @@ space_char +=
1414comma := ,
1515COMPONENT_PYTHONPATH = $(subst $(space_char ) ,:,$(realpath $(COMPONENTS ) ) )
1616
17- PYTHON_TARGET := 3.6
18-
19- REQUIREMENTS := test-requirements.txt requirements.txt
17+ # Extract the Python major/minor version to target the correct test requirements file.
18+ PYTHON_VERSION := $( shell python3 --version | sed -r 's/. * ([[0-9]+\.[0-9]+) \.[0-9]+.*/\1/g')
19+ REQUIREMENTS := test-requirements- $( PYTHON_VERSION ) .txt requirements.txt
2020# Grab the version of pip from the Makefile in the st2 repository
2121#
2222# 1. Grab the st2 branch name from ST2_BRANCH
@@ -73,7 +73,7 @@ pylint: requirements .pylint
7373 . $(VIRTUALENV_DIR ) /bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/actions/scripts/* /* .py || exit 1;
7474 . $(VIRTUALENV_DIR ) /bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/sensors/* .py || exit 1;
7575 . $(VIRTUALENV_DIR ) /bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/asserts/actions/* .py || exit 1;
76-
76+
7777.PHONY : flake8
7878flake8 : requirements .flake8
7979
@@ -107,8 +107,8 @@ requirements: virtualenv
107107
108108 # Install requirements
109109 for req in $(REQUIREMENTS); do \
110- echo "Installing $$req..." ; \
111- $(VIRTUALENV_DIR)/bin/pip install $(PIP_OPTIONS) -r $$req ; \
110+ echo "Installing $$req..." ; \
111+ $(VIRTUALENV_DIR)/bin/pip install $(PIP_OPTIONS) -r $$req ; \
112112 done
113113
114114.PHONY : virtualenv
@@ -117,7 +117,7 @@ $(VIRTUALENV_DIR)/bin/activate:
117117 @echo
118118 @echo " ==================== virtualenv ===================="
119119 @echo
120- test -d $(VIRTUALENV_DIR ) || virtualenv $(VIRTUALENV_DIR )
120+ test -d $(VIRTUALENV_DIR ) || python3 -m venv $(VIRTUALENV_DIR )
121121
122122 # Setup PYTHONPATH in bash activate script...
123123 echo '' >> $(VIRTUALENV_DIR)/bin/activate
@@ -140,3 +140,17 @@ $(VIRTUALENV_DIR)/bin/activate:
140140 echo ' functions -e old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
141141 echo 'end' >> $(VIRTUALENV_DIR)/bin/activate.fish
142142 touch $(VIRTUALENV_DIR)/bin/activate.fish
143+
144+ .PHONY : piptools
145+ piptools : virtualenv
146+ @echo
147+ @echo " ================== Install pip-tools ===================="
148+ @echo
149+ " $( VIRTUALENV_DIR) /bin/pip" install pip-tools
150+
151+ .PHONY : generate_requirements
152+ generate_requirements : piptools
153+ @echo
154+ @echo " ================== Generate requirements file ===================="
155+ @echo
156+ " $( VIRTUALENV_DIR) /bin/pip-compile" --output-file=$(ROOT_DIR ) /test-requirements-$(PYTHON_VERSION ) .txt $(ROOT_DIR ) /test-requirements.in
0 commit comments