forked from ciscops/meraki-netbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (98 loc) · 4.19 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
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
# Makefile
PYTHON_EXE = python3
PROJECT_NAME="meraki-netbox"
TOPDIR = $(shell git rev-parse --show-toplevel)
PYDIRS="meraki_netbox"
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)
NON_PYTHON_LIBS := $(shell ls | grep -v $(PYDIRS))
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: $(VENV_BIN)/activate
$(VENV): $(VENV_BIN)/activate ## Build virtual environment
$(VENV_BIN)/activate: requirements.txt test-requirements.txt
test -d $(VENV) || $(PYTHON_EXE) -m venv $(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 {} \;
$(RM) -rf lambda-packages
$(RM) lambda-packages.zip
$(RM) lambda-function.zip
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
clean-lambda:
$(RM) -rf lambda-packages
$(RM) lambda-packages.zip
$(RM) lambda-function.zip
lambda-packages: requirements.txt ## Install all libraries
@[ -d $@ ] || mkdir -p $@/python # Create the libs dir if it doesn't exist
pip install -r $< -t $@/python # We use -t to specify the destination of the
# packages, so that it doesn't install in your virtual env by default
lambda-packages.zip: lambda-packages ## Output all code to zip file
cd lambda-packages && zip -r ../$@ * # zip all python source code into output.zip
lambda-layer: lambda-packages.zip
aws lambda publish-layer-version \
--layer-name $(PROJECT_NAME)-layer \
--license-info "MIT" \
--zip-file fileb://$< \
--compatible-runtimes python3.8
lambda-function.zip: ## Output all code to zip file
zip -r $@ lambda_function.py $(PYDIRS) # zip all python source code into output.zip
lambda-deploy: lambda-function.zip ## Deploy all code to aws
aws lambda update-function-code \
--function-name $(PROJECT_NAME) \
--zip-file fileb://$<
.PHONY: all clean $(VENV) test check format check-format pylint clean-docs-html clean-docs-markdown apidocs