Skip to content

Commit

Permalink
installing specific poetry version (#29812)
Browse files Browse the repository at this point in the history
* installing specific poetry version - moving the logic to bootstrap
  • Loading branch information
kobymeir authored and maimorag committed Sep 28, 2023
1 parent cef1ca3 commit 6660b95
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .gitlab/ci/.gitlab-ci.global.yml
Expand Up @@ -127,11 +127,11 @@

.install_venv: &install_venv
- section_start "Installing Virtualenv" --collapsed
- echo "Checking if pyproject.toml is consistent with poetry.lock"
- poetry lock --check
# we still need to install even if cached. if cached, `poetry` will handle it
- echo "installing venv, with always copy:${POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY}"
- NO_HOOKS=1 .hooks/bootstrap | tee --append $ARTIFACTS_FOLDER/logs/installations.log
- echo "Checking if pyproject.toml is consistent with poetry.lock"
- poetry lock --check
- npm ci --cache .npm --prefer-offline | tee --append $ARTIFACTS_FOLDER/logs/installations.log
- source ./.venv/bin/activate
- |
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/ci/.gitlab-ci.yml
Expand Up @@ -62,6 +62,8 @@ variables:
CONTENT_GITLAB_CI: "true"
POETRY_VIRTUALENVS_OPTIONS_ALWAYS_COPY: "true"
FF_USE_FASTZIP: "true"
POETRY_VERSION: "1.6.1"
INSTALL_POETRY: "true"

include:
- local: .gitlab/ci/.gitlab-ci.global.yml
Expand Down
40 changes: 33 additions & 7 deletions .hooks/bootstrap
Expand Up @@ -10,7 +10,7 @@

function exit_on_error {
if [ "${1}" -ne 0 ]; then
echo "ERROR: ${2}"
echo "ERROR: ${2}, exiting with code ${1}" 1>&2
exit "${1}"
fi
}
Expand Down Expand Up @@ -42,7 +42,7 @@ else
if [ ! -e "${GIT_HOOKS_DIR}/pre-commit" ]; then
echo "Installing 'pre-commit' hooks"
ln -s "${HOOKS_DIR}/pre-commit" "${GIT_HOOKS_DIR}/pre-commit"
exit_on_error $? "Failed to install pre-commit hook, exiting with exit code $?"
exit_on_error $? "Failed to install pre-commit hook"
else
echo "Skipping install of pre-commit hook as it already exists."
echo "If you want to re-install: 'rm ${GIT_HOOKS_DIR}/pre-commit' and then run this script again."
Expand All @@ -51,11 +51,37 @@ else
fi

echo "======================="

if ! command -v poetry >/dev/null 2>&1; then
echo "ERROR: poetry is missing. Please run the following command to install poetry:
curl -sSL https://install.python-poetry.org | python3 -" 1>&2
exit 1
if [ -z "${INSTALL_POETRY}" ]; then
if ! command -v poetry >/dev/null 2>&1; then
echo "ERROR: poetry is missing. Please run the following command to install poetry:
curl -sSL https://install.python-poetry.org | python3 -" 1>&2
exit 1
fi
else
should_install_poetry="yes"
if command -v poetry >/dev/null 2>&1; then
if [[ "$(poetry --version)" == "Poetry (version ${POETRY_VERSION})" ]]; then
echo "Poetry already installed:$(poetry --version) with correct version"
should_install_poetry="no"
else
echo "Poetry installed with a different version:$(poetry --version) required:${POETRY_VERSION}"
fi
else
echo "Poetry isn't installed"
fi
if [[ "${should_install_poetry}" == "yes" ]]; then
echo "Installing Poetry version:${POETRY_VERSION}"
curl -sSL https://install.python-poetry.org | python3 - --version "${POETRY_VERSION}"
exit_on_error $? "Failed to install Poetry version:${POETRY_VERSION}"
if ! command -v poetry >/dev/null 2>&1; then
exit_on_error $? "Poetry isn't installed"
fi
if [[ "$(poetry --version)" == "Poetry (version ${POETRY_VERSION})" ]]; then
echo "Poetry version ${POETRY_VERSION} installed successfully"
else
exit_on_error 1 "Poetry version $(poetry --version) doesn't match the required version: ${POETRY_VERSION}"
fi
fi
fi

if [ -n "${CI}" ]; then
Expand Down

0 comments on commit 6660b95

Please sign in to comment.