Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: add pre-commit config #582

Merged
merged 3 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ env/*
tests/htmlcov/*
.DS_Store
.python-version
.pre-commit-config.yaml
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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.
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: ["."]
Comment on lines +8 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not forced to worry about this so it's not a big deal... but:

  • is it a good idea to have two slightly different sets of linting passes (tox -e lint and this pre-commit list)?
  • do we understand the dependency chains here? I assume black and isort hooks depend on already installed tools (or does pre-commit install magically install them from somewhere?)... but what about the "builtin" hooks? Do they use code embedded in the pre-commit package?
  • are we in trouble when we inevitably forget to update these versions? I suppose not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it a good idea to have two slightly different sets of linting passes (tox -e lint and this pre-commit list)?

I don't see a big problem there. Config is the same for both. Differences would mainly come from different versions of black && isort. But tox -e lint on CI is the ultimate authority.

do we understand the dependency chains here? I assume black and isort hooks depend on already installed tools (or does pre-commit install magically install them from somewhere?)... but what about the "builtin" hooks? Do they use code embedded in the pre-commit package?

I admit, I don't exactly know where pre-commit installs the dependencies, but I suppose in some virtual environment. It claims that "python hooks work without any system-level dependencies".

are we in trouble when we inevitably forget to update these versions? I suppose not?

I don't think, we are. But yeah, it would be nice to automate updates. There are some 3rd-party solutions to do this, and a feature request for Dependabot.

10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"]
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down