The `monorepo` Python library (version 0.2.0) simplifies importing packages and modules from the root of a monorepo structure. It achieves this by programmatically adding the monorepo root to `sys.path`, allowing sub-packages to reference each other easily without complex relative imports. The library has an active release cadence, with the latest release in early 2024.
pip install monorepoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `monorepo` by calling `Monorepo.setup()` with the absolute path to your monorepo's root directory. Once set up, you can perform direct imports of packages located anywhere under the specified root, such as `from service_b import my_module`, regardless of the current working directory's depth. The example creates a temporary monorepo structure for demonstration.
Ensure `root` points to the absolute path of your monorepo's root directory, where all top-level packages/services are located. Use `Path(__file__).parent.parent.parent` or similar for robust relative pathing from within a sub-package.
Be aware that `monorepo` modifies `sys.path`. If you're also using `PYTHONPATH` or other `sys.path.insert()` calls, carefully test the order of operations. `monorepo` inserts its path at the beginning of `sys.path`, giving it high precedence.
IDEs like VS Code or PyCharm might not immediately pick up the `sys.path` modifications from `Monorepo.setup()` for static analysis. Configure your IDE's Python interpreter paths or source roots to include the monorepo root manually for correct linting and autocompletion.
No dependency data recorded yet.