https://pantsbuild.org/ logo
q

quick-iron-62162

11/17/2022, 3:10 PM
Hello, we’re integrating black with pants in a django project and we want all the migrations file to be skipped from black… we already have in our
pyproject.toml
the following:
Copy code
exclude = '''
/(
  | \.git
  | \.mypy_cache
  | \.venv
  | migrations
  | protos
)/
'''
but running
./pants lint ::
it does not skip them (while running
black .
it does). We also tried writing the following in the root BUILD file:
Copy code
python_sources(
    name="migrations",
    skip_black=True,
    sources=["**/migrations/*.py"]
)
but it didn’t work. We know we can put the
skip_black=True
in each of the
BUILD
files inside all
migrations
folders but this would require us to add it every time we have a new
migrations
folder, which is a bit of a pain. Can you help us?
1
🙏 1
b

bitter-ability-32190

11/17/2022, 3:13 PM
The issue, I think, is Black doesn't respect
exclude
if you provide filenames to the cmd. I think they added a
force-exclude
option for this?
🙌 1
s

sparse-lifeguard-95737

11/17/2022, 3:14 PM
if you’re using Pants >= 2.14, you could use
__defaults__
to set
skip_black=True
for all of your migrations
something like:
Copy code
# In migrations/BUILD.pants
__defaults__(
  {(python_sources, python_source): dict(skip_black=True)}
)
q

quick-iron-62162

11/17/2022, 3:17 PM
@sparse-lifeguard-95737 The fact is we have a lot of folders containing a
migrations
sub_folder
s

sparse-lifeguard-95737

11/17/2022, 3:17 PM
ah, hrm
q

quick-iron-62162

11/17/2022, 3:18 PM
@bitter-ability-32190 thanks for the hint we’ll try
@bitter-ability-32190 it worked 🎉 thanks a lot
b

bitter-ability-32190

11/17/2022, 3:21 PM
FWIW you'll be doing some wasted work here, invoking Pants to run black and black then no-ops, but 🤷‍♂️
q

quick-iron-62162

11/17/2022, 3:22 PM
true that, do you know if there is a way to write some defaults in the root build file to skip them?
b

bitter-ability-32190

11/17/2022, 3:26 PM
Hmmmmmmmmm
No, and I'm thinking of th elowest-bar way of doing it and I got nothing easy
q

quick-iron-62162

11/17/2022, 3:27 PM
ok thanks
c

curved-television-6568

11/17/2022, 3:34 PM
I think you could get away with excludes and pants aliases..
Copy code
# pants.toml
[cli.alias]
exclude-migrations = "!src/apps/foo/migrations:: !src/apps/bar/migrations::"
Then when formatting:
Copy code
./pants fmt exclude-migrations src/apps::
h

happy-kitchen-89482

11/17/2022, 5:18 PM
What you had could work;
Copy code
python_sources(
    name="migrations",
    skip_black=True,
    sources=["**/migrations/*.py"]
)
but I’m guessing that you also have another
python_sources
that also globs over the migrations?
q

quick-iron-62162

11/17/2022, 6:03 PM
We also have some BUILD files created by
./pants tailor
in all of the
migrations
folders and all of them contains a
python_sources()
so I guess they all override it, am I correct?
@happy-kitchen-89482 We just needed to remove all
**/migrations/BUILD
or am I taking a wrong conclusion?
1
h

happy-kitchen-89482

11/17/2022, 8:06 PM
That would work, yes. And since that higher-level
migrations
target would cover new migration dirs as well, tailor wouldn’t generate new BUILD files for those new migrations
🔝 1
q

quick-iron-62162

11/17/2022, 8:16 PM
Great thanks a lot
6 Views