{"library":"monorepo","title":"Monorepo Path Management Library","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install monorepo"],"cli":null},"imports":["from monorepo import Monorepo"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pathlib import Path\nfrom monorepo import Monorepo\nimport sys\n\n# Simulate a monorepo structure for demonstration\n# In a real monorepo, __file__ would be inside a sub-package\n# For this example, let's create a dummy structure\n\n# Create a dummy monorepo root and a sub-package\nmonorepo_root = Path('./my_monorepo_root')\nmonorepo_root.mkdir(exist_ok=True)\n(monorepo_root / 'service_a').mkdir(exist_ok=True)\n(monorepo_root / 'service_b').mkdir(exist_ok=True)\n\n# Create a dummy module in service_b\n(monorepo_root / 'service_b' / '__init__.py').touch(exist_ok=True)\n(monorepo_root / 'service_b' / 'my_module.py').write_text(\"MY_VALUE = 'Hello from service_b!'\")\n\n# Now, simulate being inside 'service_a/main.py'\n# The 'root' should point to 'my_monorepo_root'\nMonorepo.setup(root=monorepo_root.absolute())\n\n# Now you can import from other services/packages in the monorepo root\n# This would typically be 'from service_b import my_module'\n# We need to ensure 'service_b' is discoverable, which Monorepo.setup does.\n# If running from a different directory, adjust sys.path for the quickstart\n\ntry:\n    from service_b import my_module\n    print(f\"Successfully imported my_module: {my_module.MY_VALUE}\")\nexcept ModuleNotFoundError as e:\n    print(f\"Failed to import module: {e}\")\nfinally:\n    # Clean up dummy files\n    import shutil\n    if monorepo_root.exists():\n        shutil.rmtree(monorepo_root)","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}