Skip to content

clean

Clean command module.

clean_project(project_name)

Removes the kernel and/or virtual environment of an SSB-project.

Parameters:

Name Type Description Default
project_name str

Project name

required
Source code in ssb_project_cli/ssb_project/clean/clean.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def clean_project(project_name: str) -> None:
    """Removes the kernel and/or virtual environment of an SSB-project.

    Args:
        project_name: Project name
    """
    clean_venv()

    kernels = get_kernels_dict()

    if project_name not in kernels:
        print(
            "Could not find kernel {!r}. Is the project name spelled correctly?".format(
                project_name
            )
        )

        sys.exit(1)

    confirmation = questionary.confirm(
        "Are you sure you want to delete the kernel {!r}. This action will delete the kernel associated with the virtual environment and leave all other files untouched.".format(
            project_name
        )
    ).ask()

    if not confirmation:
        sys.exit(1)

    print(
        f"Deleting kernel {project_name}...If you wish to also delete the project files, you can do so manually."
    )

    remove_kernel_spec(project_name)

clean_venv()

Removes the virtual environment for project if it exists in current directory. If not, user is prompted for path to ssb project.

Source code in ssb_project_cli/ssb_project/clean/clean.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def clean_venv() -> None:
    """Removes the virtual environment for project if it exists in current directory. If not, user is prompted for path to ssb project."""
    confirm = questionary.confirm(
        "Do you also wish to delete the virtual environment for this project?"
    ).ask()
    if confirm:
        if Path(".venv").is_dir():
            clean_venv_cmd = "rm -rf .venv"

            execute_command(
                clean_venv_cmd,
                "clean-virtualenv",
                "Virtual environment successfully removed!",
                "Something went wrong while removing virtual environment in current directory. A log of the issue was created...",
                None,
            )

        else:
            print("No virtual environment found in current directory. Skipping...")