From ed8a06bcb3541235e2c47e01249fc801382b06cf Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Tue, 30 Nov 2021 16:40:44 +0200 Subject: [PATCH] Move part of isort options in pyproject.toml We are using 4 linters: black, isort, pylint and mypy. It's good if we use one file as a source for truth for all linter configurations. I tried multiple ways to use the src_path option, so we can just call isort without pointing out the target folders, but I was not successful. I tried running isort with "isort --settings-path=pyproject.toml" I got the error: "Error: arguments passed in without any paths or content." Additionally, I saw one project with source configuration https://github.com/Pylons/pyramid/blob/master/pyproject.toml, but they had to give explicit folders too https://github.com/Pylons/pyramid/blob/8061fce297cc7117d3e6e2b39e47512c7db2904f/tox.ini#L26 and https://github.com/Pylons/pyramid/blob/8061fce297cc7117d3e6e2b39e47512c7db2904f/tox.ini#L66 It was a similar situation with "check" and "diff". In the documentation it's said that for both check and diff are not supported in configuration files. See: - https://pycqa.github.io/isort/docs/configuration/options.html#check - https://pycqa.github.io/isort/docs/configuration/options.html#show-diff Additionally, in two issues it was confirmed that in integration tests we should use --check and --diff the way we did until now. As a result, I moved part of the configuration options for isort inside pyproject.toml without the actual directories that need to be linted and "check" and "diff" options. Signed-off-by: Martin Vrachev --- docs/CONTRIBUTORS.rst | 3 +-- pyproject.toml | 7 +++++++ tox.ini | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/CONTRIBUTORS.rst b/docs/CONTRIBUTORS.rst index bf685941..54ef8a8d 100644 --- a/docs/CONTRIBUTORS.rst +++ b/docs/CONTRIBUTORS.rst @@ -113,9 +113,8 @@ CI/CD will check that new TUF code is formatted with `black Auto-formatting can be done on the command line: :: - $ # TODO: configure black and isort args in pyproject.toml (see #1161) $ black - $ isort --line-length 80 --profile black -p tuf tuf/api + $ isort or via source code editor plugin [`black `__, diff --git a/pyproject.toml b/pyproject.toml index be5e7238..339f2416 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,6 +8,13 @@ build-backend = "setuptools.build_meta" [tool.black] line-length=80 +# Isort section +# Read more here: https://pycqa.github.io/isort/docs/configuration/config_files.html +[tool.isort] +profile="black" +line_length=80 +known_first_party = ["tuf"] + # Pylint section # Minimal pylint configuration file for Secure Systems Lab Python Style Guide: diff --git a/tox.ini b/tox.ini index b06150ea..a6e0d765 100644 --- a/tox.ini +++ b/tox.ini @@ -40,9 +40,8 @@ commands = changedir = {toxinidir} commands = # Use different configs for new (tuf/api/*) and legacy code - # TODO: configure black and isort args in pyproject.toml (see #1161) black --check --diff tuf/api tuf/ngclient - isort --check --diff --line-length 80 --profile black -p tuf tuf/api tuf/ngclient + isort --check --diff tuf/api tuf/ngclient pylint -j 0 tuf/api tuf/ngclient --rcfile=pyproject.toml # NOTE: Contrary to what the pylint docs suggest, ignoring full paths does