From 3592276c23f19fd1b71b5dd45f00232085f171cb Mon Sep 17 00:00:00 2001 From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com> Date: Mon, 10 Jul 2023 16:22:29 +0200 Subject: [PATCH] add mypy --- mypy.r2.yml | 15 +++++++++++++++ python/code_quality/mypy/README.md | 29 +++++++++++++++++++++++++++++ python/code_quality/mypy/mypy.yml | 14 ++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 mypy.r2.yml create mode 100644 python/code_quality/mypy/README.md create mode 100644 python/code_quality/mypy/mypy.yml diff --git a/mypy.r2.yml b/mypy.r2.yml new file mode 100644 index 0000000..105d900 --- /dev/null +++ b/mypy.r2.yml @@ -0,0 +1,15 @@ +files: + template: ./python/code_quality/mypy/mypy.yml + documentation: ./python/code_quality/mypy/README.md +data: + description: "Run mypy on your repository" + icon: 💎 + public: true + labels: + - Static TypeChecking + - Utilities + - Code Quality + - Python + - TypeChecker + license: MIT + deprecated: false diff --git a/python/code_quality/mypy/README.md b/python/code_quality/mypy/README.md new file mode 100644 index 0000000..2cc6ee4 --- /dev/null +++ b/python/code_quality/mypy/README.md @@ -0,0 +1,29 @@ +## Objective + +Run [mypy](https://mypy.readthedocs.io/en/stable/) on your Python code to perform static typing +checks, ensuring better code reliability and readability. `mypy` is a Python tool that checks the +types of variables, function return values, and more. + +### Global Configuration of mypy + +To add configuration to `mypy` shared with any other usage of mypy (such as manual run, pre-commit, +etc), you can use `mypy.ini`, `setup.cfg` or `pyproject.toml` configuration file. Learn more +about [mypy configuration](https://mypy.readthedocs.io/en/stable/config_file.html) files. + +## How to use it + +1. Configure the `mypy.ini`, `setup.cfg` or `pyproject.toml` file in your repository's root directory with your + desired rules. +2. Include the mypy 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). + +## Add a <a href="https://mypy.readthedocs.io/"><img alt="Type Checked: mypy" src="https://img.shields.io/badge/mypy-checks-blue"></a> Badge to your project README.md + +To display the use of mypy in your project, you can add the following badge to your README.md: + +```markdown +<a href="https://mypy.readthedocs.io/"> + <img alt="Type Checked: mypy" src="https://img.shields.io/badge/mypy-checks-blue"> +</a> +``` diff --git a/python/code_quality/mypy/mypy.yml b/python/code_quality/mypy/mypy.yml new file mode 100644 index 0000000..5922d95 --- /dev/null +++ b/python/code_quality/mypy/mypy.yml @@ -0,0 +1,14 @@ +mypy: + image: python:latest + stage: code_quality + 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 + - pip install mypy + - mypy + only: + changes: + - ./**/*.py + - .gitlab-ci.yml + - pyproject.toml -- GitLab