-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.yaml
299 lines (299 loc) · 11 KB
/
Makefile.yaml
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
- hosts: local
vars:
app_dir: ansible_taskrunner
conda_environment_name: py3.10-ansible
lib_dir_name: libs
lib_dir: ${app_dir}/${lib_dir_name}
zip_release_dir: build/zip-release
cli_provider: bash
plugins_dir: ${app_dir}/plugins
pandoc_template_dir: ${HOME}/.pandoc/templates
python_versions:
- py3.10
workdir: ${PWD}
commands:
pypi:
options:
pypi_username:
help: "Specify the username for authenticating against pypi.org"
short: -U
long: --pypi-username
var: pypi_username
prompt: True
pypi_password:
help: "Specify the password for authenticating against pypi.org"
short: -P
long: --pypi-password
var: pypi_password
secure: True
prompt: True
pypi_repourl:
help: "Specify an alternate pypi URL"
short: -R
long: --pypi-repo-url
var: pypi_repourl
secure: True
prompt: True
required: False
replace_exe:
help: "Replace exe (used with build)"
long: --replace-exe
var: REPLACE_EXE
is_flag: True
build_zip:
help: "Invoke the 'zipapp' shell function"
short: -bz
var: zipapp
is_flag: true
release:
help: "Release to pypi"
short: -release
var: pypi_release
is_flag: true
clean:
help: "Clean build artifacts"
short: -clean
var: clean
is_flag: True
help:
message: |
Task Runner for the Task Runner!
examples:
- Build Python Module and Push to PyPi: |-
python ansible_taskrunner/cli.py -f Makefile.yaml pypi run ---make pypi -U $username -P $password
functions:
clean:
shell: bash
help: Remove all build, test, coverage and Python artifacts
source: |-
echo Cleaning up build, pyc, and test artifacts ...
clean-build
clean-pyc
clean-test
echo 'Done!'
clean-test:
shell: bash
help: Remove test and coverage artifacts
source: |-
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache
clean-pyc:
shell: bash
help: Remove Python file artifacts
source: |-
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
clean-build:
shell: bash
help: Remove build artifacts
source: |-
rm -rf build/
rm -rf dist/
rm -rf .eggs/
rm -rf ${app_dir}/{build,dist,.eggs}
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +
browser:
shell: python
source: |-
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
coverage:
shell: bash
help: Check code coverage quickly with the default Python
source: |-
coverage run --source ansible_taskrunner setup.py test
coverage report -m
coverage html
browser docs/_build/html/index.html
docs:
shell: bash
help: Generate Sphinx HTML documentation, including API docs
source: |-
rm -f docs/ansible_taskrunner.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ ansible_taskrunner
browser docs/_build/html/index.html
test-quick:
shell: bash
help: Run tests quickly with the default Python
source: |-
tox
test-all:
shell: bash
source: |-
python setup.py test
pypi_release:
shell: bash
help: Calls dist and release shell functions
source: |-
dist && release
dist:
shell: bash
help: Builds source and wheel package
source: |-
python setup.py sdist
python setup.py bdist_wheel
release:
shell: bash
help: Package and upload a release
source: |-
if [[ (-n $pypi_username) && (-n pypi_password) ]];then
echo ok
exit
if [[ -n $pypi_repourl ]];then
twine upload --repository-url ${pypi_repourl} dist/* -u ${username} -p ${password}
else
twine upload dist/* -u ${pypi_username} -p ${pypi_password}
fi
else
twine upload dist/*
fi
install:
shell: bash
help: Install the package to the active Python's site-packages
source: |-
python setup.py install
lint:
shell: bash
help: Check style with flake8
source: |-
flake8 ansible_taskrunner tests
check_exe:
shell: bash
hidden: true
source: |-
if ! [[ ($(type /usr/{,local/}{,s}bin/${1} 2> /dev/null)) || ($(which ${1})) ]];then
echo "This function requires ${1}, see installation instructions: ${2}"
return 1
fi
init_libs:
shell: bash
hidden: true
source: |-
echo '!!!Caveate emptor!!!'
echo -e '''Make sure of the following
- That your virtual python environments match the version of the python interpreter you intend to use!
'''
echo Checking for embedded library directories ...
for pyver in $python_versions;do
if ! test -d ${lib_dir_name}/${pyver};then
echo ${lib_dir_name}/${pyver} not found, creating ...
mkdir ${lib_dir_name}/${pyver}
if ! $(conda info --envs | grep -v '^#' | awk '{print $1}' | grep -q $pyver);then
echo Python environment $pyver not found, creating ...
conda_env_create ${pyver} ${pyver: -1}
fi
echo Activating python virtual environment $pyver ...
source activate $pyver
echo Installing modules to embedded library folder ${lib_dir_name}/${pyver} ...
pip install -t ${lib_dir_name}/${pyver} -r ${workdir}/requirements.txt
fi
done
make_zip_release:
shell: bash
hidden: true
source: |-
source activate $conda_environment_name
if ! test -d ${__release_dir};then mkdir -p ${__release_dir};fi
mv -f tasks ${__release_dir}
if [[ -n $REPLACE_EXE ]];then
echo "Replacing current executable: $(which tasks)"
pip install -U .
fi
make_zip:
shell: bash
hidden: true
source: |-
if [[ "$OSTYPE" =~ .*msys.* ]];then
echo "OSType is Windows, nesting libdir ..."
if test -d windows;then
rm -rf windows
mkdir windows
else
mkdir windows
fi
cp -r ${lib_dir_name} plugins windows
echo "Creating zip-app"
make-zipapp -f cli.py -X __pycache__ -x .pyc -d windows
if test -d windows;then rm -rf windows;fi
else
echo "OSType is most likely POSIX native"
echo "Creating zip-app"
make-zipapp -f cli.py -X __pycache__ -x .pyc
fi
conda_env_create:
shell: bash
hidden: true
source: |-
if [ $# -lt 1 ]; then
echo "Usage: ${FUNCNAME[0]} <virtualenv_name> [python_version](optional)";
return 1
fi
environment=$1
ver=${2-2.7}
conda create --name ${environment} python=$ver
msi:
shell: bash
help: Build msi
source: |-
set -o errexit
echo Checking for pandoc ...
if ! check_exe pandoc https://pandoc.org/installing.html;then
return 1
fi
if ! test -d ${pandoc_template_dir};then
mkdir -p ${pandoc_template_dir}
git clone https://github.com/ryangrose/easy-pandoc-templates ${pandoc_template_dir}
fi
if ! test -d ${app_dir}/dist;then mkdir ${app_dir}/dist;fi
if ! test -d ${app_dir}/build;then mkdir ${app_dir}/build;fi
pandoc README.md -f markdown -o ansible_taskrunner/build/README.html --template=${pandoc_template_dir}/html/easy_template.html --toc
cd ${app_dir}
python setup.cx_freeze.py bdist_msi
tests:
shell: bash
help: Build self-contained zip-app
source: |-
python tests/test_ansible_taskrunner.py
zipapp:
shell: bash
help: Build self-contained zip-app
source: |-
set -o errexit
cd ${app_dir}
echo Checking for conda ...
if ! check_exe conda https://www.continuum.io/downloads;then
return 1
fi
echo Checking for make-zipapp ...
if ! check_exe make-zipapp https://github.com/berttejeda/make-zipapp;then
return 1
fi
init_libs
__version=$(grep 'version: ' ${workdir}/setup.cfg | cut -d\ -f2)
echo "Version is ${__version}"
__release_dir=${zip_release_dir}/${__version}
lint_result=$(python cli.py --help)
echo "Initial lint OK, proceeding with build"
make_zip
mv cli tasks
lint_result=$(./tasks --help)
echo "Initial lint OK, proceeding with zipapp release"
make_zip_release
echo "Cleaning up"
rm -rf ${lib_dir_name}/py{2,3}
if [[ -n $deployment_host_and_path ]];then
echo "Pushing up"
scp_result=$(scp ${__release_dir}/tasks ${deployment_host_and_path})
fi
...