pytest_wdl/utils.py
def context_dir(
    path: Optional[Path] = None,
    change_dir: bool = False,
    cleanup: Optional[bool] = None,
) -> Path:
    """
    Context manager that looks for a specific environment variable to specify a
    directory. If the environment variable is not set, a temporary directory is
    created and cleaned up upon return from the yield.

    Args:
        path: The environment variable to look for.
        change_dir: Whether to change to the directory.
        cleanup: Whether to delete the directory when exiting the context. If None,
            the directory is only deleted if a temporary directory is created.

    Yields:
        A directory path.
    """
    if cleanup is None:
        cleanup = path is None

    if not path:
        path = Path(tempfile.mkdtemp())
    elif not path.exists():
        path.mkdir(parents=True)

    try:
        if change_dir:
            with chdir(path):
                yield path
        else:
            yield path
    finally:
        if cleanup and path.exists():
            shutil.rmtree(path, ignore_errors=True)

    Context manager that looks for a specific environment variable to specify a
    directory. If the environment variable is not set, a temporary directory is
    created and cleaned up upon return from the yield.

    Args:
        path: The environment variable to look for.
        change_dir: Whether to change to the directory.
        cleanup: Whether to delete the directory when exiting the context. If None,
            the directory is only deleted if a temporary directory is created.

    Yields:
        A directory path.
    
Context manager that looks for a specific environment variable to specify a
directory. If the environment variable is not set, a temporary directory is
created and cleaned up upon return from the yield.
Context manager that looks for a specific environment variable to specify a directory . If the environment variable is not set a temporary directory is created and cleaned up upon return from the yield .
def context_dir(
    path: Optional[Path] = None,
    change_dir: bool = False,
    cleanup: Optional[bool] = None,
) -> Path:
    if cleanup is None:
        cleanup = path is None
    if not path:
        path = Path(tempfile.mkdtemp())
    elif not path.exists():
        path.mkdir(parents=True)
    try:
        if change_dir:
            with chdir(path):
                yield path
        else:
            yield path
    finally:
        if cleanup and path.exists():
            shutil.rmtree(path, ignore_errors=True)
def context_dir ( path : Optional [ Path ] = None , change_dir : bool = False , cleanup : Optional [ bool ] = None , ) -> Path : if cleanup is None : cleanup = path is None if not path : path = Path ( tempfile . mkdtemp ( ) ) elif not path . exists ( ) : path . mkdir ( parents = True ) try : if change_dir : with chdir ( path ) : yield path else : yield path finally : if cleanup and path . exists ( ) : shutil . rmtree ( path , ignore_errors = True )
Context manager that looks for a specific environment variable to specify a
directory.
Context manager that looks for a specific environment variable to specify a directory .
"""
    Context manager that looks for a specific environment variable to specify a
    directory. If the environment variable is not set, a temporary directory is
    created and cleaned up upon return from the yield.

    Args:
        path: The environment variable to look for.
        change_dir: Whether to change to the directory.
        cleanup: Whether to delete the directory when exiting the context. If None,
            the directory is only deleted if a temporary directory is created.

    Yields:
        A directory path.
    """
A directory path.
A directory path .
path
Optional[Path]
The environment variable to look for.
The environment variable to look for .
change_dir
bool
Whether to change to the directory.
Whether to change to the directory .
cleanup
Optional[bool]
Whether to delete the directory when exiting the context. If None,
the directory is only deleted if a temporary directory is created.
Whether to delete the directory when exiting the context . If None the directory is only deleted if a temporary directory is created .