Skip to content

config

repo_root(path=Path('.'))

Find the root of the current repository.

Parameters:

Name Type Description Default
path Path

A path in the repository.

Path('.')

Returns:

Type Description
Optional[Path]

Optional[Path]: The root of the repo if it is a repo, None otherwise.

Source code in mkreports/config.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def repo_root(path: Path = Path(".")) -> Optional[Path]:
    """
    Find the root of the current repository.

    Args:
        path (Path): A path in the repository.

    Returns:
        Optional[Path]: The root of the repo if it is a repo, None otherwise.

    """
    try:
        repo = Repo(path, search_parent_directories=True)
        if repo.working_tree_dir is None:
            return None
        else:
            return Path(repo.working_tree_dir)
    except Exception:
        pass

    return None

set_mkreports_dir(mkreports_dir=None, repo_root_dir=repo_root(Path(os.getcwd())), mkreports_root_dir=Path(os.environ.get('MKREPORTS_ROOT_DIR', Path(tempfile.gettempdir()) / 'mkreports')))

Function to derive the ckpt directory.

This is called once at initialization. The reason is that it could change if the working directory is changed and this would be undesirable behavior.

Source code in mkreports/config.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def set_mkreports_dir(
    mkreports_dir: Optional[Path] = None,
    repo_root_dir: Optional[Path] = repo_root(Path(os.getcwd())),
    mkreports_root_dir: Path = Path(
        os.environ.get("MKREPORTS_ROOT_DIR", Path(tempfile.gettempdir()) / "mkreports")
    ),
):
    """
    Function to derive the ckpt directory.

    This is called once at initialization. The reason is that it could change
    if the working directory is changed and this would be undesirable
    behavior.
    """
    if mkreports_dir is None:
        if repo_root_dir is None:
            mkreports_dir = mkreports_root_dir / "default"
        else:
            hash_str = hashlib.md5(str(repo_root_dir.resolve()).encode()).hexdigest()
            mkreports_dir = mkreports_root_dir / hash_str

    state["mkreports_dir"] = mkreports_dir