flaky-artist-57016
09/14/2022, 1:16 PM./pants lint ::
would succeed locally and then fail on some files on the same branch in CI? This has happened once or twice on my team. Recloning the branch into a new directory and running ./pants fmt ::
properly catches the files that need reformatting. Could it be a local cache issue?bitter-ability-32190
09/14/2022, 1:48 PMflaky-artist-57016
09/14/2022, 1:54 PMblack
and isort
. We’ve had occasions where folks will run ./pants fmt ::
and some files get reformatted. Our pre-commit hook runs ./pants lint ::
and it passes. But then our ./pants lint ::
check in CI flags several files as needing to be reformatted. The only way we can get the files reformatted is to make a fresh clone of the branch in a new directory and run ./pants fmt ::
there.bitter-ability-32190
09/14/2022, 1:54 PMisort
configured to use `black`'s style?flaky-artist-57016
09/14/2022, 1:54 PMbitter-ability-32190
09/14/2022, 1:55 PMbitter-ability-32190
09/14/2022, 1:55 PMflaky-artist-57016
09/14/2022, 2:00 PM$ ./pants lint ::
22:38:53.59 [INFO] Completed: Lint with Flake8 - flake8 succeeded.
22:38:53.59 [INFO] Completed: Format with Black - black made no changes.
22:38:53.60 [INFO] Completed: Format with Autoflake - autoflake made no changes.
22:38:53.60 [INFO] Completed: Format with isort - isort made no changes.
22:38:56.32 [WARN] Completed: Format with Autoflake - autoflake made changes.
directory/config.py
22:38:57.22 [WARN] Completed: Format with Black - black made changes.
directory1/__init__.py
directory1/config.py
directory2/__init__.py
22:38:58.00 [INFO] Completed: Format with Autoflake - autoflake made no changes.
22:39:00.13 [WARN] Completed: Format with Black - black made changes.
directory3/__init__.py
22:39:03.94 [INFO] Completed: Lint with Flake8 - flake8 succeeded.
22:39:04.29 [INFO] Completed: Lint with Flake8 - flake8 succeeded.
22:39:05.01 [WARN] Completed: Format with isort - isort made changes.
another_directory/trigger.py
22:39:05.06 [WARN] Completed: Format with isort - isort made changes.
file1.py
file2.py
file3.py
22:39:05.06 [INFO] Wrote lint report files to dist/lint/flake8/__CPython<3.9,>=3.8__.
22:39:05.06 [INFO] Wrote lint report files to dist/lint/flake8/__CPython<3.9,>=3.8___.
22:39:05.06 [INFO] Wrote lint report files to dist/lint/flake8/__CPython<3.9,>=3.8____.
✕ autoflake failed.
✕ black failed.
✓ flake8 succeeded.
✕ isort failed.
(One or more formatters failed. Run `./pants fmt` to fix.)
It is proprietary code in a private GitLab repo so I can’t really share a reproducible version.bitter-ability-32190
09/14/2022, 2:02 PMflaky-artist-57016
09/14/2022, 2:03 PMbitter-ability-32190
09/14/2022, 2:04 PMlint
running black locally?flaky-artist-57016
09/14/2022, 2:05 PMpants.ci.toml
that I guess would cause any differences in behavior:
# This file defines settings to use in CI
# in addition to those in pants.toml
[GLOBAL]
# cache pants files in working dir
local_store_dir=".cache/pants/lmdb_store"
named_caches_dir=".cache/pants/named_caches"
# Colors often work in CI, but the shell is usually not a TTY so Pants
# doesn't attempt to use them by default.
colors = true
# enable section below to show cache hits
# [stats]
# log = true
[coverage-py]
report = ["xml"]
output_dir = "."
[pytest]
args = ["-vv", "--no-header"]
flaky-artist-57016
09/14/2022, 2:06 PM./pants fmt ::
as before. No other changes.bitter-ability-32190
09/14/2022, 2:08 PMflaky-artist-57016
09/14/2022, 2:10 PMbitter-ability-32190
09/14/2022, 2:14 PMlint
as well as fmt
in the 'bad" case?
./pants lint --only=black ::
then ./pants fmt --only=black ::
flaky-artist-57016
09/14/2022, 2:18 PMbitter-ability-32190
09/14/2022, 2:20 PM-ldebug
and inspecting the log (or scrubbing it and posting here).
Otherwise it's hard to say without more info. Seems like a nasty bug for sure, but Pants has so many moving parts finding the problematic one is challenging.
The daemon might be to blame perhaps.
Or the way we "reuse" the process execution between fmt
and lint
bitter-ability-32190
09/14/2022, 2:21 PMlint ::
themselves, do they see it passing?flaky-artist-57016
09/14/2022, 2:25 PM./pants lint ::
locally after the lint step fails in CI. The formatters pass locally.flaky-artist-57016
09/14/2022, 2:26 PM-ldebug
. Is there anything in particular I should look out for?bitter-ability-32190
09/14/2022, 2:37 PMblack
on 22 files", or something along those lines.
They likely won't be identical and thats a cluebitter-ability-32190
09/14/2022, 2:45 PMfmt
and `lint`:
• For lint
, we create batches of files, then "materialize" a sandbox from a "snapshot" of those files. We do this for all batches of files across all tools in parallel. Under the hood, we run the tool on those files and capture the "snapshot" of files after. If they changed 💥 we error and print which files changed.
• For fmt
however its a bit different. We still batch, but we have to run tools sequentially one-after-the-other to make sure two tools can re-format the same line (otherwise we'd have to try and "merge" results). So we feed the output of tool 1 as an input to tool 2, and so on...
Meaning if the tools are making changes in fmt
, tool 2 and so on won't have a matching node to their respective lint
process since the input will be different (the unformatted repo file vs. the formatted output of tool 1).
So the helpful node to look at is the node for running the first tool in fmt
(i believe they use the order of backend_packages
flaky-artist-57016
09/16/2022, 4:01 PM./pants fmt ::
and autoflake
, isort
, and black
incorrectly said everything looks good. So I added a bunch of blank lines to the end of one file to see if that would trigger the formatters, but nope “no changes needed.” I then tried deleting the pants cache (~/.cache/pants
) just to see what would happen, same result. I then ran ./pants -ldebug fmt ::
and the formatters DID run. Very oddbitter-ability-32190
09/16/2022, 4:02 PMmv
the cache instead of deleting so you can mv
it back)bitter-ability-32190
09/16/2022, 4:03 PMflaky-artist-57016
09/16/2022, 4:03 PMflaky-artist-57016
09/16/2022, 5:10 PMbitter-ability-32190
09/16/2022, 5:14 PMflaky-artist-57016
09/16/2022, 5:19 PMflaky-artist-57016
09/16/2022, 5:21 PM./pants -ldebug fmt ::
caused the formatters to pick up the file changes.flaky-artist-57016
09/16/2022, 5:24 PM./pants fmt ::
and ./pants -ldebug fmt ::
, but the result differed.bitter-ability-32190
09/16/2022, 5:26 PMwitty-crayon-22786
09/16/2022, 5:27 PMflaky-artist-57016
09/21/2022, 2:41 PMgit
performance. Periodically VS Code will show a notification to the effect of VS Code is unable to watch for file changes
which made me think that perhaps pants
is similarly not seeing any changed files and saying “no changes? no formatting needed.” At some point the changes are noticed and pants
runs the formatter as expected.
TLDR; laggy inotify on a fileshare?
(I am out of my depth at this level, but figured I’d share my theory.)bitter-ability-32190
09/21/2022, 2:42 PMbitter-ability-32190
09/21/2022, 2:42 PMinotify
(whoch is what the daemon uses)bitter-ability-32190
09/21/2022, 2:42 PMflaky-artist-57016
09/21/2022, 2:43 PMbitter-ability-32190
09/21/2022, 2:43 PMwitty-crayon-22786
09/21/2022, 4:39 PM