From f77bb1b7608c89415c2bb191732ce2c47b4d893d Mon Sep 17 00:00:00 2001 From: Dorian Turba <froggit.commit.z3jqj@simplelogin.com> Date: Sat, 8 Jul 2023 11:40:14 +0200 Subject: [PATCH] flake8 job --- flake8.r2.yml | 14 ++++++++++ python/code_quality/flake8/README.md | 39 +++++++++++++++++++++++++++ python/code_quality/flake8/flake8.yml | 14 ++++++++++ 3 files changed, 67 insertions(+) create mode 100644 flake8.r2.yml create mode 100644 python/code_quality/flake8/README.md create mode 100644 python/code_quality/flake8/flake8.yml diff --git a/flake8.r2.yml b/flake8.r2.yml new file mode 100644 index 0000000..5a05adc --- /dev/null +++ b/flake8.r2.yml @@ -0,0 +1,14 @@ +files: + template: ./python/code_quality/flake8/flake8.yml + documentation: ./python/code_quality/flake8/README.md +data: + description: "Run flake8 on your repository" + icon: 💎 + public: true + labels: + - Lint + - Utilities + - Code Quality + - Python + license: MIT + deprecated: false diff --git a/python/code_quality/flake8/README.md b/python/code_quality/flake8/README.md new file mode 100644 index 0000000..c6cc96a --- /dev/null +++ b/python/code_quality/flake8/README.md @@ -0,0 +1,39 @@ +## Objective + +Run [Flake8](https://flake8.pycqa.org/en/latest/) on your Python code to ensure it adheres to PEP8 +standards and to detect various errors such as syntax errors, semantic errors, and complex code. +Flake8 is a Python tool that glues together pycodestyle, pyflakes, and McCabe. + +### Global Configuration of Flake8 + +To add configuration to `flake8` shared with any other usage of flake8 (such as manual run, +pre-commit, etc), you can use `.flake8` configuration file. Learn more +about [flake8 configuration](https://flake8.pycqa.org/en/latest/user/configuration.html) files. + +See this example: + +```ini +[flake8] +exclude = .git,__pycache__,venv,dist +max-complexity = 10 +max-line-length = 100 +``` + +This example ignores certain errors, sets the maximum line length to 100 characters, excludes the +tests directory, and sets the maximum McCabe complexity to 10. + +## How to use it + +1. Configure the `.flake8` file in your repository's root directory with your desired rules. +2. Include the flake8 template in your CI/CD configuration (see quick use above). +3. Customize the template if it's relevant. + +## Add a <a href="https://flake8.pycqa.org/"><img alt="Code style: Flake8" src="https://img.shields.io/badge/Flake8-checks-blue"></a> Badge to your project README.md + +To display the use of Flake8 in your project, you can add the following badge to your README.md: + +```markdown +<a href="https://flake8.pycqa.org/"> + <img alt="Code style: Flake8" src="https://img.shields.io/badge/Flake8-checks-blue"> +</a> +``` diff --git a/python/code_quality/flake8/flake8.yml b/python/code_quality/flake8/flake8.yml new file mode 100644 index 0000000..873c1d4 --- /dev/null +++ b/python/code_quality/flake8/flake8.yml @@ -0,0 +1,14 @@ +flake8: + 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 flake8 + - flake8 + only: + changes: + - ./**/*.py + - .gitlab-ci.yml + - pyproject.toml -- GitLab