elegant-florist-94385
08/20/2024, 1:42 PMmypy . --always-true FEATURE_FLAG
and then mypy . --always-false FEATURE_FLAG
to typecheck both variants of my code. This would cause a full run of mypy each time since it would invalidate the mypy cache. I changed it to mypy . --always-true FEATURE_FLAG --cache-dir .mypy_cache.flag_on
(and .flag_off
). This made mypy do fast incremental runs since it could preserve its cache correctly.
With pants: I (naiively) expected I could just run pants check --mypy-args=["--always-true FEATURE_FLAG"] ::
and pants check --mypy-args=["--always-false FEATURE_FLAG"] ::
and as expected this works to deliver a fast (pants cached) success. However, I get a full mypy run (roughly 1 minute for each feature flag variant) if any python files have changed. ie. The mypy cache is not being preserved.
I added back the --cache-dir
argument to mypy (as --mypy-args
) but it still looks like I'm getting the slow mypy runs and not getting the incremental caching.
Is there something I need to do to get pants to preserve mypy caches when I'm using non-standard cache names?ancient-france-42909
08/20/2024, 4:06 PMelegant-florist-94385
08/29/2024, 12:32 PMelegant-florist-94385
08/29/2024, 12:38 PM__mypy_runner.sh
file with the mypy invocation. It includes my --cache-dir
argument with absolute file path, but also includes another (later) argument: --cache-dir .tmp_cache/mypy_cache
So it looks like pants is supplying its own caching args to mypy and overwriting mine. Is there any way to disable this from pants so I can manage it myself?elegant-florist-94385
08/29/2024, 12:39 PMbroad-processor-92400
08/30/2024, 3:04 AM{sha256(build_root.path.encode()).hexdigest()}
part of that second link customisable, for instance, a new cache_path_disambiguator
option on https://github.com/pantsbuild/pants/blob/0392d378d6b9c6c8cecd17ac5bffa0698b5eb454/src/python/pants/backend/python/typecheck/mypy/subsystem.py#L[…]20
with default value default=lambda _: pants.base.build_environment.get_buildroot()
(This would also solve https://github.com/pantsbuild/pants/issues/18830)
Then, for your usecase, you could do pants check --mypy-args=[...] --mypy-cache-disambiguator='%(buildroot)s:flag_...'
(and/or create an alias.)
Are you interested in contributing? 😄elegant-florist-94385
09/03/2024, 4:22 PMelegant-florist-94385
09/03/2024, 4:22 PM