import shutil


def tpl_repo(request, tmp_path, tpl_path):
    """
    Creates a temporary folder containing a set of test templates.

    The templates to copy can be passed in by using the tpl_repo_contents mark.

    Used for testing installation of template directories.
    """
    repo_dir = tmp_path / "template_repository"
    repo_dir.mkdir()

    marker = request.node.get_closest_marker("tpl_repo_contents")

    templates = ["hello_world", "test"]
    if marker is not None:
        templates = [a for a in marker.args]

    for tpl in templates:
        tpl_dir = tpl_path / tpl
        if tpl_dir.is_dir():
            shutil.copytree(tpl_dir, repo_dir / tpl)

    return repo_dir