We run our Pants formatting/linting via pre-commit...
# general
h
We run our Pants formatting/linting via pre-commit (which has various other issues that I won’t get into) and have had a few occasions where files passed to Pants from pre-commit were in the various explicit-ignore lists that Pants has so we’d get a glob catch failure. Would it be possible to have a
--filter-files
option similar to https://pycqa.github.io/isort/docs/configuration/options#filter-files that would tell Pants to filter the files it’s being passed. Currently, we need to ensure all files passed to Pants aren’t being ignored and can be handled.
w
Can you show an example of what's currently going on? By pre-commit, I'm assuming you mean the tool (https://pre-commit.com/) not the githook itself? So, what ends up happening is that you're getting a bunch of loose filenames passed to pants that you format/lint?
h
pre-commit run
will run on changed files between two commit refs. In our pre-commit config we have a hook for
pants lint
which pre-commit appends files to when ran e.g.
pants lint dir/file1.py main.py
. The issue we had was that the
.github
dir used to be ignored by default by Pants, but pre-commit would still pick up changed files within that dir for markdown formatting, for instance. So this file would be passed to pants from pre-commit like
pants lint .github/TEMPLATE.MD
which would result in a Pants glob error as that file “couldn’t be found” since it was being ignored. Simplest solution here was to just tell Pants to not ignore that dir, which is the default in current Pants version, but that’s beside the point. I could see this being an issue for other scenarios where Pants is passed files (by pre-commit or other). Which is presumably why linters have these
--filter-files
options? Thoughts?
w
I've have to give it some thought - as I've never considered what happens when you explicitly pass an ignored file into a pants command. I feel like there is some sort of introspection construct that could help out here: https://www.pantsbuild.org/2.21/docs/using-pants/project-introspection Not a great solution, but off the top of my head - Is there any way to leverage pant's
--changed-since
behavior and call that from pre-commit?
pants --changed-since=origin/main lint
kinda thing?
h
Is there any way to leverage pant’s
--changed-since
behavior and call that from pre-commit?
pants --changed-since=origin/main lint
kinda thing?
Yes, that was an alternative option - to pass the from/to refs that pre-commit would use to pants’
—changed-since
option. But it would be nice to not have to duplicate this. I can imagine this feature would be useful for other cases where it’s not as easy to replicate the files that may be being passed to Pants by other tools.