I think the mypy plugin needs a feature flag to co...
# general
g
I think the mypy plugin needs a feature flag to control whether it adds all of the source roots to MYPYPATH or kicks off one mypy run per source root. I found these two threads which hit the same issue I have. https://pantsbuild.slack.com/archives/C046T6T9U/p1671746311585759 https://pantsbuild.slack.com/archives/C046T6T9U/p1671746224355039 For context; I am adopting pants in a python monorepo. Before pants we built, tested, linted all packages individually. So our conflicting test sub-dir module-a/{module_a,test} and module-b/{module_b,test} wasn't an issue. Now pants is pulling in and shoving all of the source roots into MYPYPATH which is causing mypy to throw the following error:
Copy code
error: Duplicate module named 'test'
I've attempted to use the mypy ignore option without success. I realize that moving around the test sub-dir to something unique per module would fix this or moving tests next to the source, but both of those options aren't ideal when talking about adopting pants into over 100 modules. This is the culprit: https://github.com/pantsbuild/pants/blob/1d1e93edcdf617c651c3eb1d1cbadd29d99172b2/src/python/pants/backend/python/typecheck/mypy/rules.py#L338
I tried doing this and it doesn't work either because it's still pulling in dependent modules.
Copy code
pants --changed-since=origin/main list | grep pyproject.toml:poetry | sed 's|/pyproject.toml:poetry|::|g' | xargs pants check
Workaround I came up with for now... 1. Install mypy via pipx 2. For loop over changed and call mypy directly
Copy code
set -e

for dir in $(pants --changed-since=origin/main list | egrep "pyproject.toml:poetry$" | sed 's|/pyproject.toml:poetry||g'); do
    pushd $dir
    mypy --config-file $(git rev-parse --show-toplevel)/mypy.ini .
    popd
done
d
I would love something like this as well. Would solve a significant problem for us as well.
b
One possible approach to this would be https://github.com/pantsbuild/pants/issues/17739, where mypy invocations are partitioned by the config files that apply, and then one could indicate the separate invocations by having appropriate mypy configuration in ecah directory.