-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-py
executable file
·70 lines (60 loc) · 1.66 KB
/
gh-py
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
#!/usr/bin/env bash
if [[ "$OSTYPE" == "msys" ]]; then
PYTHON="python"
else
if [[ $(python3 --version) ]]; then
PYTHON="python3"
else
PYTHON="python"
fi
fi
if [[ "$OSTYPE" == "msys" ]]; then
PIP="pip"
else
if [[ $(pip3 --version) ]]; then
PIP="pip3"
else
PIP="pip"
fi
fi
if [[ "$(pwd -W)" ]] 2> /dev/null; then
CALLING_DIR=$(pwd -W)
else
CALLING_DIR=$(pwd)
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "${SCRIPT_DIR}"
export PYTHONPATH="${SCRIPT_DIR}/.gh-py"
export PATH="${SCRIPT_DIR}/.gh-py/bin:${PATH}"
result=true
for dir in "${SCRIPT_DIR}/.gh-py" "${SCRIPT_DIR}/.venv"
do
if ! [ -d "$dir" ]; then
result=false
break
fi
done
if (! $result ) then
echo "Installing extension environment."
if [ ! -d "${SCRIPT_DIR}/.gh-py" ]; then
$PIP install --upgrade --target "${SCRIPT_DIR}/.gh-py" -q poetry
fi
if [ ! -d "${SCRIPT_DIR}/.venv" ]; then
"${SCRIPT_DIR}/.gh-py/bin/poetry" config virtualenvs.in-project true
"${SCRIPT_DIR}/.gh-py/bin/poetry" install -q
fi
echo "Extension environment installed."
fi
if [ "$1" = "poetry" ]; then
shift
"${SCRIPT_DIR}/.gh-py/bin/poetry" $@
exit 0;
fi
if [ "pyproject.toml" -nt "poetry.lock" ] || [ ! -f "poetry.lock" ]; then
echo "Updating extension environment."
"${SCRIPT_DIR}/.gh-py/bin/poetry" config virtualenvs.in-project true
"${SCRIPT_DIR}/.gh-py/bin/poetry" update -q -n
echo "Extension environment updated."
fi
"${SCRIPT_DIR}/.gh-py/bin/poetry" run python -c "import gh_py.cli;import os;os.chdir('${CALLING_DIR}');gh_py.cli.run('$*')"
exit 0;