ancient-terabyte-9085
04/22/2023, 12:35 AMflake8 and yapf running with Pants on our code but I'm having some questions & wondering what the best approach is. flake8 is handling configuration well, but yapf is giving me some trouble. In particular, we have some autogenerated files that we want to not run yapf on. If I use a .yapfignore, however, yapf will return
input filenames did not match any python files
and an exit code of 1 when called against a set of files that are all excluded in the .yapfignore. This makes ./pants lint fail when run against a set of files of files.
I did find a fairly reasonable workaround here, using either a python_sources(skip_yapf=True) or a
python_sources(overrides={
"*_pattern_common_to_generated_files.py": {
"skip_yapf": True
},
}
)
I'm wondering if this is the best way to handle this? ./pants tailor :: won't know to include this line, so developers will probably have some confusion when they write something that will produce a new folder of generated files. I could mitigate that with a unit test that inspects the BUILD files, but that also seems a little gross. Is there a way to make that *_pattern_common_to_generated_files.py override implicit in each python_sources?broad-processor-92400
04/22/2023, 12:39 AM__defaults__ : https://www.pantsbuild.org/docs/targets#field-default-valuesancient-terabyte-9085
04/22/2023, 12:53 AMoverrides I used for places were generated files are mixed in with regular code.
__defaults__(
{
(python_sources, ): dict(overrides={
"*_generated.py": {
"skip_yapf": True
},
})
},
extend=True,
)
Yields
TypeError: Even though you are using a `FrozenDict`, the underlying values are not hashable. Please use hashable (and preferably immutable) types for the underlying values, e.g. use tuples instead of lists and use FrozenOrderedSet instead of set().
Original error message: unhashable type: 'dict'
Value: FrozenDict({'overrides': {('*_generated.py',): {'skip_yapf': True}}})broad-processor-92400
04/22/2023, 12:58 AM__defaults__ not supporting nested dicts. Could you file an issue? https://github.com/pantsbuild/pants/issues/new?assignees=&labels=bug&template=bug_report.md&title=
In the short term, I wonder if it will coerce sequences of pairs to a dict: overides=(("*_generated.py", (("skip_yapf", True),)),) 🤔ancient-terabyte-9085
04/22/2023, 1:27 AMInvalidFieldTypeException: The 'overrides' field in target my/path#__defaults__ must be dict[str | tuple[str, ...], dict[str, Any]], but was `(('*_generated.py',), (('skip_yapf', True),))` with type `tuple`.ancient-terabyte-9085
04/22/2023, 1:29 AMhappy-kitchen-89482
04/22/2023, 2:28 AMancient-terabyte-9085
04/22/2023, 5:59 AMcurved-television-6568
04/22/2023, 12:24 PMcurved-television-6568
04/22/2023, 1:16 PMancient-terabyte-9085
04/22/2023, 10:48 PM*_generated.py files? What I had intended to test after the TypeError was to see how unmatched globs would be handledcurved-television-6568
04/23/2023, 12:22 PM__defaults__ feels like it should be able to ignore any errors the same way unknown fields may be ignored if needed.