summaryrefslogtreecommitdiff
path: root/dev.sh
blob: fb8ac0cd385d8d8c4f2c6d04d14c1ec8f935d1ac (plain)
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
#!/bin/sh

ECHO="`which echo` -e"

[ x$1 = x ] && $ECHO "\
Small script for running developement tools. 

Usage: $0 <command>

Commands:

dev        Install developement envoronment
run	   Run the app in developement environment
pytest     Run pytest unittests
pylint     Do pylint
covhtml    Make branch coverage report with coverage in html format
covff      Genarate and open html coverage report in firefox
all        Do it all: pytest, coverage report in firefox and pylint
install    Build PyPI package form source and install it
" && exit 0

# Ensure ~/.local/bin in the PATH.
echo $PATH | grep /.local/bin > /dev/null \
	|| export PATH="$HOME/.local/bin:$PATH"

PIP=`which pipx`
[ x$PIP = x ] && PIP=`which pip`
[ x$PIP = x ] \
	&& $ECHO "This scripts uses pipx or pip to install poetry and the build." \
	&& exit 1
	
export DEVSH_PRIN=">>$DEVSH_PRIN"
export DEVSH_PROUT="<<$DEVSH_PROUT"

$ECHO "\033[32m$DEVSH_PRIN $0 $1 - started...\033[0m"

case $1 in

	install-poetry)
		[ -e $HOME/.local/bin/poetry ] \
		|| $PIP install poetry
		;;

	install-latest-build)
		$PIP install `ls dist/*.tar.gz -t -c -1 | head -1` \
		&& $ECHO "For uninstall please use '$PIP uninstall ...'"
		;;

	poetry-dev-deps)
		PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring \
		poetry install
		;;
	
	dev)
		$0 install-poetry \
		&& $0 poetry-dev-deps
		;;

	run)
		DEBUG=1 poetry run sliceitoff
		;;

	pytest)
		poetry run pytest -v
		;;

	pylint)
		poetry run pylint src/
		;;

	coverage)
		poetry run coverage run -m pytest -v
		;;

	covhtml)
		$0 coverage \
		&& poetry run coverage html
		;;

	covff)
		$0 covhtml \
		&& firefox htmlcov/index.html
		;;

	all)	
		$0 covff \
		&& $0 pylint
		;;

	poetry-build)
		poetry build
		;;

	install)
		$0 install-poetry \
		&& $0 poetry-build \
		&& $0 install-latest-build
		;;

	*)	
		$ECHO "\033[31m$DEVSH_PROUT $0 $1 - unknown command.\033[0m"
		exit 1
		;;
esac

STATUS=$?

[ $STATUS != 0 ] \
	&& $ECHO "\033[31m$DEVSH_PROUT $0 $1 - exited with code $STATUS.\033[0m" \
	&& exit $STATUS
	
$ECHO "\033[32m$DEVSH_PROUT $0 $1 - done.\033[0m"