cki_lint.sh
Overview
The cki_lint.sh script supports two modes of operation:
Code Linting (default)
Runs flake8 and ruff. The
script automatically handles environment preparation including dependency
installation via pip. Ruff checks and sorts import order (see [lint.isort] in
ruff.toml). For pylint, only the packages specified as parameters
will be checked.
The experimental --fix parameter can be used to automatically fix some of the
detected issues. At the moment, this will invoke autopep8 and ruff --fix
(which includes import sorting).
Markdown Linting
Performs linting and link checking for markdown files. It uses the markdownlint tool to check for markdown errors and lychee to check for broken links in all markdown files.
Markdownlint uses the repo .markdownlint.yaml when present; otherwise it
downloads the cki-lib default from production (same pattern as ruff.toml).
Usage
# Code linting (default mode)
cki_lint.sh [code] <package_name>
# Markdown linting with explicit mode
cki_lint.sh markdownlint <glob_pattern>
# Using environment variables
CKI_LINT_MODE=markdownlint CKI_MARKDOWN_GLOB="**/*.md" cki_lint.sh
# Show help
cki_lint.sh help
For correct editor integration of linters/fixers, the following parameters must be set:
flake8:--max-line-length 100autopep8:--max-line-length 100- Import order is enforced by ruff (see
ruff.toml[lint.isort]).
When run in a GitLab CI/CD pipeline for a merge request, the script tries to
determine the previous code coverage and will fail if code coverage decreased.
This can be skipped by adding [skip coverage check] with an explanation to
the merge request description.
Automatic Preparation
The script automatically sources and executes cki_prepare.sh to handle dependency
installation, version management, and package overrides. This includes automatic
cki-lib version checking in CI/MR environments and support for custom package
overrides via *_pip_url environment variables.
For detailed information about preparation and environment variables, see the cki_prepare documentation.
For a comprehensive overview of the entire linting and testing pipeline, see the cki tox pipeline documentation.
Environment variables
Mode Control
| Environment variable | Description |
|---|---|
CKI_LINT_MODE |
Set to code or markdownlint to specify the linting mode |
CKI_MARKDOWN_GLOB |
Glob pattern for markdown files (default: **/README.*.md) |
Linting Control
| Environment variable | Description |
|---|---|
CKI_DISABLED_LINTERS |
linters to disable or all |
CKI_IGNORED_LINTERS |
space-separated list of linters where results are ignored, or all |
CKI_PYLINT_ARGS |
Additional arguments for pylint, e.g. to disable certain warnings |
Preparation Control
| Environment variable | Description |
|---|---|
CKI_SKIP_PREPARE |
true if Python package installation should be skipped |
cki_lib_pip_url |
Override cki-lib with custom Git URL (see cki_prepare docs) |
NOTE
CKI_SKIP_PREPARE=true can be useful to run checks without network.
When using tox, you should probably call: tox --skip-pkg-install;
when using podman, you should probably call podman run --net none ...args....
Running Python tests and code linting
To run both Python tests and linting, execute the following command:
tox
To run only code linting, use the lint tox environment:
tox -e lint
Running markdown linting
To run only markdown linting, use the markdownlint mode:
cki_lint.sh markdownlint "**/README.*.md"
Disabling linters
To skip certain linters, specify them in the CKI_DISABLED_LINTERS variable as a
space-separated list. For example:
TOX_OVERRIDE=tool.tox.env_run_base.pass_env+=CKI_DISABLED_LINTERS \
CKI_DISABLED_LINTERS="flake8 pylint" \
tox -e lint
The above command skips the flake8 and pylint linters when running
tox.