From 6cfae3e9c8ea2f17f2634a33d5d01b1253195051 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Mon, 22 May 2023 10:41:31 +0200 Subject: [PATCH 1/3] lint: move black/pylint config to pyproject.toml This allows re-using the same config in tox and other tools, e.g. pre-commit. Signed-off-by: Lukas Puehringer --- pyproject.toml | 10 ++++++++++ tox.ini | 6 ++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6efabb2e..d837955d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,3 +64,13 @@ include = [ "/CHANGELOG.md", "/.coveragerc", ] + +[tool.black] +line-length=80 +extend-exclude="_vendor" + +[tool.isort] +profile="black" +line_length=80 +known_first_party = ["securesystemslib"] +extend_skip_glob=["*/_vendor/*"] diff --git a/tox.ini b/tox.ini index 80bb870b..805aefbd 100644 --- a/tox.ini +++ b/tox.ini @@ -72,10 +72,8 @@ deps = -r{toxinidir}/requirements-pinned.txt -r{toxinidir}/requirements-lint.txt commands = - # TODO: Move configs to pyproject.toml - black --check --diff --line-length=80 --extend-exclude=_vendor . - isort --check --diff --line-length=80 --extend-skip-glob='*/_vendor/*' \ - --profile=black --project=securesystemslib . + black --check --diff . + isort --check --diff . pylint -j 0 --rcfile=pylintrc securesystemslib tests bandit --recursive securesystemslib --exclude _vendor From 6d87825f54070190b340b371b2b54cc616cfcdb5 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Mon, 22 May 2023 11:17:44 +0200 Subject: [PATCH 2/3] lint: add pre-commit config Add basic pre-commit config file, with hooks for black and isort, plus two convenient builtin checkers. Also adds pre-commit to dev requirements and removes the config file name from .gitignore Caveat: hooks in config file must be manually initialzed and updated, e.g. with the following commands: ``` pre-commit install pre-commit autoupdate ``` Signed-off-by: Lukas Puehringer --- .gitignore | 1 - .pre-commit-config.yaml | 24 ++++++++++++++++++++++++ requirements-dev.txt | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.gitignore b/.gitignore index 087afc91..974c41f6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,3 @@ env/* tests/htmlcov/* .DS_Store .python-version -.pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..6b695e9b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +# Automatically run checks over changed files prior to `git commit`. +# Required one-time setup: +# +# pre-commit install +# +# See https://pre-commit.com for details. +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + args: ["."] + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["."] diff --git a/requirements-dev.txt b/requirements-dev.txt index e1c12e9a..8713c2ce 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,6 +2,7 @@ # requirements for local testing with tox, and also for the running test suite # or individual tests manually tox +pre-commit -r requirements.txt -r requirements-test.txt -r requirements-lint.txt From 1863002b83c1d70078d35c37d3c8f1cd4d73a558 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Wed, 24 May 2023 15:26:55 +0200 Subject: [PATCH 3/3] lint: remove pre-commit dev requirement pre-commit is optional for devs, we should not make everyone install it. Signed-off-by: Lukas Puehringer --- .pre-commit-config.yaml | 1 + requirements-dev.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6b695e9b..63a86a3f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,7 @@ # Automatically run checks over changed files prior to `git commit`. # Required one-time setup: # +# pip install pre-commit # pre-commit install # # See https://pre-commit.com for details. diff --git a/requirements-dev.txt b/requirements-dev.txt index 8713c2ce..e1c12e9a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,7 +2,6 @@ # requirements for local testing with tox, and also for the running test suite # or individual tests manually tox -pre-commit -r requirements.txt -r requirements-test.txt -r requirements-lint.txt