Namespacing when publishing packages as libraries #428
-
|
Hello! I'm starting to switch our team's codebase over to a Polylith repo, and we're excited to give it a try! Throughout our codebase, there are a few small libraries that exist to be imported by users from other teams (and whose scripts are not in our monorepo). For now, these are just directly contained in a base. I.e. I understand from the documentation and the uv example repo that I can give these distributions a new top-namespace above the main polylith namespace. I was wondering if instead, there was a way to flatten the namespace when publishing a library, so that consumers would only have to do from lib_A import fooThat would let us move this package into the monorepo and maintain it there without causing breaking changes for users. As it is now, if we do a release built from the monorepo, we'll force consuming scripts to shift to I've also gotten gotten pushback from team members who thought it would be too confusing to build and publish uv pip install lib_A
uv run python -c "import lib_A" # ModuleNotFoundError
uv run python -c "import namespace.lib_A" # User confused -- "shouldn't installing lib_A give me the lib_A namespace"?I am pretty new to monorepos in general, so perhaps this is a naive question. Is there a recommended approach here, in general? Worst case scenario, we can simply keep projects like this outside of the monorepo so that they can own their own namespace. However, I'm curious if there is a workaround, or if I have a misunderstanding about how packaging from the monorepo should look. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hi @tjweitzel225, I am happy that you have found Polylith and trying it out! Yes, the main use case is to have all Python code in the monorepo and reuse the code for the features of the services or apps that are developed. It's also possible to package code into libraries, as you write. In fact, the Polylith tooling itself is bulit that way (currently 5 different things such as the CLI, a Poetry plugin and hooks for Hatch and PDM). Adding the custom top-namespace is good (and probably necessary) if you plan to package several libraries and distribute them publicly. This is to avoid namespace collissions in case a user would install two packages of different versions or decide to remove one of them without re-synchronizing the virtual environment. But if you are about to package one or some libraries for internal use (where you would have more control, and better communication with other teams) you could do this without appending a new top namespace. It's only to avoid any potential namespace/versioning issues. Removing the Polylith top-namespace: you can't do that today with the tooling, and I wouldn't recommend it either. Because that could cause other types of namespace clashes. Let's say that you have a component called If I understand you correctly, the other teams will need to handle any new releases coming from the monorepo as a breaking change, because of the new version now is in a different structure? |
Beta Was this translation helpful? Give feedback.
Hi @tjweitzel225, I am happy that you have found Polylith and trying it out!
Yes, the main use case is to have all Python code in the monorepo and reuse the code for the features of the services or apps that are developed. It's also possible to package code into libraries, as you write. In fact, the Polylith tooling itself is bulit that way (currently 5 different things such as the CLI, a Poetry plugin and hooks for Hatch and PDM).
Adding the custom top-namespace is good (and probably necessary) if you plan to package several libraries and distribute them publicly. This is to avoid namespace collissions in case a user would install two packages of different versions or decide to remove on…