Skip to content

environment

This module reads in environment variables.

reset_global_gitconfig()

Reset the global gitconfig using 'kvakk-git-tools' module.

This function attempts to configure the global gitconfig using the 'kvakk-git-tools' module. If the configuration fails, an error message is printed indicating the platform's support status.

Source code in ssb_project_cli/ssb_project/build/environment.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def reset_global_gitconfig() -> None:
    """Reset the global gitconfig using 'kvakk-git-tools' module.

    This function attempts to configure the global gitconfig using the 'kvakk-git-tools' module.
    If the configuration fails, an error message is printed indicating the platform's support status.
    """
    print("\nConfiguring git with 'kvakk-git-tools':")

    try:
        ssb_gitconfig.main(test=False)
    except SystemExit:
        platform = ssb_gitconfig.Platform()
        is_supported_bools = ("is", "is not")
        print(
            f"\n:x:\tYour global gitconfig was not fixed, your platform {is_supported_bools[platform.is_unsupported()]} supported."
        )

running_onprem(image_spec)

Are we running in Jupyter on-prem?

Parameters:

Name Type Description Default
image_spec str

Value of the JUPYTER_IMAGE_SPEC environment variable

required

Returns:

Type Description
bool

True if running on-prem, else False.

Source code in ssb_project_cli/ssb_project/build/environment.py
15
16
17
18
19
20
21
22
23
24
def running_onprem(image_spec: str) -> bool:
    """Are we running in Jupyter on-prem?

    Args:
        image_spec: Value of the JUPYTER_IMAGE_SPEC environment variable

    Returns:
        True if running on-prem, else False.
    """
    return "onprem" in image_spec

verify_local_config(template_repo_url, checkout, cwd='')

Verifies that the local configuration files contains all lines from the files in the remote repository.

Returns True if local config is following SSB recommendations otherwise False.

Parameters:

Name Type Description Default
template_repo_url str

Template repository url

required
checkout str | None

The git reference to check against. Supports branches, tags and commit hashes.

required
cwd str

Current working directory

''
Source code in ssb_project_cli/ssb_project/build/environment.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def verify_local_config(
    template_repo_url: str, checkout: str | None, cwd: str = ""
) -> bool:
    """Verifies that the local configuration files contains all lines from the files in the remote repository.

    Returns True if local config is following SSB recommendations otherwise False.

    Args:
        template_repo_url: Template repository url
        checkout: The git reference to check against. Supports branches, tags and commit hashes.
        cwd: Current working directory
    """
    file_paths = [".gitattributes", ".gitignore"]

    if cwd != "":
        # If a path is used we should add a slash
        cwd = cwd + "/"

    # create a temporary directory
    with TempTemplateRepo(template_repo_url, checkout) as temp_repo:
        # compare the contents of the local files with the files in the repository
        for file_path in file_paths:
            # get the paths of the local and remote files
            remote_file_path = (
                f"{temp_repo.temp_dir.name}/{temp_repo.subdir}/{file_path}"
            )
            local_file_path = cwd + file_path
            if not Path(local_file_path).exists():
                return False
            # compare the contents of the local and remote files
            if not _local_file_contains_remote_lines(local_file_path, remote_file_path):
                return False
    return True