forked from Deep-MI/FastSurfer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_pip-r.sh
77 lines (67 loc) · 2.08 KB
/
export_pip-r.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
#!/bin/bash
# Copyright 2023 Image Analysis Lab, German Center for Neurodegenerative Diseases (DZNE), Bonn
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function usage()
{
cat <<EOF
export_pip-r.sh <requirements file> <docker image/singularity image file>
Will generate requirements files from docker/singularity images to distribute with
the FastSurfer repository.
examples:
export_pip-r.sh $FASTSURFER_HOME/requirements.txt fastsurfer:dev
export_pip-r.sh $FASTSURFER_HOME/requirements_cpu.txt fastsurfer:dev
Created 26-11-2023, David Kügler, Image Analysis Lab,
German Center for Neurodegenerative Diseases (DZNE), Bonn
EOF
}
if [ "$#" != 2 ]
then
echo "This scripts expects 2 parameters, got $#"
exit 1
fi
echo "Exporting versions from $2..."
{
echo "#"
echo "# This file is autogenerated by $USER from $2"
echo "# by the following command from FastSurfer:"
echo "#"
echo "# $*"
echo "#"
} > $1
pip_cmd="python --version && pip list --format=freeze --no-color --all --disable-pip-version-check --no-input"
if [ "${2/#.sif}" != "$2" ]
then
# singularity
cmd="singularity exec $2 /bin/bash -c '$pip_cmd'"
else
# docker
cmd="docker run --entrypoint /bin/bash $2 -c '$pip_cmd'"
fi
{
echo "# Which ran the following command:"
echo "# $cmd"
echo "#"
} >> $1
out=$($cmd)
hardware=$(echo "$out" | grep "torch==" | cut -d"+" -f2)
pyversion=$(echo "$out" | head -n 1 | cut -d" " -f2)
{
echo "#"
echo "# Image was configured for $hardware using python version $pyversion"
echo "#"
echo "--extra-index-url https://download.pytorch.org/whl/$hardware"
echo ""
echo "# $out"
} >> $1
}