Commit a8c0740b authored by Gaëtan Montury's avatar Gaëtan Montury
Browse files

fix: cherry pick from fix/avoid-extend-exclude, so manage ignore .cache with .gitignore

- change black-args to .
- change mypy-args to --exclude-gitignore
- ruff ignore manage by .gitignore
- black ignore manage by .gitignore
add TRACE to many command
parent 1f0a155a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -344,7 +344,7 @@ This job **disabled by default** and runs [black](https://black.readthedocs.io)
| Input / Variable | Description                                                             | Default value     |
| ---------------- | ----------------------------------------------------------------------- | ----------------- |
| `black-enabled` / `PYTHON_BLACK_ENABLED` | Set to `true` to enable black job               | _none_ (disabled) |
| `black-args` / `PYTHON_BLACK_ARGS`     | Additional [black options](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html) | _none_ |
| `black-args` / `PYTHON_BLACK_ARGS`     | Additional [black options](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html) | . |

### `py-isort` job

@@ -393,7 +393,7 @@ It is bound to the `build` stage, and uses the following variables:
| Input / Variable         | Description                        | Default value     |
| ------------------------ | ---------------------------------- | ----------------- |
| `mypy-enabled` / `MYPY_ENABLED` | Set to `true` to enable the `mypy` job                  | _none_ (disabled) |
| `mypy-args` / `MYPY_ARGS` | Additional [mypy CLI options](https://mypy.readthedocs.io/en/stable/command_line.html) | _none_           |
| `mypy-args` / `MYPY_ARGS` | Additional [mypy CLI options](https://mypy.readthedocs.io/en/stable/command_line.html) | --exclude /.cache/ --exclude /.venv/ |
| `mypy-files` / `MYPY_FILES` | Files or directories to analyse   | . |

In addition to a textual report in the console, this job produces the following reports, kept for one day:
+2 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@
        {
          "name": "PYTHON_BLACK_ARGS",
          "description": "Additional [black options](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html)",
          "default": "",
          "default": ".",
          "advanced": true
        }
      ]
@@ -332,6 +332,7 @@
        {
          "name": "MYPY_ARGS",
          "description": "Additional [mypy CLI options](https://mypy.readthedocs.io/en/stable/command_line.html)",
          "default": "--exclude /.cache/ --exclude /.venv/",
          "advanced": true
        },
        {
+27 −26
Original line number Diff line number Diff line
@@ -180,7 +180,7 @@ spec:
      default: false
    black-args:
      description: Additional [black options](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html)
      default: ''
      default: '.'
    isort-enabled:
      description: Enable isort
      type: boolean
@@ -205,7 +205,8 @@ spec:
      default: false
    mypy-args:
      description: Additional [mypy CLI options](https://mypy.readthedocs.io/en/stable/command_line.html)
      default: ""
      default: "--exclude /.cache/ --exclude /.venv/"  
      # As of October 2025, we should normally want to use --exclude-gitignore, but the option was added too recently  
    mypy-files:
      description: Files or directories to analyse
      default: '.'
@@ -775,7 +776,7 @@ variables:
    if ! command -v "$PYTHON_BUILD_SYSTEM_CMD" > /dev/null
    then
      # shellcheck disable=SC2086
      pip install ${PIP_OPTS} "$PYTHON_BUILD_SYSTEM"
      pip install ${TRACE+--verbose} ${PIP_OPTS} "$PYTHON_BUILD_SYSTEM"
    fi
  }

@@ -789,34 +790,34 @@ variables:
        log_warn "Using Poetry but \\e[33;1mpoetry.lock\\e[0m file not found: you shall commit it with your project files"
      fi
      maybe_install_build_system
      poetry install ${PYTHON_EXTRA_DEPS:+--extras "$PYTHON_EXTRA_DEPS"}
      poetry install ${TRACE+--verbose} ${PYTHON_EXTRA_DEPS:+--extras "$PYTHON_EXTRA_DEPS"}
      ;;
    setuptools*)
      maybe_install_build_system
      # shellcheck disable=SC2086
      pip install ${PIP_OPTS} ".${PYTHON_EXTRA_DEPS:+[$PYTHON_EXTRA_DEPS]}"
      pip install ${TRACE+--verbose} ${PIP_OPTS} ".${PYTHON_EXTRA_DEPS:+[$PYTHON_EXTRA_DEPS]}"
      ;;
    pipenv*)
      maybe_install_build_system
      if  [[ ! -f "Pipfile.lock" ]]; then
        log_warn "Using Pipenv but \\e[33;1mPipfile.lock\\e[0m file not found: you shall commit it with your project files"
        pipenv install --dev --system
        pipenv install ${TRACE+--verbose} --dev --system
      else
        pipenv sync --dev --system
        pipenv sync ${TRACE+--verbose} --dev --system
      fi
      ;;
    reqfile)
      if [[ -f "${PYTHON_REQS_FILE}" ]]; then
        log_info "--- installing main requirements from \\e[33;1m${PYTHON_REQS_FILE}\\e[0m"
        # shellcheck disable=SC2086
        pip install ${PIP_OPTS} -r "${PYTHON_REQS_FILE}"
        pip install ${TRACE+--verbose} ${PIP_OPTS} -r "${PYTHON_REQS_FILE}"
        # shellcheck disable=SC2086
        found_reqs_files=$(eval ls -1 $PYTHON_EXTRA_REQS_FILES 2>/dev/null || echo "")
        # shellcheck disable=SC2116
        for extrareqsfile in $(echo "$found_reqs_files"); do
          log_info "--- installing extra requirements from \\e[33;1m${extrareqsfile}\\e[0m"
          # shellcheck disable=SC2086
          pip install ${PIP_OPTS} -r "${extrareqsfile}"
          pip install ${TRACE+--verbose} ${PIP_OPTS} -r "${extrareqsfile}"
        done
      else
        log_warn "--- requirements build system defined, but no ${PYTHON_REQS_FILE} file found"
@@ -827,15 +828,15 @@ variables:
        log_warn "Using uv but \\e[33;1muv.lock\\e[0m file not found: you shall commit it with your project files"
      fi
      maybe_install_build_system
      uv sync --frozen ${PYTHON_EXTRA_DEPS:+--extra "$PYTHON_EXTRA_DEPS"}
      uv sync ${TRACE+--verbose} --frozen ${PYTHON_EXTRA_DEPS:+--extra "$PYTHON_EXTRA_DEPS"}
      ;;
    hatch*)
      maybe_install_build_system
      hatch env create
      hatch env create ${TRACE+--verbose}
      ;;
    pdm*)
      maybe_install_build_system
      pdm sync --dev ${PYTHON_EXTRA_DEPS:+--extra "$PYTHON_EXTRA_DEPS"}
      pdm sync ${TRACE+--verbose} --dev ${PYTHON_EXTRA_DEPS:+--extra "$PYTHON_EXTRA_DEPS"}
      ;;
    esac

@@ -866,10 +867,10 @@ variables:
    then
      maybe_install_build_system
      # shellcheck disable=SC2086
      uv pip "$cmd" ${PIP_OPTS} "$@"
      uv pip ${TRACE+--verbose} "$cmd" ${PIP_OPTS} "$@"
    else
      # shellcheck disable=SC2086
      _run pip "$cmd" ${PIP_OPTS} "$@"
      _run pip ${TRACE+--verbose} "$cmd" ${PIP_OPTS} "$@"
    fi
  }

@@ -888,7 +889,7 @@ variables:
      hatch*)
        maybe_install_build_system
        log_info "--- build packages (hatch)..."
        $PYTHON_BUILD_SYSTEM_CMD build
        $PYTHON_BUILD_SYSTEM_CMD build ${TRACE+--verbose}
        ;;
      pdm*)
        maybe_install_build_system
@@ -1025,11 +1026,11 @@ variables:
      then
        py_cur_version=$(hatch version)
        log_info "[hatch version] increase \\e[1;94m${PYTHON_RELEASE_NEXT}\\e[0m (from current \\e[1;94m${py_cur_version}\\e[0m)"
        hatch version "$PYTHON_RELEASE_NEXT"
        hatch version ${TRACE+--verbose} "$PYTHON_RELEASE_NEXT"
        py_next_version=$(hatch version)
      else
        log_info "[hatch] change version \\e[1;94m${py_cur_version}\\e[0m → \\e[1;94m${py_next_version}\\e[0m"
        hatch version "$py_next_version"
        hatch version ${TRACE+--verbose} "$py_next_version"
      fi

      py_git_tag_commit_release_change "$py_cur_version" "$py_next_version"
@@ -1243,7 +1244,7 @@ py-lint:
    - install_requirements
    - _pip install pylint_gitlab # codeclimate reports
    # run pylint and generate reports all at once
    - _run pylint --output-format=colorized,pylint_gitlab.GitlabCodeClimateReporter:reports/py-lint.codeclimate.json,parseable:reports/py-lint.parseable.txt ${PYLINT_ARGS} ${PYLINT_FILES} --ignore-paths=\.venv/,\.cache/ || exit_code=$?
    - _run pylint ${TRACE+--verbose} --output-format=colorized,pylint_gitlab.GitlabCodeClimateReporter:reports/py-lint.codeclimate.json,parseable:reports/py-lint.parseable.txt ${PYLINT_ARGS} ${PYLINT_FILES} --ignore-paths=\.venv/,\.cache/ || exit_code=$?
    # check pylint exit code against $PYLINT_SEVERITY
    - |
      if [[ "${exit_code:-0}" == "0" ]]
@@ -1303,7 +1304,7 @@ py-black:
  script:
    - install_requirements
    - _pip install black
    - _run black . --check --extend-exclude '(\/\.cache\/|\/\.venv\/)' ${PYTHON_BLACK_ARGS}
    - _run black ${TRACE+--verbose} --check ${PYTHON_BLACK_ARGS}
  rules:
    # exclude if $PYTHON_BLACK_ENABLED not set
    - if: '$PYTHON_BLACK_ENABLED != "true"'
@@ -1316,7 +1317,7 @@ py-isort:
  script:
    - install_requirements
    - _pip install isort
    - _run isort --check-only --extend-skip .cache --extend-skip .venv ${PYTHON_ISORT_ARGS}
    - _run isort ${TRACE+--verbose} --check-only --extend-skip .cache --extend-skip .venv ${PYTHON_ISORT_ARGS}
  rules:
    # exclude if $PYTHON_ISORT_ENABLED not set
    - if: '$PYTHON_ISORT_ENABLED != "true"'
@@ -1338,10 +1339,10 @@ py-ruff:
    - |
      if [[ "$SONAR_HOST_URL" ]]
      then
        ruff check ${RUFF_ARGS} --extend-exclude .venv,.cache --exit-zero --output-format json --output-file reports/py-ruff.native.json
        ruff check ${TRACE+--verbose} ${RUFF_ARGS} --exit-zero --output-format json --output-file reports/py-ruff.native.json
      fi
    # then GitLab and grouped/console formats
    - 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
    - ruff check ${TRACE+--verbose} ${RUFF_ARGS} --output-format gitlab --output-file reports/py-ruff.gitlab.json || ruff check ${RUFF_ARGS} --output-format grouped
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
@@ -1366,7 +1367,7 @@ py-ruff-format:
      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
    - ruff format ${TRACE+--verbose} --check # TODO RUFF_FORMAT_ARGS
  rules:
    # exclude if $RUFF_FORMAT_ENABLED not set
    - if: '$RUFF_FORMAT_ENABLED != "true"'
@@ -1382,7 +1383,7 @@ py-mypy:
    - mkdir -p -m 777 reports
    - install_requirements
    - _pip install mypy mypy-to-codeclimate
    - _run mypy ${MYPY_ARGS} ${MYPY_FILES} --exclude /.cache/ --exclude /.venv/ | tee reports/py-mypy.console.txt || true
    - _run mypy ${TRACE+--verbose} ${MYPY_ARGS} ${MYPY_FILES} | tee reports/py-mypy.console.txt || true
    # mypy-to-codeclimate will fail if any error was found
    - _run mypy-to-codeclimate reports/py-mypy.console.txt reports/py-mypy.codeclimate.json
  artifacts:
@@ -1406,7 +1407,7 @@ py-basedpyright:
    - mkdir -p -m 777 reports
    - install_requirements
    - _pip install basedpyright
    - _run basedpyright --level ${PYRIGHT_LEVEL} --gitlabcodequality reports/py-basedpyright.codeclimate.json ${PYRIGHT_ARGS}
    - _run basedpyright ${TRACE+--verbose} --level ${PYRIGHT_LEVEL} --gitlabcodequality reports/py-basedpyright.codeclimate.json ${PYRIGHT_ARGS}
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
@@ -1449,7 +1450,7 @@ py-pytest:
    - mkdir -p -m 777 reports
    - install_requirements
    - _pip install pytest pytest-cov coverage
    - _run pytest --junit-xml=reports/TEST-pytests.xml --cov --cov-report term  --cov-report xml:reports/py-coverage.cobertura.xml ${PYTEST_ARGS}
    - _run pytest ${TRACE+--verbose} --junit-xml=reports/TEST-pytests.xml --cov --cov-report term  --cov-report xml:reports/py-coverage.cobertura.xml ${PYTEST_ARGS}
  rules:
    # skip if $PYTEST_ENABLED not set
    - if: '$PYTEST_ENABLED != "true"'