I have a monorepo with multiple top-level projects...
# general
f
I have a monorepo with multiple top-level projects and a couple of shared projects. Here’s a fragment of the roots
Copy code
common/src/python
common/test/python
directory_pull/src/docker
directory_pull/src/python
directory_pull/test/python
mypy-stubs/src/python
project_management/src/docker
project_management/src/python
project_management/test/python
Each project has the same code structure within the
src/python
directory. So, there is a
run.py
in each of
directory_pull/src/python
and
project_management/src/python
Everything works fine within each project, but when I run
pants check ::
mypy complains about duplicate modules across the projects. If I add a directory above
run.py
like
directory_pull/src/python/directory_pull
then there is no error. I’m curious what is going on with my original organization that yields this behavior, and whether there is an alternative solution to the slight reorganization
e
Its exactly like it says. MyPy sees 2x run.py, so a duplicate module. If there is a way to exclude run.py from MyPy checks, that's one path forward, but only if you can swallow doing that. Otherwise, IIUC, a single Pants command line invocation can't get you what you want here. You need to run it a few times.
I guess you're not seeing that when Pants runs it runs: + Not in your repo, it creates a sandbox snapshot to run mypy in. + Pants does not just copy your repo to the sandbox, it factors in the source roots and strips them (in spirit - details are complicated); so mypy sees none of the prefix dirs (common/src/python, directory_pull/src/python, project_management/src/python), just the files relative to those dirs. And thus is sees 2 identical
run.py
.
@famous-kilobyte-26155 IOW, could you previously run mypy against all this in 1 go with some sortof configuration or did you likewise have to run it once per project?
f
Thanks @enough-analyst-54434. I was misunderstanding the role of the source roots in this case. And, no, I haven’t had a configuration where I didn’t get this error after adding more projects