diff --git a/README.md b/README.md index 8e7250ffad1124aa0d4f524ec63a704c8a42f633..3d633b3c4e847484a28e11bdb68fdf00d5fd3eec 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,15 @@ This job **disabled by default** and runs [black](https://black.readthedocs.io) | ---------------- | ----------------------------------------------------------------------- | ----------------- | | `black-enabled` / `PYTHON_BLACK_ENABLED` | Set to `true` to enable black job | _none_ (disabled) | +### `py-isort` job + +This job **disabled by default** and runs [isort](https://pycqa.github.io/isort/) on the repo. It is bound to the build stage. + +| Input / Variable | Description | Default value | +| ---------------- | ----------------------------------------------------------------------- | ----------------- | +| `isort-enabled` / `PYTHON_ISORT_ENABLED` | Set to `true` to enable isort job | _none_ (disabled) | + + ### SonarQube analysis If you're using the SonarQube template to analyse your Python code, here is a sample `sonar-project.properties` file: diff --git a/kicker.json b/kicker.json index 54b83d468b6236175dac27d579309bb861367d88..8ec4b4564901eca6193f79a01d99416f03bb3275 100644 --- a/kicker.json +++ b/kicker.json @@ -246,6 +246,12 @@ "name": "black", "description": "Code formatting based on [black](https://black.readthedocs.io)", "enable_with": "PYTHON_BLACK_ENABLED" + }, + { + "id": "isort", + "name": "isort", + "description": "Check imports order with [isort](https://pycqa.github.io/isort)", + "enable_with": "PYTHON_ISORT_ENABLED" } ], "variants": [ diff --git a/templates/gitlab-ci-python.yml b/templates/gitlab-ci-python.yml index c938018a66d9d494929d5decf8b7a80feac7f93e..680bd42bb216b51f9f6684aecf8c166794a35c6f 100644 --- a/templates/gitlab-ci-python.yml +++ b/templates/gitlab-ci-python.yml @@ -151,6 +151,10 @@ spec: description: Enable black type: boolean default: false + isort-enabled: + description: Enable isort + type: boolean + default: false --- # default workflow rules: Merge Request pipelines workflow: @@ -265,6 +269,7 @@ variables: PYTHON_RELEASE_ENABLED: $[[ inputs.release-enabled ]] PYTHON_BLACK_ENABLED: $[[ inputs.black-enabled ]] + PYTHON_ISORT_ENABLED: $[[ inputs.isort-enabled ]] .python-scripts: &python-scripts | @@ -879,6 +884,19 @@ py-black: when: never - !reference [.test-policy, rules] +py-isort: + extends: .python-base + stage: build + script: + - install_requirements + - _pip install isort + - _run isort . --check-only + rules: + # exclude if $PYTHON_ISORT_ENABLED not set + - if: '$PYTHON_ISORT_ENABLED != "true"' + when: never + - !reference [.test-policy, rules] + ############################################################################################### # test stage # ###############################################################################################