Useful tools
Kadi CLI
The Kadi command line interface (CLI) contains various useful tools and utilities as part of mulitple subcommands and is available automatically after installing the package. An overview over all commands can be obtained by simply running:
kadi
The Kadi CLI ensures that each subcommand runs inside the context of the application, which is why it always needs access to the correct Kadi4Mat environment and, if applicable, configuration file. Please see the Kadi4Mat configuration section in the development installation instructions for a reminder. For this reason, some subcommands are simply wrappers over existing ones provided by other libraries, making their use in certain scenarios or environments easier. See also cli.
virtualenvwrapper
virtualenvwrapper is an extension to the Virtualenv tool and can be used to manage and switch between multiple virtual environments more easily. The tool can be installed globally via pip while not having any virtual environment currently active:
pip3 install virtualenvwrapper
Afterwards, some environment variables have to be set. Generally, a suitable place for
them is the ~/.bashrc
file. An example could look like the following:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=${HOME}/.venvs
source ${HOME}/.local/bin/virtualenvwrapper.sh
Please refer to the official documentation about their meaning as well as other possible variables that can be used, as their values differ by system and personal preference.
EditorConfig
For general editor settings related to indentation, maximum line length and line
endings, the settings in the .editorconfig
file can be applied. This file can be
used in combination with a text editor or IDE that supports it. For more information,
take a look at the EditorConfig documentation.
pre-commit
pre-commit is a framework for managing and maintaining
multi-language pre-commit hooks, which get executed each time git commit
is run. The
tool itself should be installed already. The hooks listed in .pre-commit-config.yaml
can be installed by simply running:
pre-commit install
The hooks can also be run manually on all versioned and indexed files using:
pre-commit run -a
The versions of all hooks can be updated automatically by running:
pre-commit autoupdate
black
black is a code formatter which is used throughout all Python code in the project. The tool itself should be installed already and can be applied on one or multiple files using:
black <path>
Besides running black on the command line, there are also various integrations available for different text editors and IDEs. black is also part of the pre-commit hooks. As such, it will run automatically on each commit or when running the pre-commit hooks manually.
isort
isort is another kind of code formatter with focus on sorting and grouping import statements throughout all Python code in the project. The tool itself should be installed already and can be applied on one or multiple files using:
isort <path>
isort will automatically use the configuration specified in the [tool.isort]
section
inside pyproject.toml
. Similar to black, various integrations are available for
different text editors and IDEs. Furthermore, isort is part of the pre-commit hooks and
will run automatically on each commit or when running the pre-commit hooks manually.
autoflake
autoflake is a tool mainly used to help with
the common case of removing unused import statements. The tool itself should be
installed already and can be applied on one or multiple files (via the -r
flag)
using:
autoflake -i -r <path>
autoflake will automatically use the configuration specified in the [tool.autoflake]
section inside pyproject.toml
. As it also is part of the pre-commit hooks, there is
usually no need to run it manually. However, it may be necessary to exclude certain
files or imports, which can be achieved with one of the options shown in the following
example:
# autoflake: skip_file
import unused_import # noqa
Pylint
Pylint is a static code analysis tool for Python and
should already be installed as well. It can be used on the command line to aid with
detecting some common programming or style mistakes, even if not using an IDE that
already does that. For example, linting the whole kadi
package can be done by
running the following command:
pylint kadi
Pylint will automatically use the configuration specified in the [tool.pylint.*]
sections inside pyproject.toml
. Sometimes, there might be certain code that should
never be checked for various things. Using specific comments, one can instruct Pylint to
skip such code, e.g. the following line will not raise a message for an unused import
statement:
import something # pylint: disable=unused-import
ESLint
ESLint is a linter and basic code formatter which is used for
all JavaScript code throughout the project, including any code snippets inside script
tags and Vue.js components. It should be already installed and can be applied on the
whole kadi
folder using the eslint
script exposed by the npm
command. Note
that npm needs access to the package.json
file, see also the section about
managing frontend dependencies.
npm run eslint kadi
ESLint will automatically use the configuration specified in eslint.config.cjs
.
Besides running ESlint on the command line, there are also various integrations available for different text
editors and IDEs. Some files also contain code that should never be checked for certain
things. Using specific comments again, one can instruct ESLint to skip such code, e.g.
the following will suppress errors for unused variables in the specified function:
/* eslint-disable no-unused-vars */
function foo(a) {}
/* eslint-enable no-unused-vars */
// eslint-disable-next-line no-unused-vars
function foo(a) {}
ESLint is also part of the pre-commit hooks. As such, it will run automatically on each commit or when running the pre-commit hooks manually.