When using `pyproject.toml` for `black` configurat...
# general
When using
configuration, is there a way to run
only against the file patterns in the
Hey Nick, I think that gets overridden because Pants specifies each file explicitly to run against What's your use case? Possibly relevant: There's a new feature in 2.5.0 that you can add skip_black=True to python_library and python_tests targets to opt out of Black. Altho that's a blocklist, not allowlist
Hey Eric, yeah that's what I suspected. Our use case is to do a soft rollout of formatting on a mono repo. We would only like
to run a specific set of files described in the
regex. I'll bump to
give your suggestion a try. The block list should be fine for now.
Great! Yeah this feature was added for precisely this reason. You'll want to use the latest, 2.5.0rc0
Okay this works thank you! However, I have to groom over a lot of different BUILD files to apply this change. It would be great if this could somehow be captured in the tailor command (e.g. apply
by default). Or is there another solution for this you can recommend?
The solution we want to give is to merge metadata, so that (totally strawman design) you could set something like:
Copy code
  "**/*.py": {"skip_black": True},
  "some_specific_file.py: {"skip_flake8": True},
But that is an enormous project to re-envision targets, which we want to do but is on the backburner atm to focus on what users prioritized for 2021: https://groups.google.com/u/1/g/pants-devel/c/F8Saug3BrFw/m/ZtWDP4YmDwAJ In the meantime, unfortunately no 😕 You can use far fewer targets with
, but we've found that one target per directory usually works best. https://www.pantsbuild.org/docs/targets#target-granularity-for-first-party-code
👍 1
But that is an enormous project to re-envision targets, which we want to do
(the awkwardness of targets is I think my biggest qualm with Pants atm)
okay got it and that sounds like a good long term solution. For now, could the filter goal somehow help here? Maybe grab targets by regex then pass those to the
goal directly?
Oh yeah, you could do that with
filter --address-regex
for example. But then you need to remember to run that specific command, and doing
./pants fmt ::
will do the wrong thing A goal of Pants is to empower you to move away from bash scripts like needing to run
for example, that
./pants fmt ::
should do The Right Thing
Okay understood. The goal for our project is to have black run on all targets eventually but may not be out of the door. Let me give the filter command a shot and hopefully that should solve our use case for now (then just throw that away and just use
./pants fmt ::
once were ready)
👍 1
so the
via CLI doesn't like my regexes 😅. I see the tests here: https://github.com/pantsbuild/pants/blob/d9ec8acbe867299bda9465ff4200116fc39bbab9/src/python/pants/backend/project_info/filter_targets_test.py#L[…]3 how would the CLI command look for a regex on
I suspect missing the quote?
./pants filter --address-regex='^src/python/pants/util' ::
omg no I was missing
haha yes this works now thank you!
🤘 1
If you're interested, it'd be great to add a warning to
./pants filter
like we have with
./pants list
Copy code
❯ ./pants list
WARNING: No targets were matched in goal `list`.
It's 3 lines of code: https://github.com/pantsbuild/pants/blob/bcc5a8499a8230c08055b314f70fe5c60b5970dc/src/python/pants/backend/project_info/list_targets.py#L53-L55 We'd welcome a patch 🙂 Lmk, there are 2 tweaks I'd suggest we do
Yes this is a great idea and I'd be more than happy to contribute!
🙌 1
Yay! So the two tweaks for
are: 1. Rather than using
, I think it makes sense to use
. That's how we always do warnings with that
prefix. To do that,
import logging
and near top of the file set
logger = logging.getLogger(__name__)
2. The wording is not as clear as it should be imo. I thought what it was trying to get at is if you run
./pants list dir::
and there are no targets there, so the result is empty. But it turns out that that will error instead with
. So, I think the only way this error can trigger is you left off args. Maybe this (taken from what happens when you run
./pants test
Copy code
17:07:13.09 [WARN] No files or targets specified.
You'll need to tweak the wording in
. Then, copy and paste that code into
. Add a test
(note the same as no targets matching). It looks like we currently assert that stderr was empty, which will need to be adjusted
Check out https://www.pantsbuild.org/docs/contributor-setup for getting set up with contributions
Perfect, the requirements are clear and this is a good amount of information to get started. Let me get my machine setup for localdev and I can get started on this tomorrow!
🚀 1