hi! I’m trying to build a monorepo with internal d...
# general
a
hi! I’m trying to build a monorepo with internal dependencies and I am not sure I am doing it properly. Each dependency is a namespace library located in the
lib
folder, so for example the common library would be placed in
lib/common/namespace/common
(with the build file for each library as
lib/common/BUILD
). To include dependencies, I am adding things like
dependencies=["lib/common"]
to the library configuraiton, but I am not sure if: 1. I need to add them in
module_mapping
, eg,
"lib/common": ["namespace.common"]
2. If they re being picked up correctly, because I don’t know how to properly read
./pants dependencies
and they don’t show up in
./pants dependencies --type=3rdparty
Can anybody give me a hint to see if what I’m doing makes sense? Thanks!
h
Hi Albert! Generally, you should not need to be manually adding `dependencies`: that is what dependency inference is for. https://blog.pantsbuild.org/dependency-inference/ I suspect that you need to set up "source roots" so that Pants understands your imports, like that
lib/common/namespace/common.py
corresponds to the import
namespace.common
. I believe you will want to set up
root_patterns = ["lib/common"]
The
module_mapping
thing is only for third-party dependencies. Is that what you're having issues with?
h
To elaborate - generally in a monorepo it's easiest to consume dependencies directly from source (i.e., "1st party"), rather than "build an artifact, publish it, consume the artifact" (i.e., effectively depending on your own code as if it were 3rdparty code). And dependency inference will figure the dependencies out for you. So as Eric said, it's likely that the only missing piece is to correctly configure your source roots: https://www.pantsbuild.org/docs/source-roots
a
OK, understood,thanks! I’m using marker files already so this should be OK.
I was thinking what would happen if I wanted to package each library separately, but I guess dependency inference would take this into account 🙂
h
By package do you mean as a wheel/sdist using
python_distribution
?
a
yes, exactly