Skip to content

Dingpf/python_venv #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bin/quick-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ TRACE_version=v3_15_09
folly_version=v2020_05_25
ers_version=v0_26_00c
ninja_version=v1_10_0
python_version=v3_8_3b

basedir=$PWD
builddir=$basedir/build
logdir=$basedir/log
srcdir=$basedir/sourcecode

dbt_version="develop"
dbt_version="dingpf/python-venv"

precloned_packages="daq-buildtools:${dbt_version}"

Expand Down Expand Up @@ -163,6 +164,8 @@ setup ers $ers_version -q ${gcc_version_qualifier}:prof
setup_returns=\$setup_returns"\$? "
setup nlohmann_json $nlohmann_json_version -q ${gcc_version_qualifier}:prof
setup_returns=\$setup_returns"\$? "
setup python $python_version
setup_returns=\$setup_returns"\$? "

setup ninja $ninja_version 2>/dev/null # Don't care if it fails
if [[ "\$?" != "0" ]]; then
Expand Down Expand Up @@ -533,6 +536,9 @@ else
exit 70
fi

setup_python_script="setup_python_venv"
ln -s "$srcdir/daq-buildtools/scripts/$setup_python_script" $basedir/$setup_python_script

endtime_d=$( date )
endtime_s=$( date +%s )

Expand Down
17 changes: 17 additions & 0 deletions scripts/pyvenv_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
anyconfig==0.9.11
attrs==20.2.0
click==7.1.2
et-xmlfile==1.0.1
fastjsonschema==2.14.5
jdcal==1.4.1
Jinja2==2.11.2
jsonnet==0.16.0
jsonpointer==2.0
jsonschema==3.2.0
MarkupSafe==1.1.1
numpy==1.19.4
openpyxl==3.0.5
pyrsistent==0.17.3
six==1.15.0
# Comment out moo, as by default PyPI's moo will be picked up.
# moo==0.2.0
Comment on lines +16 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to replace these lines with one like:

git+git://github.com/brettviren/[email protected]#egg=moo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I tried it in this commit 4ec2be3.

But it looks like pip was still checking the moo in PyPI. I got the error messages as the following:

  ERROR: Could not find a version that satisfies the requirement moo==git+https://github.com/brettviren/[email protected]#egg=moo (from -r pyvenv_requirements.txt (line 17)) (from versions: 0.1.0, 0.1.1, 0.1.2, 0.1.5, 0.1.7, 0.1.8, 0.2.0, 0.5.3, 0.5.4, 0.5.5)
  ERROR: No matching distribution found for moo==git+https://github.com/brettviren/[email protected]#egg=moo (from -r pyvenv_requirements.txt (line 17))      

97 changes: 97 additions & 0 deletions scripts/setup_python_venv
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

WORK_DIR=$PWD
timenow="date \"+%D %T\""

requirements_edit_overwrite=true

###
# Default virtual env name
###
VENV_NAME="moo_venv"

###
# Check if inside a virtualenv already
###
if [[ "$VIRTUAL_ENV" != "" ]]
then
echo "ERROR: [`eval $timenow`]: You are already in a virtual env. Please deactivate first."
exit 11
fi

###
# Check if python from cvmfs has been set up.
# Add version check in the future.
###
if [ -z "$SETUP_PYTHON" ]; then
echo "INFO [`eval $timenow`]: Python UPS product is not set, setting it from cvmfs now."
setup python
if [[ $? != "0" ]]; then
echo "ERROR [`eval $timenow`]: setup python failed, please check if you have sourced the \"setup_build_environment\" script and run this script again."
exit 10
fi
else
echo "INFO [`eval $timenow`]: Python UPS product $PYTHON_VERSION has been set up."
fi

###
# Check existance/create the default virtual_env
###
if [ -f "$WORK_DIR/$VENV_NAME/pyvenv.cfg" ]; then
echo "INFO [`eval $timenow`]: virtual_env $VENV_NAME already exists. "
cat "$WORK_DIR/$VENV_NAME/pyvenv.cfg"
else
echo "INFO [`eval $timenow`]: creating virtual_env $VENV_NAME. "
python -m venv $VENV_NAME
fi

###
# Activate the venv
###
echo "INFO [`eval $timenow`]: activating virtual_env $VENV_NAME. "
source $WORK_DIR/$VENV_NAME/bin/activate

###
# Install required modules except moo
###
if [ -f "$WORK_DIR/pyvenv_requirements.txt" ]; then
echo "INFO [`eval $timenow`]: found existing requirements file: $WORK_DIR/pyvenv_requirements.txt"
if [ $requirements_edit_overwrite ]; then
curl -o $WORK_DIR/.tmp_python_setup https://raw.githubusercontent.com/DUNE-DAQ/daq-buildtools/dingpf/python-venv/scripts/pyvenv_requirements.txt
diff_req=$(diff $WORK_DIR/.tmp_python_setup $WORK_DIR/pyvenv_requirements.txt)
if [[ -n $diff_req ]]; then
echo "INFO [`eval $timenow`]: Overwriting is turned on. The exisiting file will be moved to: $moved_req"
moved_req=$WORK_DIR/pyvenv_requirements.txt.`date "+%y%m%d%H%M%S"`
mv $WORK_DIR/pyvenv_requirements.txt $moved_req
mv $WORK_DIR/.tmp_python_setup $WORK_DIR/pyvenv_requirements.txt
else
rm -f $WORK_DIR/.tmp_python_setup
fi
fi
else
curl -O https://raw.githubusercontent.com/DUNE-DAQ/daq-buildtools/dingpf/python-venv/scripts/pyvenv_requirements.txt
fi
echo "INFO [`eval $timenow`]: checking/installing required modules for virtual_env $VENV_NAME. "
python -m pip install -r pyvenv_requirements.txt
if [[ $? != "0" ]]; then
echo "ERROR [`eval $timenow`]: Installing required modules failed."
exit 12
fi

###
# special handling of the moo module since PyPI has a module with same name.
###
if python -c "import moo" &> /dev/null; then
echo "INFO [`eval $timenow`]: moo is installed."
pip list|grep moo
else
echo "INFO [`eval $timenow`]: moo is not installed. Install it now."
pip install git+git://github.com/brettviren/moo.git
if [[ $? != "0" ]]; then
echo "ERROR [`eval $timenow`]: Installing moo failed."
exit 13
fi
fi


echo "INFO [`eval $timenow`]: $VEVN_NAME has been activated, use \"deactivate\" to exit the venv."