Skip to content

Commit

Permalink
Add install_requirements script
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed May 22, 2021
1 parent 8efeb56 commit 5ec0dd1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/py-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
python -m pip install --upgrade pip
# Prefer requirements-dev.txt
if [ -f requirements-dev.txt ]; then
pip install -r requirements-dev.txt
bin/install_requirements requirements-dev.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
elif [ -f requirements-test.txt ]; then
pip install -r requirements-test.txt
bin/install_requirements requirements-test.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
bin/install_requirements requirements.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
fi
pip install pytest-xdist coveralls
Expand Down Expand Up @@ -106,11 +106,11 @@ jobs:
python -m pip install --upgrade pip
# Prefer requirements-test.txt
if [ -f requirements-test.txt ]; then
pip install -r requirements-test.txt
bin/install_requirements requirements-test.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
elif [ -f requirements-dev.txt ]; then
pip install -r requirements-dev.txt
bin/install_requirements requirements-dev.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
elif [ -f requirements.txt ]; then
pip install -r requirements.txt
bin/install_requirements requirements.txt "${{ secrets.ADMIN_GITHUB_TOKEN }}"
fi
pip install pytest-xdist
Expand Down
34 changes: 34 additions & 0 deletions bin/install_requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
# Install component requirements.
# Require requirements.txt file path as first argument
# and GitHub access token as second argument.

# Stop on errors
set -e

ROOT="$( cd "$( dirname "$(readlink -f "$0")" )/.." >/dev/null 2>&1 && pwd )"
cd "${ROOT}"

python=$(which python3)
pip="${python} -m pip"

REQ=$(cat "${1}")
while true; do
FILES=$(echo "${REQ}" | grep "^-r " | sed "s/^-r\\s\+//g")
if test -z "${FILES}"; then
break
fi
for FILE in ${FILES}; do
FILE_R=$(echo "${FILE}" | sed "s/\\./\\\\./g")
REQ=$(echo "${REQ}" | sed -e "/^-r\\s\+${FILE_R}/{r ${FILE}" -e "d" -e "}")
done
done
GIT=$(echo "${REQ}" | grep "{GITHUB_TOKEN}" | tr '\r\n' ' ')
REQ=$(echo "${REQ}" | grep -v "{GITHUB_TOKEN}" | tr '\r\n' ' ')

if test -n "${GIT}"; then
GIT=$(echo "${GIT}" | sed "s/{GITHUB_TOKEN}/${2}/g")
${pip} install --upgrade ${GIT}
fi

${pip} install --upgrade ${REQ}

0 comments on commit 5ec0dd1

Please sign in to comment.