-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev.sh
executable file
·137 lines (126 loc) · 4.03 KB
/
dev.sh
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
NAME=starter_package
USER=hallamlab
HERE=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
DOCKER_IMAGE=quay.io/$USER/$NAME
VER=$(cat $HERE/src/$NAME/version.txt)
# CONDA=conda
CONDA=mamba # https://mamba.readthedocs.io/en/latest/mamba-installation.html#mamba-install
# this file contains a list of commands useful for dev,
# providing automation for some build tasks
#
# example workflow 1, pip:
# dev.sh --idev # create a local conda dev env
# # add pypi api token as file to ./secrets [https://pypi.org/help/#apitoken]
# # make some changes to source
# # bump up ./src/fabfos/version.txt
# dev.sh -bp # build the pip package
# dev.sh -up # test upload to testpypi
# dev.sh -upload-pypi # release to pypi index for pip install
#
# example workflow 2, conda:
# dev.sh --idev # create a local conda dev env
# dev.sh -bp # build the pip package
# dev.sh -bc # build conda package from pip package
# dev.sh -uc # publish to conda index
#
# example workflow 3, containerization:
# dev.sh --idev # create a local conda dev env
# dev.sh -bd # build docker image
# dev.sh -ud # publish to quay.io
# dev.sh -bs # build singularity image from local docker image
case $1 in
###################################################
# environments
--idev) # with dev tools for packaging
cd $HERE/envs
$CONDA env create --no-default-packages -n $NAME -f ./base.yml
$CONDA env update -n $NAME -f ./dev.yml
;;
--ibase) # base only
cd $HERE/envs
$CONDA env create --no-default-packages -n $NAME -f ./base.yml
;;
###################################################
# build
-bp) # pip
# build pip package
rm -r build
rm -r dist
python -m build
;;
-bpi) # pip - test install
python setup.py install
;;
-bpx) # pip - remove package
pip uninstall -y $NAME
;;
-bc) # conda
rm -r $HERE/conda_build
python ./conda_recipe/compile_recipe.py
$HERE/conda_recipe/call_build.sh
;;
-bd) # docker
echo image: $DOCKER_IMAGE:$VER
echo ""
docker build -t $DOCKER_IMAGE:$VER --build-arg PKG_NAME=${NAME} .
;;
-bs) # singularity image *from docker*
singularity build $NAME.sif docker-daemon://$DOCKER_IMAGE:$VER
;;
###################################################
# upload
-up) # pip (testpypi)
PYPI=testpypi
TOKEN=$(cat secrets/${PYPI}) # https://pypi.org/help/#apitoken
python -m twine upload --repository $PYPI dist/*.whl -u __token__ -p $TOKEN
;;
-upload-pypi) # pip (pypi)
echo "not all dependencies are available on pypi, so this is not a good idea if using conda..."
# PYPI=pypi
# TOKEN=$(cat secrets/${PYPI}) # https://pypi.org/help/#apitoken
# python -m twine upload --repository $PYPI dist/*.whl -u __token__ -p $TOKEN
;;
-uc) # conda (personal channel)
# run `anaconda login` first
find ./conda_build -name *.tar.bz2 | xargs -I % anaconda upload --user $USER %
;;
-ud) # docker
# login and push image to quay.io
# sudo docker login quay.io
docker push $DOCKER_IMAGE:$VER
echo "!!!"
echo "remember to update the \"latest\" tag"
echo "https://$DOCKER_IMAGE?tab=tags"
;;
###################################################
# run
-r)
shift
export PYTHONPATH=$HERE/src:$PYTHONPATH
python -m $NAME $@
;;
-rd) # docker
# -e XDG_CACHE_HOME="/ws"\
shift
docker run -it --rm \
-u $(id -u):$(id -g) \
--mount type=bind,source="$HERE",target="/ws"\
--workdir="/ws" \
$DOCKER_IMAGE:$VER /bin/bash
;;
-rs) # singularity
# -e XDG_CACHE_HOME="/ws"\
shift
singularity exec \
--bind ./:/ws \
--workdir /ws \
$HERE/$NAME.sif /bin/bash
;;
-rt) # single manual test
# --size 20 \
;;
*)
echo "bad option"
echo $1
;;
esac