From f6a0b2e23f6edf57b08b2da318a27d91e79dd3f5 Mon Sep 17 00:00:00 2001 From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com> Date: Mon, 17 Jul 2023 16:18:46 +0200 Subject: [PATCH] update python_install readme --- python_install.r2.yml | 2 +- templates/python/partial/README.md | 50 +++++++++++++----------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/python_install.r2.yml b/python_install.r2.yml index 60cd8b2..069dfd7 100644 --- a/python_install.r2.yml +++ b/python_install.r2.yml @@ -2,7 +2,7 @@ files: template: ./templates/python/partial/python_install.yml documentation: ./templates/python/partial/README.md data: - description: "Job that is meant to be extend by subsequent jobs that need a python environment." + description: "Job that is meant to be extend by jobs that need a python environment." icon: ðŸ public: true labels: diff --git a/templates/python/partial/README.md b/templates/python/partial/README.md index e006bb4..7533c19 100644 --- a/templates/python/partial/README.md +++ b/templates/python/partial/README.md @@ -1,51 +1,43 @@ ## 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. +The objective of the `python_install` job is to provide a Python environment with all requirements +installed for CI jobs. This reusable job can help speed up other jobs creation and ensure +consistent configuration across CI jobs that rely on a python environment. ## 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). +1. Include the pytest template in your CI/CD configuration (see quick use above). +2. Create a job that extend the `python_install` job template. 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"` | +| Name | Description | Default | +|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------| +| `PROJECT_PATH` | The path to the project root directory. | `"."` | +| `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"` | +| `PYTHON_SETUP` | Bash commands to setup your python environment. Default rely on `requirements.txt` to install all dependencies. | `"pip install -r ${PROJECT_PATH}/requirements.txt"` | -## 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 +```yml include: - - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/pytest@latest.yaml' + - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/python_install@1.0.0.yaml' -# Compatibility tests -pytest_3.10: - extends: pytest +flake8: + extend: python_install + stage: code_quality variables: + PROJECT_PATH: "." IMAGE_TAG: "3.10" + PYTHON_SETUP: "pip install ${PROJECT_PATH}[CODE_QUALITY]" + script: + python_install + - flake8 ${PROJECT_PATH} -v ``` -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: -- GitLab