Is there any support for <https://www.pantsbuild.o...
# general
t
Is there any support for [tailor].ignore_adding_targets globs? I would ideally like to avoid adding certain, identically named targets, across an entire directory tree. From what I gather now, I would have to specify each
BUILD
file's path and the target name for each string. However I have around 50 files that would require these ignores.
šŸ‘€ 1
f
I think your options are somewhat limited. You cannot pass a Shell command with some path expansion in the
pants.toml
file (under
[tailor]
or
[cli.alias]
), so you do need to provide string literals. Getting the list of paths is fairly straightforward, however, e.g.
Copy code
$ tree cheeseshop/data
cheeseshop/data
ā”œā”€ā”€ dir1
│   ā”œā”€ā”€ dir1A
│   │   ā”œā”€ā”€ __init__.py
│   │   ā”œā”€ā”€ pymod.py
│   │   └── test_pymod.py
│   └── __init__.py
ā”œā”€ā”€ dir2
│   ā”œā”€ā”€ dir2A
│   │   ā”œā”€ā”€ __init__.py
│   │   ā”œā”€ā”€ pymod.py
│   │   └── test_pymod.py
│   └── __init__.py
ā”œā”€ā”€ dir3
│   ā”œā”€ā”€ dir3A
│   │   ā”œā”€ā”€ __init__.py
│   │   ā”œā”€ā”€ pymod.py
│   │   └── test_pymod.py
│   └── __init__.py
└── __init__.py

7 directories, 13 files
I've created a directory with source and test targets. Now, by default both source and tests targets are going to be created:
Copy code
$ pants tailor --check cheeseshop/data::            
17:18:53.37 [INFO] Initializing scheduler...
17:18:56.65 [INFO] Scheduler initialized.
Would create cheeseshop/data/dir1/dir1A/BUILD:
  - Add python_sources target dir1A
  - Add python_tests target tests
Would create cheeseshop/data/dir2/dir2A/BUILD:
  - Add python_sources target dir2A
  - Add python_tests target tests
Would create cheeseshop/data/dir3/dir3A/BUILD:
  - Add python_sources target dir3A
  - Add python_tests target tests

To fix `tailor` failures, run `pants tailor`.
with a list of targets to ignore, only the sources are going to be tailored:
Copy code
$ pants tailor --check --tailor-ignore-adding-targets="[$(find cheeseshop/data -type d -name 'dir*' | sed "s|$|:tests|;s|^|'|;s|$|'|" | paste -sd ',' -)]" cheeseshop/data::
Would create cheeseshop/data/dir1/dir1A/BUILD:
  - Add python_sources target dir1A
Would create cheeseshop/data/dir2/dir2A/BUILD:
  - Add python_sources target dir2A
Would create cheeseshop/data/dir3/dir3A/BUILD:
  - Add python_sources target dir3A

To fix `tailor` failures, run `pants tailor`.
with the paths evaluated to:
Copy code
$ echo "[$(find cheeseshop/data -type d -name 'dir*' | sed "s|$|:tests|;s|^|'|;s|$|'|" | paste -sd ',' -)]"                
['cheeseshop/data/dir1:tests','cheeseshop/data/dir1/dir1A:tests','cheeseshop/data/dir2:tests','cheeseshop/data/dir2/dir2A:tests','cheeseshop/data/dir3:tests','cheeseshop/data/dir3/dir3A:tests']
the best I can come up with is to perhaps create
PANTS_TAILOR_IGNORE_ADDING_TARGETS
env var with those paths pre-populated (either locally in your Shell
.rc
file or in CI). Is that any good? It should be possible to extend the
tailor
logic to accept something more complex like a glob with a list of target types, but I am not sure how useful this is. I think most often, it is sufficient to ignore a handful of directories which you don't want to become "visible" to Pants. Or it could be a few directories where you know you don't want to create test
python_requirement
targets because they are used outside of Pants.