diff --git a/README.md b/README.md index 1ad4ce677bf4d58b3d138cb37ea03ea07a2ed75c..11e9d647c50e0a131c01c793456f724b4a321bcf 100644 --- a/README.md +++ b/README.md @@ -298,9 +298,8 @@ This job **disabled by default** and runs [Ruff](https://docs.astral.sh/ruff/) o | ---------------- | ----------------------------------------------------------------------- | ----------------- | | `ruff-enabled` / `RUFF_ENABLED` | Set to `true` to enable ruff job | _none_ (disabled) | | `ruff-args` / `RUFF_ARGS` | Additional [Ruff Linter CLI options](https://docs.astral.sh/ruff/configuration/#full-command-line-interface) | _none_ | -| `ruff-ext-exclude` / `RUFF_EXT_EXCLUDE` | Define [extend-exclude](https://docs.astral.sh/ruff/settings/#extend-exclude) files | _.venv,.cache_ | -:warning: Ruff can replace isort, Black, Bandit, Pylint and much more. [More info](https://github.com/astral-sh/ruff/blob/main/docs/faq.md#which-tools-does-ruff-replace). +:warning: Ruff can replace isort, Bandit, Pylint and much more. [More info](https://github.com/astral-sh/ruff/blob/main/docs/faq.md#which-tools-does-ruff-replace). In addition to logs in the console, this job produces the following reports, kept for one week: @@ -309,6 +308,16 @@ In addition to logs in the console, this job produces the following reports, kep | `$PYTHON_PROJECT_DIR/reports/py-ruff.gitlab.json` | [GitLab](https://docs.astral.sh/ruff/settings/#output-format) | [GitLab integration](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportscodequality) | | `$PYTHON_PROJECT_DIR/reports/py-ruff.native.json` | [JSON](https://docs.astral.sh/ruff/settings/#output-format) | [SonarQube integration](https://docs.sonarqube.org/latest/analysis/external-issues/)<br/>_This report is generated only if SonarQube template is detected_ | +### `py-ruff-format` job + +This job **disabled by default** and runs [Ruff](https://docs.astral.sh/ruff/) on the repo. It is bound to the build stage. + +| Input / Variable | Description | Default value | +| ---------------- | ----------------------------------------------------------------------- | ----------------- | +| `ruff-format-enabled` / `RUFF_FORMAT_ENABLED` | Set to `true` to enable ruff job | _none_ (disabled) | + +:warning: Ruff can replace Black and much more. [More info](https://github.com/astral-sh/ruff/blob/main/docs/faq.md#which-tools-does-ruff-replace). + #### `py-mypy` job This job is **disabled by default** and performs code analysis based on [mypy](https://mypy.readthedocs.io/en/stable/). diff --git a/kicker.json b/kicker.json index 4f55200c64663dd7fdabf9c6bc13c1729c795c14..02870d66208cae77717c800724922e9c2f40c969 100644 --- a/kicker.json +++ b/kicker.json @@ -263,14 +263,17 @@ "name": "RUFF_ARGS", "description": "Additional [Ruff Linter CLI options](https://docs.astral.sh/ruff/configuration/#full-command-line-interface)", "advanced": true - }, - { - "name": "RUFF_EXT_EXCLUDE", - "description": "Define [extend-exclude](https://docs.astral.sh/ruff/settings/#extend-exclude) files", - "advanced": true } ] }, + { + "id": "ruff-format", + "name": "Ruff Format", + "description": "An extremely fast Python linter and code formatter, written in Rust. [Ruff](https://docs.astral.sh/ruff/)", + "enable_with": "RUFF_FORMAT_ENABLED", + "variables": [ + ] + }, { "id": "mypy", "name": "mypy", diff --git a/templates/gitlab-ci-python.yml b/templates/gitlab-ci-python.yml index 6338ad01d682dc2c4120f7a9523b39874ade832f..f8b670885d39db80f51e463a2b010501fc38bb10 100644 --- a/templates/gitlab-ci-python.yml +++ b/templates/gitlab-ci-python.yml @@ -166,9 +166,10 @@ spec: ruff-args: description: Additional [Ruff Linter CLI options](https://docs.astral.sh/ruff/configuration/#full-command-line-interface) default: "" - ruff-ext-exclude: - description: Define [extend-exclude](https://docs.astral.sh/ruff/settings/#extend-exclude) files - default: "" + ruff-format-enabled: + description: Enable Ruff + type: boolean + default: false mypy-enabled: description: Enable mypy type: boolean @@ -291,7 +292,7 @@ variables: PYTHON_ISORT_ENABLED: $[[ inputs.isort-enabled ]] RUFF_ENABLED: $[[ inputs.ruff-enabled ]] RUFF_ARGS: $[[ inputs.ruff-args ]] - RUFF_EXT_EXCLUDE: $[[ inputs.ruff-ext-exclude ]] + RUFF_FORMAT_ENABLED: $[[ inputs.ruff-format-enabled ]] MYPY_ENABLED: $[[ inputs.mypy-enabled ]] MYPY_ARGS: $[[ inputs.mypy-args ]] MYPY_FILES: $[[ inputs.mypy-files ]] @@ -1063,8 +1064,8 @@ py-ruff: script: - mkdir -p -m 777 reports - | - if [[ ${BANDIT_ENABLED} == "true" || ${PYLINT_ENABLED} == "true" || ${PYTHON_ISORT_ENABLED} == "true" || ${PYTHON_BLACK_ENABLED} == "true" ]]; then - log_warn "Ruff can replace isort, Black, Bandit, Pylint" + if [[ ${BANDIT_ENABLED} == "true" || ${PYLINT_ENABLED} == "true" || ${PYTHON_ISORT_ENABLED} == "true" ]]; then + log_warn "Ruff can replace isort, Bandit, Pylint" fi # Ruff is self dependent tool (written in Rust), it can be installed without project dependencies (_pip and _run don't look required here) - pip install ${PIP_OPTS} ruff @@ -1072,10 +1073,10 @@ py-ruff: - | if [[ "$SONAR_HOST_URL" ]] then - ruff check . ${RUFF_ARGS} ${RUFF_EXCLUDE:---extend-exclude .venv,.cache} --exit-zero --output-format json --output-file reports/py-ruff.native.json + ruff check . ${RUFF_ARGS} --extend-exclude .venv,.cache --exit-zero --output-format json --output-file reports/py-ruff.native.json fi # then GitLab and grouped/console formats - - ruff check . ${RUFF_ARGS} ${RUFF_EXCLUDE:---extend-exclude .venv,.cache} --output-format gitlab --output-file reports/py-ruff.gitlab.json || ruff check . ${RUFF_ARGS} ${RUFF_EXCLUDE:---extend-exclude .venv,.cache} --output-format grouped + - ruff check . ${RUFF_ARGS} --extend-exclude .venv,.cache --output-format gitlab --output-file reports/py-ruff.gitlab.json || ruff check . ${RUFF_ARGS} --extend-exclude .venv,.cache --output-format grouped artifacts: name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" expire_in: 1 day @@ -1090,6 +1091,24 @@ py-ruff: when: never - !reference [.test-policy, rules] +py-ruff-format: + extends: .python-base + stage: build + script: + - mkdir -p -m 777 reports + - | + if [[ ${PYTHON_BLACK_ENABLED} == "true" ]]; then + log_warn "Ruff can replace Black" + fi + # Ruff is self dependent tool (written in Rust), it can be installed without project dependencies (_pip and _run don't look required here) + - pip install ${PIP_OPTS} ruff + - ruff format --check . --exclude .venv,.cache + rules: + # exclude if $RUFF_FORMAT_ENABLED not set + - if: '$RUFF_FORMAT_ENABLED != "true"' + when: never + - !reference [.test-policy, rules] + py-mypy: extends: .python-base stage: build