From 2032407b5fc222a1afefbe73206438c6387958e5 Mon Sep 17 00:00:00 2001
From: Hamza DIOUANE <hamza.diouane@try-it.fr>
Date: Fri, 31 May 2024 17:16:47 +0200
Subject: [PATCH 1/3] Fix of documentation and upgrade of quality packages

---
 .pre-commit-config.yaml            | 14 +++++++-------
 AUTHORS.rst                        |  2 +-
 CONTRIBUTING.md                    |  6 +++---
 README.md                          |  2 +-
 requirements/requirements-3_11.txt |  6 ++----
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 4da5724..df18c49 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,34 +1,34 @@
 repos:
     -   repo: https://github.com/psf/black
-        rev: 23.9.1
+        rev: 24.4.2
         hooks:
             -   id: black
                 args: [ --check, --diff, --quiet ]
                 language_version: python3
     -   repo: https://github.com/PyCQA/flake8
-        rev: 6.1.0
+        rev: 7.0.0
         hooks:
             -   id: flake8
     -   repo: https://github.com/pycqa/isort
-        rev: 5.12.0
+        rev: 5.13.2
         hooks:
             -   id: isort
                 args: [ --check-only ]
     -   repo: https://github.com/pre-commit/mirrors-mypy
-        rev: v1.5.1
+        rev: v1.10.0
         hooks:
             -   id: mypy
                 exclude: ^tests/
     -   repo: https://github.com/jackdewinter/pymarkdown
-        rev: v0.9.13.4
+        rev: v0.9.20
         hooks:
             -   id: pymarkdown
     -   repo: https://github.com/astral-sh/ruff-pre-commit
-        rev: v0.0.292
+        rev: v0.4.6
         hooks:
             -   id: ruff
     -   repo: https://github.com/pre-commit/pre-commit-hooks/
-        rev: v4.5.0
+        rev: v4.6.0
         hooks:
             -   id: check-yaml
             -   id: check-case-conflict
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 1a4ff46..e421332 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -10,4 +10,4 @@ Development Lead
 Contributors
 ------------
 
-None yet. Why not be the first?
+* Hamza Diouane <hamza.diouane@try-it.fr>
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index ccc41a5..4718ce4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -110,7 +110,7 @@ the codebase.
 
 ```bash
 pip install --upgrade pip
-pip install -e .[QUALITY]
+pip install -e ."[QUALITY]"
 pre-commit install
 ```
 
@@ -163,7 +163,7 @@ GRANT ALL PRIVILEGES ON DATABASE test TO test;
 ##### Install Python Tests requirements
 
 ```bash
-pip install -e .[TEST]
+pip install -e ."[TEST]"
 ```
 
 ##### Run tests
@@ -177,7 +177,7 @@ pytest
 ### Generate requirements
 
 ```bash
-pip install -e .[REQUIREMENTS]
+pip install -e ."[REQUIREMENTS]"
 pip-compile --output-file requirements/requirements-3_11.txt pyproject.toml
 ```
 
diff --git a/README.md b/README.md
index 16311c1..62cef44 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ Below is an example of how to use fake_session_maker fixture in a test:
 # Each test will have a fresh database, empty of any data
 @pytest.mark.parametrize("name", ["jane", "joe"])
 def test_create_example(fake_session_maker, name):
-    result = create_example('test')
+    result = create_example(name)
     assert result == 'success'
     with fake_session_maker() as session:
         # Each time we check, only the data created in this test will be present
diff --git a/requirements/requirements-3_11.txt b/requirements/requirements-3_11.txt
index 43878b9..fb41ac1 100644
--- a/requirements/requirements-3_11.txt
+++ b/requirements/requirements-3_11.txt
@@ -1,11 +1,9 @@
 #
-# This file is autogenerated by pip-compile with Python 3.11
+# This file is autogenerated by pip-compile with Python 3.12
 # by the following command:
 #
-#    pip-compile --output-file=requirements/requirements.txt pyproject.toml
+#    pip-compile --output-file=requirements/requirements-3_11.txt pyproject.toml
 #
-colorama==0.4.6
-    # via pytest
 greenlet==2.0.2
     # via sqlalchemy
 iniconfig==2.0.0
-- 
GitLab


From e681cafcadd1dbdb46bef8cde071cb964e102c6b Mon Sep 17 00:00:00 2001
From: Hamza DIOUANE <hamza.diouane@try-it.fr>
Date: Fri, 31 May 2024 17:40:53 +0200
Subject: [PATCH 2/3] [CI] Adding Build & Push of packages and container + fix
 of linter

---
 .gitlab-ci.yml           | 112 +++++++++++++++++++--------------------
 .pre-commit-config.yaml  |  19 -------
 pyproject.toml           |  65 ++++++++++++++++-------
 requirements/quality.txt |   7 +++
 requirements/tests.txt   |   7 +++
 5 files changed, 114 insertions(+), 96 deletions(-)
 create mode 100644 requirements/quality.txt
 create mode 100644 requirements/tests.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9886782..a0074db 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,69 +1,65 @@
-default:
-    services:
-        - postgres:alpine
-
-stages:
-    - code_quality
-    - test
+# Pip's cache doesn't store the python packages
+# https://pip.pypa.io/en/stable/topics/caching/
+#
+# If you want to also cache the installed packages, you have to install
+# them in a virtualenv and cache it as well.
+cache:
+  paths:
+    - .cache/pip
 
-include:
-    -   remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/black@latest.yaml'
-    -   remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/ruff@latest.yaml'
-    -   remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/pytest@latest.yaml'
-    -   remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/flake8@latest.yaml'
-    -   remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/mypy@latest.yaml'
-    -   remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/python_install@latest.yaml'
+default:
+  image:
+    name: python:latest
 
 variables:
-    PACKAGE_NAME: "fake_session_maker"
-    POSTGRES_DB: test
-    POSTGRES_USER: test
-    POSTGRES_PASSWORD: test
-    POSTGRES_HOST_AUTH_METHOD: trust
-    IMAGE_TAG: "3.12"
+  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
+  PIP_REGISTRY: https://gitlab-ci-token:${CI_JOB_TOKEN}@lab.frogg.it/api/v4/projects/1427/packages/pypi/simple
+  TAG_RELEASE_REGEX: '/^[\d]{1,2}\.[\d]{1,2}\.[\d]{1,2}(\.[\d]{1,2})?$/'
 
-black:
-    variables:
-        PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
+########################### RULES ################################
+.package_rules: &package_rules
+  rules:
+    - if: $CI_COMMIT_BRANCH == "main"
+      changes:
+        - src/*
 
-ruff:
-    variables:
-        PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
-
-flake8:
-    variables:
-        PYTHON_SETUP: "pip install ${PROJECT_PATH}[QUALITY]"
+.container_rules: &container_rules
+  rules:
+    - if: $CI_COMMIT_TAG && $CI_COMMIT_TAG =~ $TAG_RELEASE_REGEX
 
-mypy:
-    variables:
-        PYTHON_SETUP: "pip install . mypy"
-        MYPY_RUN: "mypy"
-
-pytest:
-    variables:
-        PYTHON_SETUP: "pip install ${PROJECT_PATH}[TEST]"
-
-pytest_311:
-    extends: pytest
-    variables:
-        IMAGE_TAG: "3.11"
-
-pytest_310:
-    extends: pytest
-    variables:
-        IMAGE_TAG: "3.10"
+########################### STAGES ################################
+stages:
+  - code quality
+  - tests
+  - build package & push
 
-pytest_39:
-    extends: pytest
+########################### LINTING ################################
+"Linter":
+  stage: code quality
+  before_script:
+    - pip install -r requirements/quality.txt
+  script:
+    - ruff check --output-format=gitlab src/fake_session_maker/fsm.py
+  only:
     variables:
-        IMAGE_TAG: "3.9"
+      - $CI_PIPELINE_SOURCE == "push"
 
-pytest_38:
-    extends: pytest
+########################### TESTING ################################
+"Tests":
+  stage: tests
+  before_script:
+    - pip install -r requirements/tests.txt
+  script:
+    - pytest
+  only:
     variables:
-        IMAGE_TAG: "3.8"
+      - $CI_PIPELINE_SOURCE == "push"
 
-pytest_37:
-    extends: pytest
-    variables:
-        IMAGE_TAG: "3.7"
+########################### BUILDING ################################
+"Build and Push FSM PyPI Package":
+  stage: build package & push
+  <<: *package_rules
+  script:
+    - pip install build twine
+    - python -m build
+    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --verbose --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index df18c49..e35e5e8 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,28 +1,9 @@
 repos:
-    -   repo: https://github.com/psf/black
-        rev: 24.4.2
-        hooks:
-            -   id: black
-                args: [ --check, --diff, --quiet ]
-                language_version: python3
-    -   repo: https://github.com/PyCQA/flake8
-        rev: 7.0.0
-        hooks:
-            -   id: flake8
-    -   repo: https://github.com/pycqa/isort
-        rev: 5.13.2
-        hooks:
-            -   id: isort
-                args: [ --check-only ]
     -   repo: https://github.com/pre-commit/mirrors-mypy
         rev: v1.10.0
         hooks:
             -   id: mypy
                 exclude: ^tests/
-    -   repo: https://github.com/jackdewinter/pymarkdown
-        rev: v0.9.20
-        hooks:
-            -   id: pymarkdown
     -   repo: https://github.com/astral-sh/ruff-pre-commit
         rev: v0.4.6
         hooks:
diff --git a/pyproject.toml b/pyproject.toml
index baf631d..e220b86 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -34,9 +34,6 @@ MANAGE = [
     "bump-my-version",
 ]
 QUALITY = [
-    "black",
-    "flake8",
-    "isort",
     "mypy",
     "pre-commit",
     "ruff",
@@ -54,9 +51,6 @@ TEST = [
 "Bug Tracker" = "https://lab.frogg.it/dorianturba/fake_session_maker"
 "Homepage" = "https://lab.frogg.it/dorianturba/fake_session_maker"
 
-[tool.black]
-line-length = 88
-
 [tool.bumpversion]
 allow_dirty = false
 commit = true
@@ -84,10 +78,6 @@ disallow_untyped_defs = true
 packages = "fake_session_maker"
 python_version = 3.7
 
-[tool.pymarkdown]
-strict-config = true
-plugins.line-length.line_length = 88
-
 [tool.pytest.ini_options]
 addopts = "-rA -q --strict-markers"
 markers = [
@@ -101,6 +91,48 @@ testpaths = [
     "tests",
 ]
 
+[tool.ruff]
+exclude = [
+    ".bzr",
+    ".direnv",
+    ".eggs",
+    ".git",
+    ".git-rewrite",
+    ".hg",
+    ".mypy_cache",
+    ".nox",
+    ".pants.d",
+    ".pytype",
+    ".ruff_cache",
+    ".svn",
+    ".tox",
+    ".venv",
+    "_build",
+    "buck-out",
+    "build",
+    "dist",
+    "node_modules",
+    "pypackages",
+    "venv",
+]
+indent-width = 4
+line-length = 88
+target-version = "py312"
+
+[tool.ruff.format]
+docstring-code-format = true
+docstring-code-line-length = "dynamic"
+
+[tool.ruff.lint]
+select = ["ANN", "C90", "D2", "D3", "D4", "E", "F", "I", "N", "RUF", "UP", "W"]
+
+[tool.ruff.lint.flake8-annotations]
+suppress-dummy-args = true
+
+[tool.ruff.lint.pydocstyle]
+convention = "pep257"
+ignore-decorators = ["typing.overload"]
+
 [tool.tomlsort]
 all = true
 in_place = true
@@ -116,8 +148,7 @@ legacy_tox_ini = """
     min_version = 4.0
     env_list =
         py{37,38,39,310,311}
-        black
-        flake8
+        ruff
         mypy
     isolated_build = true
 
@@ -125,13 +156,9 @@ legacy_tox_ini = """
     deps = pytest
     commands = pytest
 
-    [testenv:black]
-    deps = black
-    commands = black --check .
-
-    [testenv:flake8]
-    deps = flake8
-    commands = flake8
+    [testenv:ruff]
+    deps = ruff
+    commands = ruff check .
 
     [testenv:mypy]
     deps = mypy
diff --git a/requirements/quality.txt b/requirements/quality.txt
new file mode 100644
index 0000000..12fd347
--- /dev/null
+++ b/requirements/quality.txt
@@ -0,0 +1,7 @@
+#
+# This file is autogenerated by pip-compile
+# by the following command:
+#
+#    pip-compile --allow-unsafe --extra=quality --output-file=requirements/quality.txt --strip-extras pyproject.toml
+#
+ruff==0.4.4
\ No newline at end of file
diff --git a/requirements/tests.txt b/requirements/tests.txt
new file mode 100644
index 0000000..7fc585c
--- /dev/null
+++ b/requirements/tests.txt
@@ -0,0 +1,7 @@
+#
+# This file is autogenerated by pip-compile
+# by the following command:
+#
+#    pip-compile --allow-unsafe --extra=quality --output-file=requirements/quality.txt --strip-extras pyproject.toml
+#
+pytest==8.2.0
\ No newline at end of file
-- 
GitLab


From 2336357c9160371ac00bc0fad3930b9c61463a11 Mon Sep 17 00:00:00 2001
From: Dorian Turba <commit.9wuzh@slmail.me>
Date: Wed, 19 Jun 2024 15:26:35 +0200
Subject: [PATCH 3/3] review ci

---
 .gitlab-ci.yml           | 10 +++-------
 requirements/quality.txt |  7 -------
 requirements/tests.txt   |  7 -------
 3 files changed, 3 insertions(+), 21 deletions(-)
 delete mode 100644 requirements/quality.txt
 delete mode 100644 requirements/tests.txt

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a0074db..fbf5bbf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,7 +14,6 @@ default:
 variables:
   PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
   PIP_REGISTRY: https://gitlab-ci-token:${CI_JOB_TOKEN}@lab.frogg.it/api/v4/projects/1427/packages/pypi/simple
-  TAG_RELEASE_REGEX: '/^[\d]{1,2}\.[\d]{1,2}\.[\d]{1,2}(\.[\d]{1,2})?$/'
 
 ########################### RULES ################################
 .package_rules: &package_rules
@@ -22,10 +21,7 @@ variables:
     - if: $CI_COMMIT_BRANCH == "main"
       changes:
         - src/*
-
-.container_rules: &container_rules
-  rules:
-    - if: $CI_COMMIT_TAG && $CI_COMMIT_TAG =~ $TAG_RELEASE_REGEX
+        - pyproject.toml
 
 ########################### STAGES ################################
 stages:
@@ -37,7 +33,7 @@ stages:
 "Linter":
   stage: code quality
   before_script:
-    - pip install -r requirements/quality.txt
+    - pip install ruff
   script:
     - ruff check --output-format=gitlab src/fake_session_maker/fsm.py
   only:
@@ -48,7 +44,7 @@ stages:
 "Tests":
   stage: tests
   before_script:
-    - pip install -r requirements/tests.txt
+    - pip install pytest
   script:
     - pytest
   only:
diff --git a/requirements/quality.txt b/requirements/quality.txt
deleted file mode 100644
index 12fd347..0000000
--- a/requirements/quality.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-#
-# This file is autogenerated by pip-compile
-# by the following command:
-#
-#    pip-compile --allow-unsafe --extra=quality --output-file=requirements/quality.txt --strip-extras pyproject.toml
-#
-ruff==0.4.4
\ No newline at end of file
diff --git a/requirements/tests.txt b/requirements/tests.txt
deleted file mode 100644
index 7fc585c..0000000
--- a/requirements/tests.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-#
-# This file is autogenerated by pip-compile
-# by the following command:
-#
-#    pip-compile --allow-unsafe --extra=quality --output-file=requirements/quality.txt --strip-extras pyproject.toml
-#
-pytest==8.2.0
\ No newline at end of file
-- 
GitLab