OK. This is a little odd, but what if a `fmt` tool...
# development
p
OK. This is a little odd, but what if a
fmt
tool adds a new file? Should that be reported in the list of changed files? Pants 2.12 shows the files that fmt changed, but the changed list only includes files that were present in both input and output digests. I dove into the code to figure out what does the diff. This is where the diff is displayed: https://github.com/pantsbuild/pants/blob/main/src/python/pants/core/goals/fmt.py#L116-L119 And this is where the actual diff happens, populating the list of
changed_files
: https://github.com/pantsbuild/pants/blob/main/src/rust/engine/fs/src/directory.rs#L599-L605 I believe that rust code only adds files to
changed_files
if the file is in both
ours
and
theirs
during diff... but I don't understand some of the syntax of rust, so I'm not sure.
🤯 2
Oh! It's capturing the files under
our_unique_files
and
their_unique_files
. so only the python bit needs to change.
h
Huh interesting! When would a formatter do this?
p
When codegen is masquerading as a formatter so that it is not restricted to
dist/codegen
and so that some schemas/specs (that get checked in) get auto-generated whenever their python deps change (without requiring manually running some command beyond the standard goals that people will be doing regularly).
Also, I can imagine ansible-lint moving a few files (eg: in an ansible content collection, playbooks should always be in the playbooks/ directory - it's fairly simple to identify those files and just move them. Though there are probably gotchas with doing that).
More backstory: some of StackStorm's
lint
targets in the old Makefile (that I want to eliminate) ensure that these schemas/specs were regenerated if needed. If regeneration would change the files, then lint fails. So, as I'm translating that to pants, I'm making a formatter that generates those files. That formatter does double duty as a linter to allow me to replace those old Makefile targets.
b
@proud-dentist-22844 have you tested this with your changes? I'm wondering out the `Process`s output_files would work. Seems like it wouldn't capture it. Oh but you're making the process object. I see
I guess this is only weird to me then because we're haven't renamed fmt to fix
p
fix
would make more sense. Using
fmt
for this feels wrong, but I don't want anyone to have to remember to extra commands if it can be avoided.
I used
output_directory
instead of
output_files
to ensure that all generated files get captured. 🙂
1
b
There's a proposal to rename
fmt
to
fix
, and then we'll add a
style-only
flag to it if you just want style. The gist is our tools do more than format (like your case), but semantic changes aren't always welcome (consider running
fix
on save, and it removes an import you just added, but havent used yet)
p
That makes sense. I'm cool with that. gofmt removing my imports is particularly irritating 😛 (or maybe it is Goland doing it, whatever), so the ability to do style-only could be useful.
1