2013-08-13 23:14:01 +02:00
|
|
|
#!/usr/bin/env fish
|
2013-08-14 23:52:37 +02:00
|
|
|
# usage: . ./hacking/env-setup [-q]
|
2013-08-13 23:14:01 +02:00
|
|
|
# modifies environment for running Ansible from checkout
|
|
|
|
set HACKING_DIR (dirname (status -f))
|
|
|
|
set FULL_PATH (python -c "import os; print(os.path.realpath('$HACKING_DIR'))")
|
|
|
|
set ANSIBLE_HOME (dirname $FULL_PATH)
|
2016-10-24 19:35:00 +02:00
|
|
|
set PREFIX_PYTHONPATH $ANSIBLE_HOME/lib
|
2018-09-20 02:58:55 +02:00
|
|
|
set PREFIX_PATH $ANSIBLE_HOME/bin
|
2013-08-13 23:14:01 +02:00
|
|
|
set PREFIX_MANPATH $ANSIBLE_HOME/docs/man
|
|
|
|
|
2016-04-27 20:34:51 +02:00
|
|
|
# set quiet flag
|
2016-10-24 19:35:00 +02:00
|
|
|
if test (count $argv) -ge 1
|
2016-04-27 20:34:51 +02:00
|
|
|
switch $argv
|
2016-10-24 19:35:00 +02:00
|
|
|
case '-q' '--quiet'
|
|
|
|
set QUIET "true"
|
|
|
|
case '*'
|
2016-04-27 20:34:51 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-13 23:14:01 +02:00
|
|
|
# Set PYTHONPATH
|
|
|
|
if not set -q PYTHONPATH
|
|
|
|
set -gx PYTHONPATH $PREFIX_PYTHONPATH
|
|
|
|
else
|
|
|
|
switch PYTHONPATH
|
|
|
|
case "$PREFIX_PYTHONPATH*"
|
2013-08-14 18:46:58 +02:00
|
|
|
case "*"
|
2016-04-27 20:34:51 +02:00
|
|
|
if not [ $QUIET ]
|
|
|
|
echo "Appending PYTHONPATH"
|
|
|
|
end
|
2014-08-12 21:09:20 +02:00
|
|
|
set -gx PYTHONPATH "$PREFIX_PYTHONPATH:$PYTHONPATH"
|
2013-08-13 23:14:01 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set PATH
|
|
|
|
if not contains $PREFIX_PATH $PATH
|
|
|
|
set -gx PATH $PREFIX_PATH $PATH
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set MANPATH
|
|
|
|
if not contains $PREFIX_MANPATH $MANPATH
|
|
|
|
if not set -q MANPATH
|
2016-06-15 17:41:14 +02:00
|
|
|
set -gx MANPATH $PREFIX_MANPATH:
|
2013-08-13 23:14:01 +02:00
|
|
|
else
|
|
|
|
set -gx MANPATH $PREFIX_MANPATH $MANPATH
|
|
|
|
end
|
|
|
|
end
|
2013-08-14 18:46:58 +02:00
|
|
|
|
2017-08-01 15:41:21 +02:00
|
|
|
# Set PYTHON_BIN
|
|
|
|
if not set -q PYTHON_BIN
|
|
|
|
if test (which python)
|
|
|
|
set -gx PYTHON_BIN (which python)
|
|
|
|
else if test (which python3)
|
|
|
|
set -gx PYTHON_BIN (which python3)
|
|
|
|
else
|
|
|
|
echo "No valid Python found"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2014-05-06 20:19:41 +02:00
|
|
|
# Generate egg_info so that pkg_resources works
|
2017-08-01 15:41:21 +02:00
|
|
|
#
|
|
|
|
|
|
|
|
# Do the work in a fuction
|
|
|
|
function gen_egg_info
|
2019-10-18 16:56:19 +02:00
|
|
|
# Cannot use `test` on wildcards.
|
2019-06-28 00:15:13 +02:00
|
|
|
# @see https://github.com/fish-shell/fish-shell/issues/5960
|
|
|
|
if count $PREFIX_PYTHONPATH/ansible*.egg-info > /dev/null
|
|
|
|
rm -rf $PREFIX_PYTHONPATH/ansible*.egg-info
|
2017-08-01 15:41:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if [ $QUIET ]
|
|
|
|
set options '-q'
|
|
|
|
end
|
|
|
|
|
|
|
|
eval $PYTHON_BIN setup.py $options egg_info
|
|
|
|
|
2016-10-24 19:35:00 +02:00
|
|
|
end
|
2017-08-01 15:41:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
pushd $ANSIBLE_HOME
|
|
|
|
|
2016-04-27 20:34:51 +02:00
|
|
|
if [ $QUIET ]
|
2017-08-01 15:41:21 +02:00
|
|
|
gen_egg_info ^ /dev/null
|
|
|
|
find . -type f -name "*.pyc" -exec rm -f '{}' ';' ^ /dev/null
|
2016-04-27 20:34:51 +02:00
|
|
|
else
|
2017-08-01 15:41:21 +02:00
|
|
|
gen_egg_info
|
|
|
|
find . -type f -name "*.pyc" -exec rm -f '{}' ';'
|
2016-04-27 20:34:51 +02:00
|
|
|
end
|
2014-05-06 20:19:41 +02:00
|
|
|
|
2017-08-01 15:41:21 +02:00
|
|
|
popd
|
2014-05-06 20:19:41 +02:00
|
|
|
|
2016-04-27 20:34:51 +02:00
|
|
|
if not [ $QUIET ]
|
|
|
|
echo ""
|
|
|
|
echo "Setting up Ansible to run out of checkout..."
|
|
|
|
echo ""
|
|
|
|
echo "PATH=$PATH"
|
|
|
|
echo "PYTHONPATH=$PYTHONPATH"
|
2017-08-01 15:41:21 +02:00
|
|
|
echo "PYTHON_BIN=$PYTHON_BIN"
|
2016-04-27 20:34:51 +02:00
|
|
|
echo "ANSIBLE_LIBRARY=$ANSIBLE_LIBRARY"
|
|
|
|
echo "MANPATH=$MANPATH"
|
|
|
|
echo ""
|
|
|
|
echo "Remember, you may wish to specify your host file with -i"
|
|
|
|
echo ""
|
|
|
|
echo "Done!"
|
|
|
|
echo ""
|
2013-08-13 23:14:01 +02:00
|
|
|
end
|
2016-04-27 20:34:51 +02:00
|
|
|
|
|
|
|
set -e QUIET
|