rootutils (formerly pyrootutils) is a Python library designed for simple and robust project root setup. It helps locate the project root directory using an indicator file and can optionally add it to `sys.path` for simplified imports. The library is currently at version 1.0.7 and maintains a moderately active release cadence, typically releasing minor updates or bug fixes every few months.
pip install rootutilsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `rootutils.autosetup()` to find the project root (indicated by `.project-root`) and add it to `sys.path`. This enables direct imports of modules located within the project root, simplifying project structure management. The example simulates a project root by creating a temporary indicator file.
Update your `pip install` commands from `pyrootutils` to `rootutils`. Change all `import pyrootutils` statements to `import rootutils` throughout your codebase. If you need to maintain compatibility with older versions, consider conditional imports or pinning your dependency to `<1.0.5`.
If you intend to make modules at the detected root importable, use `rootutils.setup_root(add_to_pythonpath=True)` or, more conveniently, `rootutils.autosetup()`. `autosetup()` is generally the recommended method as it combines finding the root with adding it to `sys.path`.
Ensure that an `indicator_file` (e.g., an empty `.project-root` file or `pyproject.toml`) exists in your actual project's root directory. If calling from an unusual location, explicitly set the `project_dir` argument to specify the starting point for the root search.
Update all occurrences of `import pyrootutils` to `import rootutils` in your codebase.
Ensure the indicator file (e.g., `.project-root`, `.git` directory, `pyproject.toml`) exists in the desired project root. Always check the return value of `rootutils.setup_root()` for `None` before attempting to use it.
Replace `pip install pyrootutils` with `pip install rootutils` in your terminal or `requirements.txt`.
No dependency data recorded yet.