From 62833b5ff44f5073728658e229f3445394d404c2 Mon Sep 17 00:00:00 2001
From: kmochocki <kmochocki@syncad.com>
Date: Fri, 13 Sep 2024 18:16:43 +0000
Subject: [PATCH] Use PYPROJECT_DIR during poetry install

---
 templates/python_projects.gitlab-ci.yml | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/templates/python_projects.gitlab-ci.yml b/templates/python_projects.gitlab-ci.yml
index 4c840bd..be17e7e 100644
--- a/templates/python_projects.gitlab-ci.yml
+++ b/templates/python_projects.gitlab-ci.yml
@@ -22,10 +22,9 @@ variables:
 .configuration_template:
   extends: .job-defaults
   image: "${PYTHON_IMAGE}"
-  variables:
-    PYPROJECT_DIR: "$(pwd)"
 
   before_script:
+    - if [ -z "${PYPROJECT_DIR}" ]; then PYPROJECT_DIR="$(pwd)"; else echo "using - ${PYPROJECT_DIR}"; fi
     - poetry -C "${PYPROJECT_DIR}" env use python3  # create virtualenv if not exists
     - source $(poetry -C "${PYPROJECT_DIR}" env info --path)/bin/activate  # activate that virtualenv
     - python3 -V
@@ -37,7 +36,7 @@ variables:
   extends: .configuration_template
   before_script:
     - !reference [.configuration_template, before_script]
-    - poetry install
+    - poetry -C "${PYPROJECT_DIR}" install
     - pip list
 
 
@@ -45,11 +44,13 @@ variables:
 
 .pre_commit_checks_template:
   extends: .project_develop_configuration_template
+  variables:
+    PRE_COMMIT_CONFIG: "${PYPROJECT_DIR}/.pre-commit-config.yaml"
   script:
     - pushd . && cd /tmp && poetry self update && popd  # Bump poetry version so `poetry lock --no-update` will use the latest one; doing it in different directory to avoid `poetry.lock` and `pyproject.toml` changes
-    - poetry -V
+    - poetry -C "${PYPROJECT_DIR}" -V
     - echo -e "${TXT_BLUE}Checking all files with pre-commit hooks...${TXT_CLEAR}" &&
-      pre-commit run --all-files
+      pre-commit run --config ${PRE_COMMIT_CONFIG} --all-files
   artifacts:
     when: always
     expire_in: 1 week
-- 
GitLab