-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMakefile
More file actions
156 lines (134 loc) · 6.21 KB
/
Makefile
File metadata and controls
156 lines (134 loc) · 6.21 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SHELL := /bin/bash
TOX_DIR := .tox
VIRTUALENV_DIR ?= virtualenv
BINARIES := bin
# All components are prefixed by st2
COMPONENTS := $(wildcard st2/st2*)
# nasty hack to get a space into a variable
space_char :=
space_char +=
comma := ,
COMPONENT_PYTHONPATH = $(subst $(space_char),:,$(realpath $(COMPONENTS)))
# Extract the Python major/minor version to target the correct test requirements file.
PYTHON_VERSION := $(shell python3 --version | sed -r 's/.*([[0-9]+\.[0-9]+)\.[0-9]+.*/\1/g')
REQUIREMENTS := test-requirements-$(PYTHON_VERSION).txt requirements.txt
# Grab the version of pip from the Makefile in the st2 repository
#
# 1. Grab the st2 branch name from ST2_BRANCH
# | 2. Grab the st2 branch from CIRCLE_BRANCH if ST2_BRANCH
# isn't set or is empty
# | | 3. Default branch name, if CIRCLE_BRANCH
# | | and ST2_BRANCH aren't set or are empty
# vvvvvvvvvv vvvvvvvvvvvvv vvvvvv
# $${ST2_BRANCH:-$${CIRCLE_BRANCH:-master}}
#
# This line grabs the version of pip specified in the
#
# PIP_VERSION ?= xx.yy.zz
#
# line of the st2/Makefile, grabs the third column of it, and then installs
# that exact version of pip into the virtualenv.
#
# If the branch is specified in either ST2_BRANCH or CIRCLE_BRANCH, but there
# is no corresponding branch in st2, then curl will error out, and the master
# branch of st2 will be used.
#
ST2_BRANCH := $(shell echo $${ST2_BRANCH:-$${CIRCLE_BRANCH:-master}})
PIP_VERSION := $(shell curl --silent https://raw.githubusercontent.com/StackStorm/st2/$(ST2_BRANCH)/Makefile | grep 'PIP_VERSION ?= ' | awk '{ print $$3 }')
ifeq ($(PIP_VERSION),)
ST2_BRANCH := master
PIP_VERSION := $(shell curl --silent https://raw.githubusercontent.com/StackStorm/st2/$(ST2_BRANCH)/Makefile | grep 'PIP_VERSION ?= ' | awk '{ print $$3 }')
endif
PIP_OPTIONS := $(ST2_PIP_OPTIONS)
NOSE_OPTS := --rednose --immediate
NOSE_TIME := $(NOSE_TIME)
ifdef NOSE_TIME
NOSE_OPTS := --rednose --immediate --with-timer
endif
ifndef PIP_OPTIONS
PIP_OPTIONS := -U
endif
.PHONY: all
all: pylint
.PHONY: pylint
pylint: requirements .pylint
.PHONY: .pylint
.pylint:
@echo
@echo "================== pylint ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/actions/pythonactions/*.py || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/actions/scripts/*.py || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/actions/scripts/*/*.py || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/fixtures/sensors/*.py || exit 1;
. $(VIRTUALENV_DIR)/bin/activate; pylint -E --rcfile=./lint-configs/python/.pylintrc packs/asserts/actions/*.py || exit 1;
.PHONY: flake8
flake8: requirements .flake8
.PHONY: .flake8
.flake8:
@echo
@echo "==================== flake ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 packs/fixtures/actions/pythonactions/*.py
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 packs/fixtures/actions/scripts/*.py
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 packs/fixtures/actions/scripts/*/*.py
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 packs/fixtures/sensors/*.py
. $(VIRTUALENV_DIR)/bin/activate; flake8 --config ./lint-configs/python/.flake8 packs/asserts/actions/*.py
.PHONY: lint
lint: requirements .lint
.PHONY: .lint
.lint: .flake8 .pylint
.PHONY: requirements
requirements: virtualenv
@echo
@echo "==================== requirements ===================="
@echo
# Make sure we use latest version of pip
echo "Installing pip $(PIP_VERSION) (found from st2 branch $(ST2_BRANCH))"
$(VIRTUALENV_DIR)/bin/pip install --upgrade "pip==$(PIP_VERSION)"
$(VIRTUALENV_DIR)/bin/pip install virtualenv # Required for packs.install in dev envs.
# Install requirements
for req in $(REQUIREMENTS); do \
echo "Installing $$req..." ; \
$(VIRTUALENV_DIR)/bin/pip install $(PIP_OPTIONS) -r $$req ; \
done
.PHONY: virtualenv
virtualenv: $(VIRTUALENV_DIR)/bin/activate
$(VIRTUALENV_DIR)/bin/activate:
@echo
@echo "==================== virtualenv ===================="
@echo
test -d $(VIRTUALENV_DIR) || python3 -m venv $(VIRTUALENV_DIR)
# Setup PYTHONPATH in bash activate script...
echo '' >> $(VIRTUALENV_DIR)/bin/activate
echo '_OLD_PYTHONPATH=$$PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate
echo 'PYTHONPATH=$$_OLD_PYTHONPATH:$(COMPONENT_PYTHONPATH)' >> $(VIRTUALENV_DIR)/bin/activate
echo 'export PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate
touch $(VIRTUALENV_DIR)/bin/activate
# Setup PYTHONPATH in fish activate script...
echo '' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'set -gx _OLD_PYTHONPATH $$PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'set -gx PYTHONPATH $$_OLD_PYTHONPATH $(COMPONENT_PYTHONPATH)' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'functions -c deactivate old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'function deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' if test -n $$_OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' set -gx PYTHONPATH $$_OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' set -e _OLD_PYTHONPATH' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' end' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo ' functions -e old_deactivate' >> $(VIRTUALENV_DIR)/bin/activate.fish
echo 'end' >> $(VIRTUALENV_DIR)/bin/activate.fish
touch $(VIRTUALENV_DIR)/bin/activate.fish
.PHONY: piptools
piptools: virtualenv
@echo
@echo "================== Install pip-tools ===================="
@echo
"$(VIRTUALENV_DIR)/bin/pip" install pip-tools
.PHONY: generate_requirements
generate_requirements: piptools
@echo
@echo "================== Generate requirements file ===================="
@echo
"$(VIRTUALENV_DIR)/bin/pip-compile" --output-file=$(ROOT_DIR)/test-requirements-$(PYTHON_VERSION).txt $(ROOT_DIR)/test-requirements.in