-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
214 lines (187 loc) · 7.83 KB
/
Makefile
File metadata and controls
214 lines (187 loc) · 7.83 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
DOCHOST ?= $(shell bash -c 'read -p "documentation host: " dochost; echo $$dochost')
export VERSION := $(shell hatch version )
# Makefile color codes...
# ref -> https://stackoverflow.com/a/5947802/667301
COL_GREEN=\033[0;32m
COL_CYAN=\033[0;36m
COL_YELLOW=\033[0;33m
COL_RED=\033[0;31m
COL_END=\033[0;0m
.DEFAULT_GOAL := test
# Ref -> https://stackoverflow.com/a/26737258/667301
# Ref -> https://packaging.python.org/en/latest/guides/making-a-pypi-friendly-readme/
.PHONY: dep
dep:
@echo "$(COL_GREEN)>> getting ciscoconfparse2 pypi artifacts (wheel and tar.gz)$(COL_END)"
pip install -U pip
# Delete bogus files... see https://stackoverflow.com/a/73992288/667301
perl -e 'unlink( grep { /^\W\d*\.*\d*/ && !-d } glob( "*" ) );'
.PHONY: build
build:
# Build a new wheel / src_dist from scratch
-rm -rf dist/
hatch build
.PHONY: install_build
install_build:
make build
# Install the newly-built package
pip install --force-reinstall dist/*.tar.gz
.PHONY: cicd
cicd:
@echo "$(COL_CYAN)>> Use CI/CD to publish ciscoconfparse2 pypi artifacts$(COL_END)"
make clean
-git commit --all -m "chore: commit changes I forgot before running 'make cicd'"
# yamlfix doesn't understand pyproject.toml config
# if used in pre-commit...
yamlfix .github/workflows/
-git commit --all -m "chore: yamlfix changes"
# Run pre-commit on all files... ignore failures, which should be auto-fixed
-pre-commit run -a
-git commit --all -m "chore: pre-commit changes"
make dep
-git commit --all -m "Version $$VERSION"
# tag the repo with $$VERSION, upon git tag push,
# this triggers .github/workflows/cicd-publish.yml
-git tag $$VERSION
git checkout main
git merge @{-1} # Merge the previous branch
git push origin main
# push tag to github origin, which triggers a github CICD action (see above)
-git push origin $$VERSION
git checkout @{-1} # checkout the previous branch...
git pull origin main
.PHONY: repo-push
repo-push:
@echo "$(COL_GREEN)>> git push and merge (w/o force) to ciscoconfparse2 main branch to github$(COL_END)"
make ping
-git checkout master || git checkout main # Add dash to ignore checkout fails
# Now the main branch is checked out...
THIS_BRANCH=$(shell git branch --show-current) # assign 'main' to $THIS_BRANCH
git merge @{-1} # merge the previous branch into main...
git push origin $(THIS_BRANCH) # git push to origin / $THIS_BRANCH
git checkout @{-1} # checkout the previous branch...
.PHONY: repo-push-force
repo-push-force:
@echo "$(COL_GREEN)>> git push and merge (w/ force) ciscoconfparse2 local main branch to github$(COL_END)"
make ping
-git checkout master || git checkout main # Add dash to ignore checkout fails
# Now the main branch is checked out...
THIS_BRANCH=$(shell git branch --show-current) # assign 'main' to $THIS_BRANCH
git merge @{-1} # merge the previous branch into main...
git push --force-with-lease origin $(THIS_BRANCH) # force push to origin / $THIS_BRANCH
git checkout @{-1} # checkout the previous branch...
.PHONY: repo-push-tag
repo-push-tag:
@echo "$(COL_GREEN)>> git push (w/ local tag) ciscoconfparse2 local main branch to github$(COL_END)"
git push origin +main
git push --tags origin +main
.PHONY: repo-push-tag-force
repo-push-tag-force:
@echo "$(COL_GREEN)>> git push (w/ local tag and w/ force) ciscoconfparse2 local main branch to github$(COL_END)"
git push --force-with-lease origin +main
git push --force-with-lease --tags origin +main
.PHONY: pylama
pylama:
@echo "$(COL_GREEN)>> running pylama against ciscoconfparse2$(COL_END)"
# Good usability info here -> https://pythonspeed.com/articles/pylint/
pylama --ignore=E501,E301,E265,E266,W503 ciscoconfparse2/*py | less -XR
.PHONY: pylint
pylint:
@echo "$(COL_GREEN)>> running pylint against ciscoconfparse2$(COL_END)"
# Good usability info here -> https://pythonspeed.com/articles/pylint/
pylint --rcfile=./utils/pylintrc --ignore-patterns='^build|^dist|utils/pylintrc|README.rst|CHANGES|LICENSE|MANIFEST.in|Makefile|TODO' --output-format=colorized * | less -XR
.PHONY: tutorial
tutorial:
@echo ">> building the ciscoconfparse2 tutorial"
rst2html5 --jquery --reveal-js --pretty-print-code --embed-stylesheet --embed-content --embed-images tutorial/ccp_tutorial.rst > tutorial/ccp_tutorial.html
.PHONY: flake
flake:
flake8 --ignore E501,E226,E225,E221,E303,E302,E265,E128,E125,E124,E41,W291 --max-complexity 10 ciscoconfparse2 | less
.PHONY: ty
ty:
uvx ty check --color always | less -R
.PHONY: ruff
ruff:
uvx ruff check --color always | less -R
.PHONY: coverage-pytest
coverage-pytest:
@echo "[[[ py.test Coverage ]]]"
cd tests;py.test --cov-report term-missing --cov=ciscoconfparse2.py -s -v
.PHONY: pydocstyle
pydocstyle:
# Run a numpy-style doc checker against all files matching ciscoconfparse2/*py
find ciscoconfparse2/*py | xargs -I{} pydocstyle --convention=numpy {}
.PHONY: doctest
doctest:
# Run the doc tests
cd sphinx-doc; make doctest
.PHONY: rm-timestamp
rm-timestamp:
@echo "$(COL_GREEN)>> delete .pip_dependency if older than a day$(COL_END)"
#delete .pip_dependency if older than a day
$(shell find .pip_dependency -mtime +1 -exec rm {} \;)
.PHONY: timestamp
timestamp:
@echo "$(COL_GREEN)>> Create .pip_dependency$(COL_END)"
$(shell touch .pip_dependency)
.PHONY: test
test:
@echo "$(COL_GREEN)>> running unit tests$(COL_END)"
$(shell touch .pip_dependency)
make timestamp
make clean
# You can also test with verbose output:
# cd tests && pytest -vvs ./test_*py
cd tests && pytest ./test_*py
.PHONY: coverage
coverage:
@echo "$(COL_GREEN)>> running unit tests$(COL_END)"
$(shell touch .pip_dependency)
make timestamp
#make ping
make clean
# run tests with coverage (ensure you run 'make dep' before)
cd tests && coverage run -m pytest test*py
# Move the coverage file to the base git directory
cd tests && mv .coverage ../
.PHONY: clean
clean:
@echo "$(COL_GREEN)>> cleaning the repo$(COL_END)"
# Delete bogus files... see https://stackoverflow.com/a/73992288/667301
perl -e 'unlink( grep { /^=\d*\.*\d*/ && !-d } glob( "*" ) );'
find ./* -name '*.pyc' -exec rm {} \;
find ./* -name '*.so' -exec rm {} \;
find ./* -name '*.coverage' -exec rm {} \;
find ./* -name '*.cover' -exec rm {} \;
-find ./* -name '.pytest_cache' -exec rm -rf {} \;
@# A minus sign prefixing the line means it ignores the return value
-find ./* -path '*__pycache__' -exec rm -rf {} \;
@# remove all the MockSSH keys
-find ./* -name '*.key' -exec rm {} \;
-rm .pip_dependency
-rm -rf .mypy_cache/
-rm -rf .pytest_cache/
-rm -rf .eggs/
-rm -rf .cache/
-rm -rf sphinx-doc/_build
-rm -rf build/ dist/ ciscoconfparse2.egg-info/ setuptools*
-rm -rf artifacts/
.PHONY: help
help:
@# An @ sign prevents outputting the command itself to stdout
@echo "help : You figured that out ;-)"
@echo "cicd : Git commit, build the project w/ CICD, and push to pypi"
@echo "repo-push : Build the project and push to github"
@echo "test : Run all doctests and unit tests"
@echo "dev : Get all dependencies for the dev environment"
@echo "dep : Get all prod dependencies"
@echo "devtest : Run tests - Specific to Mike Pennington's build env"
@echo "coverage : Run tests with coverage - Specific to this build env"
@echo "flake : Run PyFlake code audit w/ McCabe complexity"
@echo "clean : Housecleaning"
@echo "parse-ios : Parse configs/sample_01.ios with default args"
@echo "parse-ios-factory : Parse configs/sample_01.ios with factory=True"
@echo "parse-iosxr-banner : Parse an interesting IOSXR banner"
@echo "perf-acl : cProfile configs/sample_05.ios (100 acls)"
@echo "perf-factory-intf : cProfile configs/sample_06.ios (many intfs, factory=True)"
@echo ""