pincer.utils.directory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A chdir() 0 18 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from contextlib import contextmanager
7
from os import getcwd, chdir as os_chdir
8
from typing import TYPE_CHECKING
9
10
if TYPE_CHECKING:
11
    from typing import Generator, Any
12
13
14
@contextmanager
15
def chdir(path: str) -> Generator[str, Any, None]:
16
    """Change the cwd to the given path as a context manager.
17
18
    Parameters
19
    ----------
20
    path:
21
        Path to change to.
22
23
    Yields
24
    ------
25
    Generator[:class:`str`, Any, None]
26
    """
27
    current_path = getcwd()
28
    os_chdir(path)
29
30
    yield current_path
31
    os_chdir(current_path)
32