Skip to content

Cruft

check_for_cruft_files(context)

Check that there are no cruft files (*.rej).

Source code in saritasa_invocations/cruft.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
@invoke.task
def check_for_cruft_files(context: invoke.Context) -> None:
    """Check that there are no cruft files (`*.rej`)."""
    found_files = tuple(
        filter(
            lambda filepath: not filepath.startswith(".venv"),
            map(str, pathlib.Path().glob("**/*.rej")),
        ),
    )
    if not found_files:
        return
    found_files_str = "\n".join(found_files)
    printing.print_error(f"Found cruft files:\n{found_files_str}")
    raise invoke.Exit(
        code=1,
        message=(
            "You have `.rej` files present, "
            "please resolve conflicts with cruft!"
        ),
    )

create_project(context, project_folder_name, **questions)

Create cruft project.

Utility shortcut for testing cruft boilerplates.

Source code in saritasa_invocations/cruft.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def create_project(
    context: invoke.Context,
    project_folder_name: str,
    **questions,
) -> str:
    """Create cruft project.

    Utility shortcut for testing cruft boilerplates.

    """
    git_change = context.run(
        "git status . --porcelain",
        pty=False,
        hide="out",
    )
    if git_change and git_change.stdout:
        printing.print_warn(
            "Warning: you have uncommitted files in boilerplate. "
            "Cruft generates project from latest commit. \n"
            "Git status output:\n"
            f"{git_change.stdout}",
        )
    config = _config.Config.from_context(context)
    tmp_folder = config.cruft.project_tmp_folder
    printing.print_success(f"Recreating tmp ({tmp_folder}) folder")
    shutil.rmtree(tmp_folder, ignore_errors=True)
    pathlib.Path(tmp_folder).mkdir(parents=True, exist_ok=True)
    with context.cd(tmp_folder):
        context.run(
            "cruft create ../. --no-input --overwrite-if-exists "
            f"--extra-context '{json.dumps(questions)}'",
        )
    project_path = f"{tmp_folder}/{project_folder_name}"
    printing.print_success(f"Project is created at {project_path}")
    return project_path