From e7091148cd74e8d82da3f47eca0f3719f20bd0ed Mon Sep 17 00:00:00 2001
From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com>
Date: Mon, 17 Jul 2023 15:17:00 +0200
Subject: [PATCH] fix flake8 using python_install

---
 .gitlab-ci.yml                                  |  1 -
 templates/python/code_quality/flake8/flake8.yml |  5 ++---
 templates/python/partial/python_install.yml     | 16 +++++++++++-----
 tests/black_project/pyproject.toml              |  5 +++++
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d820ac1..8ccae3d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -21,7 +21,6 @@ flake8:
     stage: templates
     variables:
         PROJECT_PATH: "tests/flake8_project"
-        PYTHON_SETUP: "pip install ${PROJECT_PATH} flake8"
     only:
         changes:
             - .gitlab-ci.yml
diff --git a/templates/python/code_quality/flake8/flake8.yml b/templates/python/code_quality/flake8/flake8.yml
index 787121d..90633de 100644
--- a/templates/python/code_quality/flake8/flake8.yml
+++ b/templates/python/code_quality/flake8/flake8.yml
@@ -5,14 +5,13 @@ include:
   - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/python_install@0.1.0.yaml'
 
 flake8:
-    image: python:${IMAGE_TAG}
+    extend: python_install
     stage: code_quality
     variables:
-        IMAGE_TAG: "latest"
         PROJECT_PATH: "."
         PYTHON_SETUP: "pip install ${PROJECT_PATH}[CODE_QUALITY]"
     script:
-        *python_install
+        python_install
         - flake8 ${PROJECT_PATH} -v
     only:
         changes:
diff --git a/templates/python/partial/python_install.yml b/templates/python/partial/python_install.yml
index 1c71a09..b3315a7 100644
--- a/templates/python/partial/python_install.yml
+++ b/templates/python/partial/python_install.yml
@@ -1,5 +1,11 @@
-.python_install: &python_install
-  - python --version  # Debug
-  - python -m venv venv --upgrade-deps || python -m venv venv  # upgrade-deps is not supported before 3.9
-  - source venv/bin/activate
-  - ${PYTHON_SETUP}
+.python_install:
+    image: python:${IMAGE_TAG}
+    variables:
+        IMAGE_TAG: "latest"
+        PROJECT_PATH: "."
+        PYTHON_SETUP: "pip install -r ${PROJECT_PATH}/requirements.txt"
+    script:
+        - python --version  # Debug
+        - python -m venv venv --upgrade-deps || python -m venv venv  # upgrade-deps is not supported before 3.9
+        - source venv/bin/activate
+        - ${PYTHON_SETUP}
diff --git a/tests/black_project/pyproject.toml b/tests/black_project/pyproject.toml
index beec19a..6e944a1 100644
--- a/tests/black_project/pyproject.toml
+++ b/tests/black_project/pyproject.toml
@@ -9,3 +9,8 @@ authors = [
     { name = "Author Name", email = "author.name@example.com" },
 ]
 description = "A description of what the package is for."
+
+[project.optional-dependencies]
+CODE_QUALITY = [
+    "flake8",
+]
-- 
GitLab