Debian Codegraph @

hacking/env-setup.fish

raw
1 #!/usr/bin/env fish
2 # Script: env-setup.fish
3 # Description: Modifies the environment for running Ansible from a checkout
4 # Usage: . ./hacking/env-setup [-q]
5
6 # Set PYTHON_BIN
7 if not set -q PYTHON_BIN
8 for exe in python3 python
9 if command -v $exe > /dev/null
10 set -gx PYTHON_BIN (command -v $exe)
11 break
12 end
13 end
14 if not set -q PYTHON_BIN
15 echo "No valid Python found"
16 exit 1
17 end
18 end
19
20 # Retrieve the path of the current directory where the script resides
21 set HACKING_DIR (dirname (status -f))
22 set FULL_PATH ($PYTHON_BIN -c "import os; print(os.path.realpath('$HACKING_DIR'))")
23 set ANSIBLE_HOME (dirname $FULL_PATH)
24
25 # Set quiet flag
26 set QUIET ""
27 if contains -- (string split -m 1 " " $argv) -q --quiet
28 set QUIET "true"
29 end
30
31 # Set environment variables
32 set -gx PREFIX_PYTHONPATH $ANSIBLE_HOME/lib
33 set -gx ANSIBLE_TEST_PREFIX_PYTHONPATH $ANSIBLE_HOME/test/lib
34 set -gx PREFIX_PATH $ANSIBLE_HOME/bin
35 set -gx PREFIX_MANPATH $ANSIBLE_HOME/docs/man
36
37 # Set PYTHONPATH
38 if not set -q PYTHONPATH
39 set -gx PYTHONPATH $PREFIX_PYTHONPATH
40 else if not string match -qr $PREFIX_PYTHONPATH'($|:)' $PYTHONPATH
41 if not test -n "$QUIET"
42 echo "Appending PYTHONPATH"
43 end
44 set -gx PYTHONPATH "$PREFIX_PYTHONPATH:$PYTHONPATH"
45 end
46
47 # Set ansible_test PYTHONPATH
48 if not string match -qr $ANSIBLE_TEST_PREFIX_PYTHONPATH'($|:)' $PYTHONPATH
49 if not test -n "$QUIET"
50 echo "Appending PYTHONPATH"
51 end
52 set -gx PYTHONPATH "$ANSIBLE_TEST_PREFIX_PYTHONPATH:$PYTHONPATH"
53 end
54
55 # Set PATH
56 if not contains -- $PREFIX_PATH $PATH
57 set -gx PATH $PREFIX_PATH $PATH
58 end
59
60 # Set MANPATH
61 if not set -q MANPATH
62 set -gx MANPATH $PREFIX_MANPATH
63 else if not string match -qr $PREFIX_MANPATH'($|:)' $MANPATH
64 set -gx MANPATH "$PREFIX_MANPATH:$MANPATH"
65 end
66
67 pushd $ANSIBLE_HOME
68 if test -n "$QUIET"
69 # Remove any .pyc files found
70 find . -type f -name "*.pyc" -exec rm -f '{}' ';' &> /dev/null
71 else
72 # Remove any .pyc files found
73 find . -type f -name "*.pyc" -exec rm -f '{}' ';'
74 # Display setup details
75 echo ""
76 echo "Setting up Ansible to run out of checkout..."
77 echo ""
78 echo "PATH=$PATH"
79 echo "PYTHONPATH=$PYTHONPATH"
80 echo "PYTHON_BIN=$PYTHON_BIN"
81 echo "ANSIBLE_LIBRARY=$ANSIBLE_LIBRARY"
82 echo "MANPATH=$MANPATH"
83 echo ""
84 echo "Remember, you may wish to specify your host file with -i"
85 echo ""
86 echo "Done!"
87 echo ""
88 end
89 popd
90
91 # Unset QUIET variable
92 set -e QUIET