-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
97 lines (75 loc) · 3.28 KB
/
Makefile
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
# Makefile
PYTHON_EXE = python3
# PROJECT_NAME is used to create the virtualenv name
PROJECT_NAME="example-project"
TOPDIR = $(shell git rev-parse --show-toplevel)
# PYDIRS is where we look for python code that needs to be linted
PYDIRS="myproject"
VENV = venv_$(PROJECT_NAME)
VENV_BIN=$(VENV)/bin
SRC_FILES := $(shell find $(PYDIRS) -name \*.py)
SPHINX_DEPS := $(shell find docs/source)
GENERATED_DOC_SOURCES := $(shell find docs/source -maxdepth 1 -type f -name \*.rst -not -name index.rst)
help: ## Display help
@awk -F ':|##' \
'/^[^\t].+?:.*?##/ {\
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
}' $(MAKEFILE_LIST)
all: clean venv_$(PROJECT_NAME) check test dist ## Setup python-viptela env and run tests
venv: ## Creates the needed virtual environment.
test -d $(VENV) || virtualenv -p $(PYTHON_EXE) $(VENV) $(ARGS)
$(VENV): $(VENV_BIN)/activate ## Build virtual environment
$(VENV_BIN)/activate: requirements.txt test-requirements.txt
test -d $(VENV) || virtualenv -p $(PYTHON_EXE) $(VENV)
echo "export TOP_DIR=$(TOPDIR)" >> $(VENV_BIN)/activate
. $(VENV_BIN)/activate; pip install -U pip; pip install -r requirements.txt -r test-requirements.txt
deps: venv ## Installs the needed dependencies into the virtual environment.
$(VENV_BIN)/pip install -U pip
$(VENV_BIN)/pip install -r requirements.txt -r test-requirements.txt
dev: deps ## Installs python_viptela in develop mode.
$(VENV_BIN)/pip install -e ./
check-format: $(VENV)/bin/activate ## Check code format
@( \
set -eu pipefail ; set -x ;\
DIFF=`$(VENV)/bin/yapf --style=yapf.ini -d -r *.py $(PYDIRS)` ;\
if [ -n "$$DIFF" ] ;\
then \
echo -e "\nFormatting changes requested:\n" ;\
echo "$$DIFF" ;\
echo -e "\nRun 'make format' to automatically make changes.\n" ;\
exit 1 ;\
fi ;\
)
format: $(VENV_BIN)/activate ## Format code
$(VENV_BIN)/yapf --style=yapf.ini -i -r *.py $(PYDIRS)
pylint: $(VENV_BIN)/activate ## Run pylint
$(VENV_BIN)/pylint --output-format=parseable --rcfile .pylintrc *.py $(PYDIRS)
check: check-format pylint ## Check code format & lint
build: deps ## Builds EGG info and project documentation.
$(VENV_BIN)/python setup.py egg_info
dist: build ## Creates the distribution.
$(VENV_BIN)/python setup.py sdist --formats gztar
$(VENV_BIN)/python setup.py bdist_wheel
test: deps ## Run python-viptela tests
. $(VENV_BIN)/activate; pip install -U pip; pip install -r requirements.txt -r test-requirements.txt;tox -r
clean: ## Clean python-viptela $(VENV)
$(RM) -rf $(VENV)
$(RM) -rf docs/_build
$(RM) -rf dist
$(RM) -rf *.egg-info
$(RM) -rf *.eggs
$(RM) -rf docs/api/*
find . -name "*.pyc" -exec $(RM) -rf {} \;
clean-docs-html:
$(RM) -rf docs/build/html
clean-docs-markdown:
$(RM) -rf docs/build/markdown
docs: docs-markdown docs-html ## Generate documentation in HTML and Markdown
docs-markdown: clean-docs-markdown $(SPHINX_DEPS) $(VENV)/bin/activate ## Generate Markdown documentation
. $(VENV_BIN)/activate ; $(MAKE) -C docs markdown
docs-html: clean-docs-html $(SPHINX_DEPS) $(VENV)/bin/activate ## Generate HTML documentation
. $(VENV_BIN)/activate ; $(MAKE) -C docs html
docs-clean: ## Clean generated documentation
$(RM) $(GENERATED_DOC_SOURCES)
. $(VENV_BIN)/activate ; $(MAKE) -C docs clean
.PHONY: all clean $(VENV) test check format check-format pylint clean-docs-html clean-docs-markdown apidocs