Skip to content

Commit

Permalink
Rename pyrootutils to rootutils
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleve committed May 13, 2023
1 parent a80ac07 commit 244e84d
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
pip install -r requirements.txt
- name: Run tests and collect coverage
run: pytest --cov pyrootutils
run: pytest --cov rootutils

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# pyrootutils
# rootutils

[![Python](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![Tests](https://github.com/ashleve/pyrootutils/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/ashleve/pyrootutils/actions/workflows/test.yml)
[![Codecov](https://codecov.io/gh/ashleve/pyrootutils/branch/main/graph/badge.svg)](https://codecov.io/gh/ashleve/pyrootutils)
[![Build](https://github.com/ashleve/pyrootutils/actions/workflows/publish_package.yml/badge.svg)](https://github.com/ashleve/pyrootutils/actions/workflows/publish_package.yml)
[![Issues](https://img.shields.io/github/issues/ashleve/pyrootutils)](https://github.com/ashleve/pyrootutils/issues)
[![License](https://img.shields.io/github/license/ashleve/pyrootutils)](https://github.com/ashleve/pyrootutils/blob/main/LICENSE)
[![Release](https://img.shields.io/pypi/v/pyrootutils)](pypi.org/project/pyrootutils/1.0.0/)
[![PyPi](https://img.shields.io/pypi/dm/pyrootutils)](pypi.org/project/pyrootutils/1.0.0/)
[![Tests](https://github.com/ashleve/rootutils/actions/workflows/test.yml/badge.svg?branch=main&event=push)](https://github.com/ashleve/rootutils/actions/workflows/test.yml)
[![Codecov](https://codecov.io/gh/ashleve/rootutils/branch/main/graph/badge.svg)](https://codecov.io/gh/ashleve/rootutils)
[![Build](https://github.com/ashleve/rootutils/actions/workflows/publish_package.yml/badge.svg)](https://github.com/ashleve/rootutils/actions/workflows/publish_package.yml)
[![Issues](https://img.shields.io/github/issues/ashleve/rootutils)](https://github.com/ashleve/rootutils/issues)
[![License](https://img.shields.io/github/license/ashleve/rootutils)](https://github.com/ashleve/rootutils/blob/main/LICENSE)
[![Release](https://img.shields.io/pypi/v/rootutils)](pypi.org/project/rootutils/1.0.5/)
[![PyPi](https://img.shields.io/pypi/dm/rootutils)](pypi.org/project/rootutils/1.0.5/)

A simple python package to solve all your problems with pythonpath, working directory, file paths, module imports and environment variables.

## Why pyrootutils?
## Why rootutils?

**Problem:** I would like to be able to:

Expand All @@ -21,35 +21,35 @@ A simple python package to solve all your problems with pythonpath, working dire
- Always have access to environment variables from `.env` file without having to load them manually
- Have all the above benefits in notebooks even if they're nested in subdirectories

**Solution:** The `pyrootutils` package provides a flexible way to setup the python project with a simple one-liner. It finds the project root based on the location of specified file name, e.g. `.project-root` or `.git`.
**Solution:** The `rootutils` package provides a flexible way to setup the python project with a simple one-liner. It finds the project root based on the location of specified file name, e.g. `.project-root` or `.git`.

The package is tiny and continuosly maintained.

## Setup

```bash
pip install pyrootutils
pip install rootutils
```

## Usage

```python
import pyrootutils
import rootutils

# find absolute root path (searches for directory containing .project-root file)
# search starts from current file and recursively goes over parent directories
# returns pathlib object
path = pyrootutils.find_root(search_from=__file__, indicator=".project-root")
path = rootutils.find_root(search_from=__file__, indicator=".project-root")

# find absolute root path (searches for directory containing any of the files on the list)
path = pyrootutils.find_root(search_from=__file__, indicator=[".git", "setup.cfg"])
path = rootutils.find_root(search_from=__file__, indicator=[".git", "setup.cfg"])

# take advantage of the pathlib syntax
data_dir = path / "data"
assert data_dir.exists(), f"path doesn't exist: {data_dir}"

# set root directory
pyrootutils.set_root(
rootutils.set_root(
path=path # path to the root directory
project_root_env_var=True, # set the PROJECT_ROOT environment variable to root directory
dotenv=True, # load environment variables from .env if exists in root directory
Expand All @@ -60,8 +60,8 @@ pyrootutils.set_root(

Simplest usage with one-liner (combines `find_root()` and `set_root()` into one method):
```python
import pyrootutils
root = pyrootutils.setup_root(__file__, dotenv=True, pythonpath=True, cwd=False)
import rootutils
root = rootutils.setup_root(__file__, dotenv=True, pythonpath=True, cwd=False)
```

## Defaults
Expand All @@ -74,7 +74,7 @@ Default root indicators (used when you don't specify `indicator` arg):

## Autoroot

`autoroot` is an experimental package that reduces `pyrootutils` to single import, without the need to execute any setup calls. This means just the act of importing this dependency (`import autorootcwd`) causes execution of recurrent search for `.project-root` file.
`autoroot` is an experimental package that reduces `rootutils` to single import, without the need to execute any setup calls. This means just the act of importing this dependency (`import autorootcwd`) causes execution of recurrent search for `.project-root` file.

Installation:
```bash
Expand Down
3 changes: 0 additions & 3 deletions pyrootutils/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions rootutils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .rootutils import find_root, set_root, setup_root

__all__ = ["find_root", "set_root", "setup_root"]
6 changes: 3 additions & 3 deletions pyrootutils/pyrootutils.py → rootutils/rootutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dotenv import load_dotenv


def _pyrootutils_recursive_search(path: Path, indicators: Iterable[str]) -> Optional[Path]:
def _rootutils_recursive_search(path: Path, indicators: Iterable[str]) -> Optional[Path]:
"""Recursively search for files from the `indicators` list, starting from given path.
Args:
Expand All @@ -24,7 +24,7 @@ def _pyrootutils_recursive_search(path: Path, indicators: Iterable[str]) -> Opti
if path.parent == path:
return None

return _pyrootutils_recursive_search(path.parent, indicators)
return _rootutils_recursive_search(path.parent, indicators)


def find_root(
Expand Down Expand Up @@ -64,7 +64,7 @@ def find_root(
if not hasattr(indicator, "__iter__") or not all(isinstance(i, str) for i in indicator):
raise TypeError("indicator must be a string or list of strings.")

path = _pyrootutils_recursive_search(search_from, indicator)
path = _rootutils_recursive_search(search_from, indicator)

if not path or not path.exists():
raise FileNotFoundError(f"Project root directory not found. Indicators: {indicator}")
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@


setup(
name="pyrootutils",
version="1.0.4",
name="rootutils",
version="1.0.5",
license="MIT",
description="Simple package for easy project root setup",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/ashleve/pyrootutils",
url="https://github.com/ashleve/rootutils",
author="ashleve",
author_email="[email protected]",
packages=find_packages(),
Expand Down
5 changes: 2 additions & 3 deletions tests/test_pyrootutils.py → tests/test_rootutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import pytest

from pyrootutils import find_root, set_root, setup_root
from rootutils import find_root, set_root, setup_root


def test_pyrootutils():
def test_rootutils():
assert find_root
assert set_root
assert setup_root
Expand Down Expand Up @@ -55,7 +55,6 @@ def test_find_root():


def test_set_root():

path = find_root(__file__)
assert path.exists()

Expand Down

0 comments on commit 244e84d

Please sign in to comment.