forked from idaholab/moose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diagnostic_environment.sh
176 lines (165 loc) · 6.33 KB
/
diagnostic_environment.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
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
#!/bin/bash
function compiler_test()
{
print_sep
printf "Compiler(s) (CC CXX FC F77 F90 F95):\n\n"
local compiler_array=(CC CXX FC F77 F90 F95)
local error_cnt=0
for compiler in ${compiler_array[@]}; do
if ! [[ "x${!compiler}" == "x" ]]; then
printf "${compiler}=$(which ${!compiler} 2>/dev/null \
|| printf "${compiler}=${!compiler}\tnot found")\n"
if [[ $(basename ${!compiler} | grep -c '^mpi') -ge 1 ]]; then
printf "${compiler} -show:\n$(${!compiler} -show)\n"
fi
printf "${compiler} version:\t$(which ${!compiler} &>/dev/null \
&& ${!compiler} --version | head -1)\n\n"
else
printf "${compiler}\t\tnot set\n"
let error_cnt+=1
fi
done
if [[ $error_cnt -ge 1 ]]; then
print_red "\nFAIL: "
printf "One or more compiler variables not set\n"
return 1
else
print_green "OK\n"
fi
return 0
}
function env_test()
{
print_sep
printf "Influential Environment Variables\n\n"
reg_exp='^LD\|^DYLD\|^PATH\|^CFLAGS\|^CPP\|^CC\|^CXX\|^FFLAGS\|^FC\|^F90\|^F95\|^F77\|^CONDA'
reg_exp+='\|^HDF5\|^MOOSE\|^PETSC\|^LIBMESH\|^WASP\|^APPTAINER\|^MODULES'
reg_not='CONDA_BACKUP'
env | sort | grep "${reg_exp}" | grep -v "${reg_not}"
}
function python_test()
{
print_sep
printf "Python Sanity Checks\n\n"
my_version="$(/usr/bin/env python3 --version || printf 'NONE')"
if [[ "${my_version}" != 'NONE' ]]; then
printf "Verify \`/usr/bin/env python3 --version\` (reporting as: ${my_version}),
matches versions for: \`which python3 && which python\`\n\n"
which_pythons=('python3' 'python')
local error_cnt=0
for which_python in "${which_pythons[@]}"; do
local my_python=$(which ${which_python})
if [[ -n ${my_python} ]] && [[ "$(${my_python} --version)" != "${my_version}" ]]; then
print_red "FAIL: "
printf "${my_python} --version (reporting as $(${my_python} --version)) != ${my_version}\n"
let error_cnt+=1
elif [[ -z "${my_python}" ]]; then
print_orange "\nWARNING: "
printf "\`${which_python}\` does not exist\n"
printf "This does not mean there will be a failure, but some shebangs in some python
files may still be relying on calling: \`/usr/bin/env ${which_python}\` (Python 2.x era)\n"
fi
done
else
printf "\`python3\` not found\n\n"
let error_cnt+=1
fi
if [[ $error_cnt -ge 1 ]]; then
printf "\nThis will likely result in the TestHarness failing. Or WASP/HIT parsing errors.\n"
return 1
else
print_green "OK\n"
fi
return 0
}
function _python_modules()
{
print_sep
printf "Python Modules (TestHarness, runnability)\n\n"
check_modules=(packaging yaml pyaml jinja2)
local error_cnt=0
for check_module in "${check_modules[@]}"; do
/usr/bin/env python3 -c "import ${check_module}" 2>/dev/null
if [[ $? -ge 1 ]]; then
print_red "FAIL: "
printf "python module: \`${check_module}\` not available\n"
let error_cnt+=1
fi
done
if [[ $error_cnt -ge 1 ]]; then
printf "\nSome Python modules are not available. Numerous miscellaneous issues may
persist without these packages present. Either install these packages, or
perhaps you have yet to \`conda activate moose\`.\n"
return 1
else
print_green "OK\n"
fi
return 0
}
function conda_test()
{
# First run our python_modules test. We need yaml in order to run conda_test.
_python_modules
modules_test=$?
print_sep
printf "CONDA MOOSE Packages\n\n"
if [[ $modules_test -ge 1 ]]; then
print_orange "WARNING: "
printf "Unable to run Conda tests due to missing Python modules\n\n"
return 1
fi
if [[ -n "${CONDA_PREFIX}" ]] && [[ -n "${MOOSE_NO_CODESIGN}" ]]; then
# right to left dependency
moose_packages=(dev wasp libmesh petsc)
conda_list=`conda list | grep 'moose-'`
# iterate over and break on the top-most level we find installed
for package in ${moose_packages[@]}; do
my_version=$(echo -e "${conda_list}" | grep "^moose-${package} " | awk '{print $2}')
if [ -n "$my_version" ]; then
# hack naming conventions
if [[ ${package} == 'dev' ]]; then prefix='moose-'; fi
local needs_version=(`./versioner.py "${prefix}${package}" --yaml 2>/dev/null| \
grep 'install:' | \
awk 'BEGIN { FS = "=" }; {print $2" "$3}'`)
if [[ ${package} != 'dev' ]]; then
reminder='moose-dev\t\t Not present. Careful attention needed\n\t\t\t when keep everything in sync.'
fi
break
fi
done
echo -e "${conda_list}"
if [ -n "${reminder}" ]; then print_orange "${reminder}\n"; fi
if [[ -n "${my_version}" ]] && [[ "${my_version}" != "${needs_version}" ]]; then
print_red "\nFAIL: "
printf "${prefix}${package}/repository version mismatch\n"
printf "\nYour MOOSE repository requires moose-${package}:\t$(print_green ${needs_version})
while your Conda environment has moose-${package}:\t$(print_red ${my_version})
There are two ways to fix this:
1. To install the required Conda package version:
\tconda install moose-${package}=${needs_version}
2. Or adjust your repository to be in sync with moose-${package} Conda package.\n\n"
return 1
elif [[ -n "${my_version}" ]]; then
print_green "\nOK:"
printf " Conda packages and MOOSE repo/submodule versions match\n\n"
else
printf "\nConda MOOSE packages not applicative.
User is required to manually build PETSc, libMesh, and/or WASP\n\n"
fi
else
print_orange "\nWARNING: "
printf "Not using Conda MOOSE packages, or \`conda activate moose\` not
performed\n\n"
fi
return 0
}
function print_environment()
{
if [ "${NO_ENVIRONMENT}" == 1 ]; then return; fi
local ERR_CNT=0
env_test
compiler_test || let ERR_CNT+=1
python_test || let ERR_CNT+=1
conda_test || let ERR_CNT+=1
exit $ERR_CNT
}