Hello, I am looking at pants to use on a mono repo...
# general
f
Hello, I am looking at pants to use on a mono repo. The repo contains a few projects (~7 at the moment. Looking at how pants work, I am wondering if it is possible to have projects depending on older versions of other projects in the repo. The reason for this use case is that some projects have dependencies that are not compatible with some new projects that are coming up. The common libraries has to upgrade with these new libraries. I am not experienced with mono repo yet. I would be happy to have feedback from more experience users.
👋 1
h
Hi!
To clarify, when you say "some projects have dependencies that are not compatible" does "dependencies" refer to third-party dependencies (from an external artifact repository like PyPI)? Or to internal dependencies on your own code?
f
Hi Benjy, I am talking about internal dependencies
I did not find many explanation of how to run mono repos online. This blog mentions the benefit of having all dependencies running the same version. I just find it hard to actually run the project this way. https://medium.com/opendoor-labs/our-python-monorepo-d34028f2b6fa
h
Yeah, so generally one of the big advantages of a monorepo is that it makes it possible to have your entire codebase be mutually compatible at every commit, because all internal dependencies are consumed directly from source, without versioning. But it sounds like this won't work for you, or at least not yet.
So just to be sure I understand - how does this work today? Do you publish versioned wheels/sdists from one project and consume those at a specific version in some other project?
You can do this in a monorepo, with Pants, but it's a little awkward. Is the goal to do this as a stepping-stone towards unifying the versions so that the entire codebase is mutually compatible at HEAD? Or do you think you'd be needing to depend on old versions even a long time from now? If the latter then can you mention what are the main reasons for wanting to transition to a single repo?
But basically to do this sort of thing with Pants you would have each project use a python_distribution target to package its code as an sdist/wheel, and then use a python_requirement target to describe a single published version. So for example, if library B depends on library A at version 1.2.3, you have the usual
python_sources
target for A's sources, a
python_distribution
for A that depends on the
python_sources
and publishes libA and version 1.2.3, a
python_requirement
target that represents "A==1.2.3" and then B's
python_sources
can depend on that
python_requirement
target.
The tricky part is that you'll have to disable dependency inference, as it will otherwise attempt to infer source-to-source dependencies, which is not what you want in your specific case. You need to specify dependencies between explicitly and manually, so you can control the versions.