Skip to content

Commit c1a721f

Browse files
authored
Merge pull request #51 from DUNE-DAQ/dingpf/python-venv
Dingpf/python_venv
2 parents add1980 + f34de8a commit c1a721f

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

Diff for: bin/quick-start.sh

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ TRACE_version=v3_15_09
2929
folly_version=v2020_05_25
3030
ers_version=v0_26_00c
3131
ninja_version=v1_10_0
32+
python_version=v3_8_3b
3233

3334
basedir=$PWD
3435
builddir=$basedir/build
@@ -163,6 +164,8 @@ setup ers $ers_version -q ${gcc_version_qualifier}:prof
163164
setup_returns=\$setup_returns"\$? "
164165
setup nlohmann_json $nlohmann_json_version -q ${gcc_version_qualifier}:prof
165166
setup_returns=\$setup_returns"\$? "
167+
setup python $python_version
168+
setup_returns=\$setup_returns"\$? "
166169
167170
setup ninja $ninja_version 2>/dev/null # Don't care if it fails
168171
if [[ "\$?" != "0" ]]; then
@@ -533,6 +536,9 @@ else
533536
exit 70
534537
fi
535538

539+
setup_python_script="setup_python_venv"
540+
ln -s "$srcdir/daq-buildtools/scripts/$setup_python_script" $basedir/$setup_python_script
541+
536542
endtime_d=$( date )
537543
endtime_s=$( date +%s )
538544

Diff for: scripts/pyvenv_requirements.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
anyconfig==0.9.11
2+
attrs==20.2.0
3+
click==7.1.2
4+
et-xmlfile==1.0.1
5+
fastjsonschema==2.14.5
6+
jdcal==1.4.1
7+
Jinja2==2.11.2
8+
jsonnet==0.16.0
9+
jsonpointer==2.0
10+
jsonschema==3.2.0
11+
MarkupSafe==1.1.1
12+
numpy==1.19.4
13+
openpyxl==3.0.5
14+
pyrsistent==0.17.3
15+
six==1.15.0
16+
# Comment out moo, as by default PyPI's moo will be picked up.
17+
# moo==0.2.0
18+
# moo==git+git://github.com/brettviren/[email protected]#egg=moo

Diff for: scripts/setup_python_venv

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
3+
WORK_DIR=$PWD
4+
timenow="date \"+%D %T\""
5+
6+
requirements_edit_overwrite=true
7+
8+
###
9+
# Default virtual env name
10+
###
11+
VENV_NAME="moo_venv"
12+
13+
###
14+
# Check if inside a virtualenv already
15+
###
16+
if [[ "$VIRTUAL_ENV" != "" ]]
17+
then
18+
echo "ERROR: [`eval $timenow`]: You are already in a virtual env. Please deactivate first."
19+
return 11
20+
fi
21+
22+
###
23+
# Check if python from cvmfs has been set up.
24+
# Add version check in the future.
25+
###
26+
if [ -z "$SETUP_PYTHON" ]; then
27+
echo "INFO [`eval $timenow`]: Python UPS product is not set, setting it from cvmfs now."
28+
setup python
29+
if [[ $? != "0" ]]; then
30+
echo "ERROR [`eval $timenow`]: setup python failed, please check if you have sourced the \"setup_build_environment\" script and run this script again."
31+
return 10
32+
fi
33+
else
34+
echo "INFO [`eval $timenow`]: Python UPS product $PYTHON_VERSION has been set up."
35+
fi
36+
37+
###
38+
# Check existance/create the default virtual_env
39+
###
40+
if [ -f "$WORK_DIR/$VENV_NAME/pyvenv.cfg" ]; then
41+
echo "INFO [`eval $timenow`]: virtual_env $VENV_NAME already exists. "
42+
cat "$WORK_DIR/$VENV_NAME/pyvenv.cfg"
43+
else
44+
echo "INFO [`eval $timenow`]: creating virtual_env $VENV_NAME. "
45+
python -m venv $VENV_NAME
46+
fi
47+
48+
###
49+
# Activate the venv
50+
###
51+
echo "INFO [`eval $timenow`]: activating virtual_env $VENV_NAME. "
52+
source $WORK_DIR/$VENV_NAME/bin/activate
53+
54+
###
55+
# Install required modules except moo
56+
###
57+
if [ -f "$WORK_DIR/pyvenv_requirements.txt" ]; then
58+
echo "INFO [`eval $timenow`]: found existing requirements file: $WORK_DIR/pyvenv_requirements.txt"
59+
if $requirements_edit_overwrite; then
60+
curl -o $WORK_DIR/.tmp_python_setup https://raw.githubusercontent.com/DUNE-DAQ/daq-buildtools/dingpf/python-venv/scripts/pyvenv_requirements.txt
61+
diff_req=$(diff $WORK_DIR/.tmp_python_setup $WORK_DIR/pyvenv_requirements.txt)
62+
if [[ -n $diff_req ]]; then
63+
echo "INFO [`eval $timenow`]: Overwriting is turned on. The exisiting file will be moved to: $moved_req"
64+
moved_req=$WORK_DIR/pyvenv_requirements.txt.`date "+%y%m%d%H%M%S"`
65+
mv $WORK_DIR/pyvenv_requirements.txt $moved_req
66+
mv $WORK_DIR/.tmp_python_setup $WORK_DIR/pyvenv_requirements.txt
67+
else
68+
rm -f $WORK_DIR/.tmp_python_setup
69+
fi
70+
fi
71+
else
72+
curl -O https://raw.githubusercontent.com/DUNE-DAQ/daq-buildtools/dingpf/python-venv/scripts/pyvenv_requirements.txt
73+
fi
74+
echo "INFO [`eval $timenow`]: checking/installing required modules for virtual_env $VENV_NAME. "
75+
python -m pip install -r pyvenv_requirements.txt
76+
if [[ $? != "0" ]]; then
77+
echo "ERROR [`eval $timenow`]: Installing required modules failed."
78+
return 12
79+
fi
80+
81+
###
82+
# special handling of the moo module since PyPI has a module with same name.
83+
##
84+
if python -c "import moo" &> /dev/null; then
85+
echo "INFO [`eval $timenow`]: moo is installed."
86+
pip list|grep moo
87+
else
88+
echo "INFO [`eval $timenow`]: moo is not installed. Install it now."
89+
pip install git+git://github.com/brettviren/moo.git
90+
if [[ $? != "0" ]]; then
91+
echo "ERROR [`eval $timenow`]: Installing moo failed."
92+
return 13
93+
fi
94+
fi
95+
96+
97+
echo "INFO [`eval $timenow`]: $VEVN_NAME has been activated, use \"deactivate\" to exit the venv."

0 commit comments

Comments
 (0)