Registry / devops / monorepo

monorepo

JSON →
library0.2.0pypypi✓ verified 83d ago

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 monorepo
INSTALL
IMPORT
SIG · MONOREPO
M
monorepo
devopspythonv0.2.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Path
from monorepo import Path
from monorepo import Monorepo
inspect
from monorepo import inspect
load_module
from monorepo import load_module

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.

from pathlib import Path from monorepo import Monorepo import sys # Simulate a monorepo structure for demonstration # In a real monorepo, __file__ would be inside a sub-package # For this example, let's create a dummy structure # Create a dummy monorepo root and a sub-package monorepo_root = Path('./my_monorepo_root') monorepo_root.mkdir(exist_ok=True) (monorepo_root / 'service_a').mkdir(exist_ok=True) (monorepo_root / 'service_b').mkdir(exist_ok=True) # Create a dummy module in service_b (monorepo_root / 'service_b' / '__init__.py').touch(exist_ok=True) (monorepo_root / 'service_b' / 'my_module.py').write_text("MY_VALUE = 'Hello from service_b!'") # Now, simulate being inside 'service_a/main.py' # The 'root' should point to 'my_monorepo_root' Monorepo.setup(root=monorepo_root.absolute()) # Now you can import from other services/packages in the monorepo root # This would typically be 'from service_b import my_module' # We need to ensure 'service_b' is discoverable, which Monorepo.setup does. # If running from a different directory, adjust sys.path for the quickstart try: from service_b import my_module print(f"Successfully imported my_module: {my_module.MY_VALUE}") except ModuleNotFoundError as e: print(f"Failed to import module: {e}") finally: # Clean up dummy files import shutil if monorepo_root.exists(): shutil.rmtree(monorepo_root)
Debug
Known issues
gotchaIncorrect `root` path specified for `Monorepo.setup()`.
fix
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.
affects: All
gotchaConflicts with existing `PYTHONPATH` environment variable or other programmatic `sys.path` modifications.
fix
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.
affects: All
gotchaIDE/Linter issues with recognizing monorepo paths.
fix
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.
affects: All
Upgrade
Version history
0.2.0latest on PyPI · released May 29, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
monorepo — pip install monorepo · libregistry