From 95ff81e17169c0e1183c04a2e07f7e30c2e37357 Mon Sep 17 00:00:00 2001
From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com>
Date: Mon, 10 Jul 2023 19:50:06 +0200
Subject: [PATCH] add meta template for python_install.yml

---
 python/meta/README.md          | 60 ++++++++++++++++++++++++++++++++++
 python/meta/python_install.yml | 18 ++++++++++
 2 files changed, 78 insertions(+)
 create mode 100644 python/meta/README.md
 create mode 100644 python/meta/python_install.yml

diff --git a/python/meta/README.md b/python/meta/README.md
new file mode 100644
index 0000000..e006bb4
--- /dev/null
+++ b/python/meta/README.md
@@ -0,0 +1,60 @@
+## Objective
+
+Run [pytest](https://docs.pytest.org/en/latest/) on your Python code to ensure all unit tests pass.
+Pytest is a popular framework for writing and executing tests in Python, and it supports test
+automation, modular fixtures, parameterized testing, and many other features.
+
+## How to use it
+
+1. Configure the `pytest.ini` or `pyproject.toml` file in your repository's root directory with your
+   desired rules.
+2. Include the pytest template in your CI/CD configuration (see quick use above).
+3. If you need to customize the job, check
+   the [jobs customization](https://docs.r2devops.io/get-started/use-templates/#job-templates-customization).
+
+## Variables
+
+| Name           | Description                                                                                                                                                  | Default                  |
+|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|
+| `PYTHON_SETUP` | Bash commands to setup your python environment. Default rely on `pyproject.toml` to install project and test dependencies.                                   | `"pip install .[TESTS]"` |
+| `IMAGE_TAG`    | The default tag for the docker image. See [Python Docker Official Image](https://hub.docker.com/_/python) for supported tags and respective Dockerfile links | `"latest"`               |
+
+## Global Configuration of pytest
+
+To add configuration to `pytest` that is shared with any other usage of pytest (such as manual runs,
+pre-commit, etc.), you can use the `pytest.ini` or `pyproject.toml` configuration files. Learn more
+about [pytest configuration](https://docs.pytest.org/en/stable/customize.html) files.
+
+## Multiple pytest Jobs in the same pipeline
+
+You can run this pytest job multiple times in the same pipeline (e.g. to test multiple python version
+or different namespaces) using extends GitLab keyword.
+
+```yaml
+stages:
+    - test
+
+include:
+    - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/pytest@latest.yaml'
+
+# Compatibility tests
+pytest_3.10:
+    extends: pytest
+    variables:
+        IMAGE_TAG: "3.10"
+```
+
+https://docs.r2devops.io/get-started/use-templates/#multiple-usage-of-the-same-job-template-in-your-pipeline
+
+## Add a <a href="https://docs.pytest.org/en/latest/"><img alt="Tested with pytest" src="https://img.shields.io/badge/Tested%20with-pytest-green"></a> Badge to your project README.md
+
+To display the use of pytest in your project, you can add the following badge to your README.md:
+
+```markdown
+<a href="https://docs.pytest.org/en/latest/">
+    <img alt="Tested with pytest" src="https://img.shields.io/badge/Tested%20with-pytest-green">
+</a>
+```
+
+Please note that the `src` URL in the pytest badge will need to be updated to reflect the actual
+testing status of your project in your continuous integration pipeline.
diff --git a/python/meta/python_install.yml b/python/meta/python_install.yml
new file mode 100644
index 0000000..7ca9133
--- /dev/null
+++ b/python/meta/python_install.yml
@@ -0,0 +1,18 @@
+python_install:
+    image: python:${IMAGE_TAG}
+    stage: ${ENV_SETUP}
+    variables:
+        PYTHON_SETUP: "pip install .[TESTS]"
+        IMAGE_TAG: "latest"
+        STAGE: "env_setup"
+    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}
+        - pytest
+    only:
+        changes:
+            - ./**/*.py
+            - .gitlab-ci.yml
+            - pyproject.toml
-- 
GitLab